Live data from Hacker News

I keep tripping over "true, false, true"

allthingssmitty.com

1–10 of 62 posts

Re: I keep tripping over "true, false, true"

#2
There is something to be said for the bitmasks that are so common in C, createUser(user, ADMIN | SENDMAIL); has a lot more clarity than createUser(user, true, false, true);

I don't mind the object approach used here but its quite verbose in comparison even in Javascript. Having to name the variable and set whether its true or false is a lot more than needs to be done. Booleans in general have quite poor readibility and maintenance especially if a third possibility arrives.

Re: I keep tripping over "true, false, true"

#5
named arguments are hacking object literals to provide additional readability. it's ok, but not for all code paths, they have a true overhead. problem is that these things start to become idee fixes in teams (all funcs should have named args!). ideally, this could be fixed in the language.

Re: I keep tripping over "true, false, true"

#6
In the last couple of years I’ve started using named parameters a bunch more across languages. I consider objects like this close to the JS version of a named parameter. I probably would have thrown “name” in myself so it’s one arg for the whole func.

I feel like a goal with good code is localizing understanding even if it occasionally duplicates something like a parameter name.

Re: I keep tripping over "true, false, true"

#7
post #5

named arguments are hacking object literals to provide additional readability. it's ok, but not for all code paths, they have a true overhead. problem is that these things start to become idee fixes in teams (all funcs should have named args!). ideally, this could be fixed in the language.

Agree that it would be nice to fix in the language. It seems like something that even a transpiler could take care of.

Ultimately I think I’d bias towards readability vs the marginal perf increase though.

Post reply on HN