Hacker News new | past | comments | ask | show | jobs | submit login

If you take the awful step of naming things, comprehensions are easy enough to chain. That is (in untested python...)

    parts=s.split('+')
    keep=(s for s in parts if s)
    ints=(int(s) for s in keep)
    sum(ints)
Hiding the middle steps there in a function is easy enough.

That split returns a list, but the other steps are lazy.




But naming your intermediate variables means it's not possible to splice parts out.


You did call it a grain of sand, but I suppose I'm responding to where you call it complicated. Moving a couple of the names into a separate function means passing in one of them and editing the last line (at least in python with explicit returns). That meets the meaning of more complicated, but (in my opinion) in a sort of hair splitting way.


Horses for courses then I guess. If the "easier to refactor" argument doesn't convince you maybe the "easier to read" argument will. Personally I strongly prefer zero-length variable names, but everyone has their own taste.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: