Live data from Hacker News

I keep tripping over "true, false, true"

allthingssmitty.com

11–20 of 62 posts

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

#12
Isn't this more an issue with typescript? Doesn't your ide give you the declaration if you hover over the call?

> And I’ve seen real calls like this in production code: > updateSettings(user, true, false, true, false)

Really? He wants named parameters on all function calls cos he's got a memory like a sieve? This is a long solved problem to me

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

#16
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 to it, we can make the call more concise (especially if reusing existing variables):

  let isAdmin = true in
  let sendWelcomeEmail = false in
  createUser user ~isAdmin ~sendWelcomeEmail

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

#18

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…

C# has that

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

#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.
Post reply on HN