Hacker News new | ask | show | jobs
by IceSentry 1042 days ago
I don't understand why you consider loops an abstraction. They are some of the most basic building block.
4 comments

People are getting caught up on the loops thing. All I meant was in my line of work I often end up with many special cases of general processes. Writing a loop prematurely always bites me - I end up writing control flow for handling the one-offs, it somehow always becomes more obtuse than just listing things out literally.
Loop as an abstraction of copy-paste.
They considered it a dedupe not an abstraction

It would be unnecessary to have a loop over keys of a dictionary to call function xyz when you can just repeat the xyz calls (it would look nicer too)

Unless the dictionary is huge and dynamically loaded.

Loops are an abstraction over conditional branching and, depending on the kind of loop, some other things.
> Loops are an abstraction over conditional branching

How?

Goto. In the end it's all about manipulation of the instruction pointer.

Loops as deduplication is a very specific subset of looping that is very popular in some languages and almost nonexistent in others. If you don't have destructuring and convenient list literals you might never ever see it in the wild.

But even the Java 7 version (iterating an ImmutableList.of multi-nested Maps.immutableEntry of new FunctionN) can be workable despite its hilarious amount of repeated type annotations, if you have learned to stop worrying and love the tooling. Stuff like typescript makes it a breeze, so much that one might occasionally forget that it's not the regular form of looping.

What do you think is being evaluated on each iteration of a loop?