codeinabox@programming.dev to Programming@programming.devEnglish · 1 day agoI keep tripping over “true, false, true”allthingssmitty.comexternal-linkmessage-square29fedilinkarrow-up162arrow-down11
arrow-up161arrow-down1external-linkI keep tripping over “true, false, true”allthingssmitty.comcodeinabox@programming.dev to Programming@programming.devEnglish · 1 day agomessage-square29fedilink
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up10arrow-down1·22 hours 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·21 hours agoyou can have a better data structure in any language, but rarely someone will bother doing that for booleans
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up1·43 minutes 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.
minus-squareTraister101@lemmy.todaylinkfedilinkarrow-up3·18 hours 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
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
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.
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