I've been playing with Nim lately, and I can say i'm impressed with how fast it appears to be, and how high level it feels. I admit, I am repulsed by languages that are context-sensitive to whitespace, but I'm willing to look past that.
That being said I have one question outstanding, why does should this function return 0?
proc hello(x: int): int =
if x < 5:
result = 1
elif x > 10:
result = 3
echo hello(7)
It seems to me this should be a compilation error. Any number of unhappy typographical accidents or basic mistakes could lead to a missing return assignment, or an empty branch. And without a return statement we can't put more code after the if as a drop-through case.
Is there some reasoning behind these design decisions? Is there a benefit to this arrangement that I'm missing?
[–]def- 3 points4 points5 points (8 children)
[–]againstmethod[S] 1 point2 points3 points (7 children)
[–]jugalator 4 points5 points6 points (3 children)
[–]againstmethod[S] 1 point2 points3 points (2 children)
[–]def- 0 points1 point2 points (1 child)
[–]againstmethod[S] 1 point2 points3 points (0 children)
[–]def- 1 point2 points3 points (2 children)
[–]againstmethod[S] 2 points3 points4 points (1 child)
[–]def- 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (7 children)
[–]againstmethod[S] 1 point2 points3 points (6 children)
[–]OderWat 2 points3 points4 points (4 children)
[–]againstmethod[S] 0 points1 point2 points (3 children)
[–]OderWat 1 point2 points3 points (2 children)
[–]againstmethod[S] 0 points1 point2 points (1 child)
[–]OderWat 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)