Live data from Hacker News

I keep tripping over "true, false, true"

allthingssmitty.com

41–50 of 62 posts

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

#41

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

This is one of the things I've loved about Gleam, one local variable name and potentially an external label that callers can use to annotate themselves. For example, a function declaration may look like this:

  pub fn pad_end(
    string: String,
    to desired_length: Int,
    with pad_string: String,
  ) -> String
And a call to this function may look like:

  pad_end("123", to: 5, with: ".")

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

#42
post #20

You answered your own question. Call with const isAdmin = true; . . . createUser(user, isAdmin, sendWelcomeEmail)

If you swap the order of isAdmin and sendWelcomeEmail you'll get no error from the compiler but now the names will be masking the actual behaviour.

Can you imagine how much fun it would be to find that bug?

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

#44

> toggleMenu(true); That’s clear enough. the meaning is obvious so... 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?

setMenuVisible()

If it is unclear what your one-argument function does, the name is the problem and you messed up, not the language. For multi-argument functions, you can have either enums or named arguments or, if you really have to, some kind of builder pattern thing: eatCheese(cheese().fromGoatMilk().withVanillaFlavor()).

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

#46

I was nodding along with the piece in the first half, then it repeated the same point five more times and I started to smell slop.

You can tell it was written by claude after just a few sentences, really.

The comically unncessary section headers are also incredibly LLM coded.

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

#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);

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

#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?

Post reply on HN