Second, this may differ a bit from language to language, but maybe those booleans should not be a boolean: https://gleam.run/documentation/conventions-patterns-and-ant... for example isAdmin boolean could instead be a UserRole custom type, with variants Normal and Admin, which is easier to understand in the function call, and extendable with another Moderator (or whatever) variant
I keep tripping over "true, false, true"
21–30 of 62 posts
Re: I keep tripping over "true, false, true"
#22so... it does toggle the menu? and toggleMenu(false) doesn't toggle it and keeps it as it is?
or is it toggle extended menu vs toggle basic menu?
Re: I keep tripping over "true, false, true"
#23First, sentences like "Not because it’s complicated. Just because I have no idea what I’m looking at." and "Tiny interruption. Still annoying every time." fatigue me, it's like you have an editor who, no matter what the content is , tries to spice up your writing with lots of little punchy exclamations, not everything needs such emphasis Second, this may differ a bit from language to language, but maybe those boolean…
Re: I keep tripping over "true, false, true"
#24OCaml has had labeled arguments for decades, so I assumed other languages would have added something similar by now. In C-style, it would be like: createUser(user, ~isAdmin:true, ~sendWelcomeEmail:false) Even though in OCaml's functional style it is actually like this: createUser user ~isAdmin:true ~sendWelcomeEmail:false Using the fact that a variable named exactly like a labeled argument is automatically assigned t…
> function foo({a, b, c}) {
... return {x: a, y: b, z: c};
... }
undefined
> foo({a: 1, b: 2, c: 3})
{ x: 1, y: 2, z: 3 }
> const a = 'A', b = 'B', c = 'C';
undefined
> foo({a, b, c})
{ x: 'A', y: 'B', z: 'C' }
>Re: I keep tripping over "true, false, true"
#25Re: I keep tripping over "true, false, true"
#26Re: I keep tripping over "true, false, true"
#27Also, obviously bot/bought account.
Re: I keep tripping over "true, false, true"
#28OCaml has had labeled arguments for decades, so I assumed other languages would have added something similar by now. In C-style, it would be like: createUser(user, ~isAdmin:true, ~sendWelcomeEmail:false) Even though in OCaml's functional style it is actually like this: createUser user ~isAdmin:true ~sendWelcomeEmail:false Using the fact that a variable named exactly like a labeled argument is automatically assigned t…
fn foo(namedParam internalName: bool) { // use internalName here }
fn foo(unnamedParam: bool)Re: I keep tripping over "true, false, true"
#29Re: I keep tripping over "true, false, true"
#30OCaml has had labeled arguments for decades, so I assumed other languages would have added something similar by now. In C-style, it would be like: createUser(user, ~isAdmin:true, ~sendWelcomeEmail:false) Even though in OCaml's functional style it is actually like this: createUser user ~isAdmin:true ~sendWelcomeEmail:false Using the fact that a variable named exactly like a labeled argument is automatically assigned t…
As author points out: "So I’ll usually just make it explicit:
createAdminUser(user);
createRegularUser(user);
Now there’s not much left to interpret. To be fair, this isn’t always bad. Sometimes this is completely fine:
toggleMenu(true);
That’s clear enough. This tends to work when:
- the meaning is obvious
- the function is small and local
- there’s only one flag "