Live data from Hacker News

I keep tripping over "true, false, true"

allthingssmitty.com

51–60 of 62 posts

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

#51
post #48

This is why I continue to advocate for using Ada. It's not just about memory safety but conscious effort was put into readability. Calling the procedure in the article in ada would simply be: createUser (user, isAdmin => True, sendWelcomeEmail => False, skipValidation => True);

Named arguments are supported very widely. How is this an argument specifically in favor of Ada?

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

#52
post #49

This article relates to two classic principles: 1. Avoid long parameter lists [1] 2. Avoid boolean arguments [2] For #1, long parameter lists should be named (named arguments, options object, etc). For #2, and booleans should be replaced by meaningful enumerations. > toggleMenu(true); That’s clear enough. the meaning is obvious Actually, it's incredible ambiguous. Is that toggling the menu? Or setting it to the open…

I was thinking the same. ToggleMenu(); should do it. Or is there something I'm missing? Ie is the function misnamed? OpenMenu(true); maybe what the function is doing?

Must be the latter, IMO

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

#53
You should just use objects/structs for function arguments when the arguments have any expectations of being expanded in the future. Use sane default behavior when new arguments/options are added to the function. Consumers of your interfaces will then have a much easier time handling updates down the line.

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

#54

Named arguments are a great feature in Python. I often forget TypeScript doesn't have this, but I use the object form all the times. As a bonus, you can also declare these arguments in an object an interface type, aptly named.

Amen. Was about to comment:

create_user(user, is_admin=True, send_welcome_email=False);

Not even article-worthy.

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

#58
post #32
post #27

AI;dr: keyword arguments would be great in all languages, not just Smalltalk Also, obviously bot/bought account.

Swift also has them. It's probably the one thing I sometimes wish Rust would copy from them.

Thinking more about this, I'm realizing that Swift was probably transitively inspired by Smalltalk; although I don't know much about Objective-C, my vague understanding is that it's a bit more inspired by Smalltalk's view of object-oriented programming via message passing than what commonly is considered OO nowadays (which is reflected somewhat in that it doesn't use the typical dot-operator for method calls), and I'm guessing that it was included in Swift as one of the things that was liked about Objective-C (and maybe a little to make interop more direct).

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

#59

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 a…

[dead]

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

#60
post #32
post #27

AI;dr: keyword arguments would be great in all languages, not just Smalltalk Also, obviously bot/bought account.

Swift also has them. It's probably the one thing I sometimes wish Rust would copy from them.

While I wish every language had them in a way, they do tend to enshrine the argument names in the ABI, so now you can't change those in public APIs. (Main reason I think it shouldn't be part of the ABI is because I think only the necessary things to identify and correctly use a contract should be part of the ABI)

I have been thinking off if there is a way to have it work without enshrining them in the ABI and my only real idea is: allow arbitrary names at the call site (e.g. `my_function(some_var=1)` or `my_function(some_var: 1)`) but don't enforce the naming, just have linting spit out a warning for it if it doesn't match.

Post reply on HN