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

I think his code choices are clear. The domain logic is "if it is a discount day then...". Keeping the calculation for what is and is not a discount day in the if statement muddles the logic because now you have the domain logic and logic for calculating whether or not today is a discount day in the same block of code. The discount day calculation is complex enough by the end (before memoization) that you'd likely end up adding a comment above the if statement to explain that you're calculating a discount day.

His choice to use [].include? is idiomatic ruby so I don't think it's being clever for clever's sake... although I've always kind of stumbled over that construct, I sort of wish there was an 'in' statement... if current_day in [x,y,z]. It would be easier to read (for me at least).




> current_day in [x, y, z]

Your pseudocode is idiomatic Python code :)


Yes, it did strike me how JS and Ruby are hard to read compared to Python's "if x in [a, b, c]".

Moreover, the memoise part is better handled with a decorator: it is a special behavior of the function and don't relate to its logic (its body).




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

Search: