codeinabox@programming.dev to Programming@programming.devEnglish · 6 days agoI keep tripping over “true, false, true”allthingssmitty.comexternal-linkmessage-square29linkfedilinkarrow-up164arrow-down11
arrow-up163arrow-down1external-linkI keep tripping over “true, false, true”allthingssmitty.comcodeinabox@programming.dev to Programming@programming.devEnglish · 6 days agomessage-square29linkfedilink
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up10arrow-down1·6 days agoRust doesn’t need this as much because it has enums so you can just do create_user(user, Role::Admin, Notify::None).
minus-squareEager Eagle@lemmy.worldlinkfedilinkEnglisharrow-up9·6 days agoyou can have a better data structure in any language, but rarely someone will bother doing that for booleans
minus-squareTraister101@lemmy.todaylinkfedilinkarrow-up3·6 days agoRight cause the boolean isn’t a named type. If you have two possible states that can be represented with a boolean, or an enum of the two possible states which embeds more info into the callsite
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up1·5 days agoYeah I do wonder if we need an easier way to declare these things because programmers are lazy and even in Rust I wouldn’t always bother. You can kind of do it in Typescript with strings: function create_user(role: "admin" | "normal") But of course the downside is they are strings at runtime. I’m sure it’s possible though.
Rust doesn’t need this as much because it has enums so you can just do
create_user(user, Role::Admin, Notify::None).you can have a better data structure in any language, but rarely someone will bother doing that for booleans
Right cause the boolean isn’t a named type. If you have two possible states that can be represented with a boolean, or an enum of the two possible states which embeds more info into the callsite
Yeah I do wonder if we need an easier way to declare these things because programmers are lazy and even in Rust I wouldn’t always bother.
You can kind of do it in Typescript with strings:
function create_user(role: "admin" | "normal")But of course the downside is they are strings at runtime. I’m sure it’s possible though.