Hacker News new | ask | show | jobs
by coldtea 2621 days ago
>I do not see the benefit of a 'sign' function with an optional argument

Perhaps you don't see the benefit of an identity function either ("why not just use the variable")?

Encapsulating things in a function instead of a statement is key to certain patterns (and functional style).

1 comments

I agree with GP. The 'sign' function with a mandatory argument I understand. Making the argument optional I don't understand.
I think its less about a sign function than about showing how optional (i.e. nullable) values work. Most languages have them, and making that possibility explicit is recent best practice.
As fjfaase said “The first is that you should try to include realistic examples in your documentation and promote good coding styles.”

That ‘sign’ example could be somewhat improved by having it return an optional int instead (returning null on null inputs), or by having it take a double and return an optional int (returning null for not-a-numbers), but I think it isn’t that hard to come up with a more realistic short example.