codeinabox@programming.dev to Programming@programming.devEnglish · 2 months agoI keep tripping over “true, false, true”allthingssmitty.comexternal-linkmessage-square28fedilinkarrow-up164arrow-down11
arrow-up163arrow-down1external-linkI keep tripping over “true, false, true”allthingssmitty.comcodeinabox@programming.dev to Programming@programming.devEnglish · 2 months agomessage-square28fedilink
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up10arrow-down1·2 months 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·2 months agoyou can have a better data structure in any language, but rarely someone will bother doing that for booleans
minus-squareTraister101@lemmy.todaylinkfedilinkarrow-up3·2 months 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·2 months 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.