Hacker News new | ask | show | jobs
by jarjoura 534 days ago
I constantly run into situations where I need to nest an iterator computation, and things like "it" get confusing.

I'm all for adding language features to avoid boilerplate, and it's clearly useful. I just want to call out that anonymous typing can be polarizing in large codebases and maybe only use it sparingly.

3 comments

I doubt I'll use it in committed code very often at all, this feels more like something that's very useful when hacking at something in the REPL
nested_example = [1, 2, 3, 4, 5].map do

  [it, (1..it).map { it * it }]
end

Has an ambiguity, so you just add |x| to one of them..

nested_example = [1, 2, 3, 4, 5].map do |x|

  [x, (1..x).map { x * it }]
end

Seems like a mental over complication of a non-issue to me.

Implicit `it` shadows in other languages like Kotlin just like any other variable scope, and I really can’t say I’ve ever had it be a problem (implicit receivers, on the other hand, can be a right pain in the ass in poorly designed libraries and can I just say Gradle can go right to hell for it).
It’s a nonissue in small projects, but I’m not sure I agree that `{ x * it }` is easy to reason about when coming back to this block in 6 months. It’s mostly something that I’ve seen bite engineers during refactoring.
Being ruby you can monkey patch block to add an additional t to every nested block’s `it`

(This is terrible please don’t)