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

It doesn't communicate the same thing. It communicates one example, leaving the reader to guess how to generalize it. Examples are good, testing is good; and specs are good too. It's currently popular to valorize the first two at the expense of the third, but I think this was an overreaction to the older dogma.


If the general behavior of multiplex isn't clear to the api-user from the example:

    multiplex('Tom', 4) == 'TomTomTomTom'
I'd argue that's a failure of the api designer that no amount of documentation is going to make up for.

Examples are good, testing is good, executable, testable documentation is doubly good, and predictable, intuitive api interfaces are invaluable; everything else is a liability that is going to go stale.


Covering every case provides value that covering just one does not. Natural language communicates in a way code does not. The tradeoffs are a bigger topic than I feel like arguing about in this thread.

(I agree with all you said except the last clause.)


What is the expected behavior of, say,

  multiplex('Tom', 0)
or

  multiplex(null, 2)
?


Well, if the function was designed by me, then the completely obvious answers are '' and a NullPointerException. Anything else is bug-prone — if the first case does something different, then nearly every caller of the function will need to check to see if the count is zero, or it will get behavior for that case that is not correct for its purposes; and if the second case does something different, then the function is choosing to provide incorrect output instead of crashing.

Also, I would have called it something different.

However, over the years, I've learned that many things that are obvious to me are not, in fact, true. So, what are the arguments for any other possible behavior?


Backward compatibility could be one such factor.

In any case, documenting edge conditions helps in code maintenance.


Since I'm coming from Python, JS, and C, passing a null instead of a string doesn't seem like an "edge condition"; it's the same kind of error as passing an integer or Map instead of a string. Passing 0, I suppose, is an edge condition.


Even the Agile Manifesto itself explicitly says that its signatories value comprehensive documentation. They just value working software even more.




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

Search: