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);
I keep tripping over "true, false, true"
51–60 of 62 posts
Re: I keep tripping over "true, false, true"
#52This 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?
Re: I keep tripping over "true, false, true"
#53Re: I keep tripping over "true, false, true"
#54Named 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.
create_user(user, is_admin=True, send_welcome_email=False);
Not even article-worthy.
Re: I keep tripping over "true, false, true"
#55This needed an entire article?
Re: I keep tripping over "true, false, true"
#56Re: I keep tripping over "true, false, true"
#57Re: I keep tripping over "true, false, true"
#58AI;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.
Re: I keep tripping over "true, false, true"
#59There 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…
Re: I keep tripping over "true, false, true"
#60AI;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.
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.