codeinabox@programming.dev to Programming@programming.devEnglish · 2 months agoI keep tripping over “true, false, true”allthingssmitty.comexternal-linkmessage-square23linkfedilinkarrow-up151arrow-down11
arrow-up150arrow-down1external-linkI keep tripping over “true, false, true”allthingssmitty.comcodeinabox@programming.dev to Programming@programming.devEnglish · 2 months agomessage-square23linkfedilink
minus-squareFizzyOrange@programming.devlinkfedilinkarrow-up7arrow-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-up8·2 months agoyou can have a better data structure in any language, but rarely someone will bother doing that for booleans
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
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.