This code may occur in Ruby.
I have used the unless keyword very rarely, so I will not really miss it in Nimrod.
But the conditional if at the end of a statement is really useful in Ruby, generally I write
a *= 2 if a < b
instead of
if a < b a *= 2 end
OK, for Nimrod we have no end, so it saves only one line.
But regard this code:
def process_event(boxlist, event, x0, y0, x, y, hit_selected, selected, msg) return false if @state == State::Deleted
Here I really like the conditional at the end.
What do you think.
PS: I really hope that we have the ternary ? conditional operator known from C in Nimrod for something like
c = (a > b ? a : b)
You can write the if in a single line without problem. There is no ternary conditional operator because if is an expression, so you can use it directly. For the cases you present it might be better to use system.max anyway. Here's an example of using if as expression to reduce lines:
proc some_proc(params: int): bool =
# By default the bool `result` is always false
if params > 3: result = true
proc test() =
var
a = 5
b = 7
if a < b: a *= 2
var c = if a > b: a else: b
echo a
echo b
echo c
c = max(a, b)
echo c
echo some_proc(c)
when isMainModule: test()
a = 1
a *= 2 if some_condition
a /=3 if some_other_condition
is in my opinion much more readable than this:
a = 1
if some_condition: a *= 2
if some_other_condition: a /=3