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

When reading the paper's verbose versions, I have to act as a human compiler and keep track of state which leads to mental errors. Contrast this with a shorter version reducing the LOC count from 21 to 6:

    x = [..]
    y = [..]
    between = lambda ls, low, high: (n for n in ls if low < n < high)

    x_between = between(x, 2, 10)
    y_between = between(y, -2, 9)
    xy_common = set(x).intersection(y)
Experienced users made mental stakes because they skim code and make assumptions from previous sections. This can be solved by taking advantage of a language's expressiveness to clarify intent.


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

Search: