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

I don't see the point of this. How is

  [10, 11, 12].map(&X.to_s(16))
more readable than

  [10, 11, 12].map({|x| x.to_s(16)})
? The motivation behind this (less temporary variables) is a non issue to me since the scope of such variables is tiny. In addition, this makes code non idiomatic and harder to read for anyone who hasn't used this gem, and adds another dependency to projects.


Consider you have two of these things close together:

  [10, 11, 12].map{|x| x.to_s(16)}
  [:baz, :bam, :bar].map{|x| x.to_s(16)}
At least for me, I tie the 'x's together in my head; so I have to concentrate to realise that there are two different 'x's.

I've not done any formal research into this, it would be interesting to see whether there's actually a perceivable difference between the two styles.


I would never stop to think that the x's could be the same. The fact the {} instead of do syntax is used and the fact that the parameter is called 'x' instead of something more descriptive tells me that I shouldn't be concerned with the parameter itself.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: