Skip to content

Comment on Haskell style list comprehensions in Ruby

Comments

Side question, rant. I love the syntactic side of list or dict comprehension (in python) and often use them but as soon as I have to debug or expand the functionality, I have to slice them into for loop. And then I hate myself for being lazy/clever and more and more, when I start typing a = [, I hear an internal voice: wait, aren't you being wrongfully clever one again?

I am the only one?

I adore list comprehensions, but perhaps for this reason, I generally only use them for operations so simple as to be trivially correct or incorrect without any debugging.

Dict comprehensions are just a little muddier, even for simple things, but a single line of debug output after the comprehension should confirm whether or not you're getting the structure you expect, provided you are still doing only trivial work inside your comprehension.

I like to use them for simple cases only (No nested comprehensions, etc). When in doubt, the Google Python style guide [0] has some useful guidance.

[0] - http://google-styleguide.googlecode.com/svn/trunk/pyguide.ht...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.