Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A for can be replaced by a while and a jump, that does not make it more or less elegant.

IMHO, something ‶elegant″ in programming is not something that can't be built form something else (or we will all end up in writing only CMOVs), but something that conveys the meaning of its author precisely and concisely – which makes it inherently subjective. I'm in the `unless` team, I can perfectly understand if you are in the `no unless` team, but this argument does not make a lot of sense.



Note that I said 'trivially'. The structure and meaning of an 'unless' construction is the same as 'if', adding or removing only a negation. Using 'while' and a jump to construct a loop is much more expressively distant from 'for'.


The `for` is a very ergonomic syntax to mapping a computation to every element of a sequence. The `while` does a really different thing, it's not about sequences at all, but about checking some bit of mutable state repeatedly.


> The `for` is a very ergonomic syntax to mapping a computation to every element of a sequence.

The very ergonomic solution to map a computation to every element of a sequence is `map`. In this case, `for` is filled with bookkeeping that does not matter.


I edited out "syntax sugar" that was in the post initially.

Also, the `for` operator definitely predates the `map` function. Some people also prefer `map` to be more or less pure and expect it to return a usable list; `for ` has no such expectation, it e.g. may consist solely in printing elements.


> Also, the `for` operator definitely predates the `map` function

And `CAS/Compare Accumulator with Storage` definitely predates `if`, still you are most probably using the latter.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: