Hacker News new | ask | show | jobs
by splatcollision 3752 days ago
One-liners are fine if you know you'll never need to extend the logic later on. Problem is, how often does that stay true?

For instance your 'titleize' method, in order to properly title case any string, ought to support a second option of words to ignore, such as "a, an, the, ...". If you wrote it as a one-liner at first, then you've got to go into your mapper and add conditionals if an ignore list is passed, and you've got more work than if you left it as a more expanded piece of logic.

Again, this is somewhat of a trivial example, but building on the original post's point of "how easily can I understand this later on" can also include "how easily can I extend this later on". Avoiding one-liner cleverness can help as a general principle.

1 comments

> One-liners are fine if you know you'll never need to extend the logic later on. Problem is, how often does that stay true?

Write the simple version first, wait for the need to extend the logic arise naturally, factor out the function and extend.