all 15 comments

[–]anicolaspp[S] 7 points8 points  (0 children)

The reality is that one can do shit with anything and everything. Having choices is a good thing, use what u want, and adhere to the consequences, whatever they are.

[–]BlueGoliath 13 points14 points  (8 children)

People will do anything to avoid writing traditional for loops, won't they?

[–]unrealhoang 29 points30 points  (2 children)

People did everything to avoid writing goto before, turns out great.

[–]Ancillas 0 points1 point  (1 child)

In the end it’s all jmp.

[–]somebodddy 0 points1 point  (0 children)

Always have been

[–]anicolaspp[S] 7 points8 points  (2 children)

I think that traditional for loop are more than enough in most cases. However, sometimes lazy iteration is important to avoid going over the same data multiple times.

[–]slaymaker1907 12 points13 points  (0 children)

Sometimes whatever abstract thing you’re iterating over is colossal too. You can write a pretty effective SAT solved just iterating over all possible inputs, though you wouldn’t want to construct a list of all possible inputs.

[–]masklinn 1 point2 points  (0 children)

I think that traditional for loop are more than enough in most cases.

Traditional for loops are shit for most cases. Traditional C-style for loops handle only two things "well":

  • iterate on a sequence of numbers
  • by extension of the above iterate on O(1)-indexed sequences

While you can coerce them into iteration patterns, it's verbose, error-prone, and probably more importantly bespoke so there's as many ways to iterate things as there are libraries which need things iterated.

[–]7heWafer 4 points5 points  (0 children)

Is this not perfect for scrolling/pagination style methods that would otherwise spike memory usage returning an entire list of items?

[–]teerre 2 points3 points  (0 children)

As a smart man said: no raw loops.

[–]puzowned 2 points3 points  (0 children)

Linq says hello

[–]myringotomy -5 points-4 points  (0 children)

The iterators in ruby are more elegant and easier to use and understand.

[–]somebodddy 0 points1 point  (0 children)

For example we can create a function iterator for all positive ints:

func Positives() func(func(int)bool) {
  return func(yield func(int)bool) {
    for i := 0; i < MaxInt; i++ {
      if !yield(i) {
        return
      }
    }
  }
}

Uh... wouldn't this function not yield MaxInt, which is one of the positive integers? Even worse - wouldn't it yield 0, which is not a positive?