const isAdmin = true; . . . createUser(user, isAdmin, sendWelcomeEmail)
I keep tripping over "true, false, true"
11–20 of 62 posts
Re: I keep tripping over "true, false, true"
#12> 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"
#13Re: I keep tripping over "true, false, true"
#14I 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.
Re: I keep tripping over "true, false, true"
#15Re: I keep tripping over "true, false, true"
#16 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 ~sendWelcomeEmailRe: I keep tripping over "true, false, true"
#17Re: I keep tripping over "true, false, true"
#18OCaml 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…
Re: I keep tripping over "true, false, true"
#19Avoid the Long Parameter List
https://testing.googleblog.com/2024/05/avoid-long-parameter-...
Re: I keep tripping over "true, false, true"
#20You answered your own question. Call with const isAdmin = true; . . . createUser(user, isAdmin, sendWelcomeEmail)