remix logo

Hacker Remix

A visual demo of Ruby's lazy enumerator

125 points by rossta 2 weeks ago | 27 comments

afraca 1 week ago

When I learned Haskell in college I was blown away by how laziness enables cool things like dealing with infinite lists or more performance even though the UX is exactly the same. (Apparently with Ruby there is the slight hint of adding the lazy method in between)

Later I found out laziness in the whole system by default leads to some difficult issues, which quite a few people seem to agree with. Simon Peyton Jones (Haskell co-creator) apparently has said "The next Haskell will be strict". (https://news.ycombinator.com/item?id=14011943)

drnewman 1 week ago

Laziness is great for collections, and modeling the infinite but as a general model for programming it's a little loopy for my taste too ;-)

whateveracct 1 week ago

That was SPJ being cute more than an actual indictment of Haskell fwiw. That quote gets misused a lot.

Laziness hasn't killed Haskell's usefulness. However, it is something Haskellers take for granted. I can't tell you how many times they "just turn on -XStrict" and are surprised their program gets slower.

adsteel_ 1 week ago

Hm, the CSS and JS don't appear to load for me. Not even a <body><html> set of tags in the HTML response.

fredrikholm 1 week ago

Same here, both on computer and mobile. The rest of the website looks fine.

rossta 1 week ago

I have heard a few people mention issues but I haven’t been able to reproduce nor understand the scope of the issue. Any more details you can share? You’re getting HTML but JS or CSS assets aren’t loading, right? What status and headers do you see for static assets?

Syntaf 1 week ago

Really cool visualization and neat to learn about lazy enumeration!

Excuse me while I go back through my code and make sure I’m using lazy enumeration wherever I’m iterating over large collections….

dylan604 1 week ago

This sounds like a similar response I had when learning about stream editors vs text editors. It was one of the killer apps that convinced to become a CLI warrior. Opening up a large text file in Notepad took for ever, but opening the same file in vim was a nothing burger. Then, the same person that showed me that showed me sed/awk/grep, and I was off to the races.

pansa2 1 week ago

So in Ruby, `map` and `select` are eager-by-default, but you can just write `lazy.map().select()` to make the whole chain lazy? That's really nice - much better than Python 2, which was also eager-by-default and you had to change every function call to make it lazy (`map` => `imap`, `filter` => `ifilter`).

Python 3 changed to being lazy-by-default. I assume that improves CPU/memory usage, but in some cases it does have less predictable behaviour. I can see why Ruby, with its goal of "developer happiness", would choose to retain the predictable behaviour of eager-by-default.

saagarjha 1 week ago

Swift does this too, with almost the same syntax. IMO it's the right choice.