Browse files

Avoid `unless`

  • Loading branch information...
1 parent 73c8299 commit d3686465dbf863b5b18c9b75a9c72511d0b0bfc5 @mitchellh committed May 6, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 templates/guests/debian/network_dhcp.erb
@@ -2,7 +2,7 @@
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth<%= options[:interface] %>
iface eth<%= options[:interface] %> inet dhcp
-<% unless options[:use_dhcp_assigned_default_route] %>
+<% if !options[:use_dhcp_assigned_default_route] %>
post-up route del default dev $IFACE
<% end %>

2 comments on commit d368646


I'm curious, why avoid unless?


It is just personal style. I honestly think that unless is clearer in some cases (perhaps including this), but the line becomes blurry very quickly:

  • If there is an else
  • If there are multiple boolean expressions being combined unless foo && bar
  • If the boolean expression reads as a negative unless not_foo

if expressions fall under the same problems, but as programmers we're generally trained to understand if rather intuitively, so I tend to avoid the potential unless mess in the future by using only if statements.

I'm not religious about it except in my own code, and I won't argue with someone about it (its just not that important), but I do my best to only use ifs.

Please sign in to comment.