dev_null

joined 2 years ago
[–] dev_null@lemmy.ml 1 points 3 hours ago* (last edited 3 hours ago)

Depends on your requirements.

If the admin status needs to be checked in a database, but most actions don't require authentication at all, it's pointless to waste resources checking and it would be left null until the first action that needs the information checks it and fills it in as true or false.

[–] dev_null@lemmy.ml 1 points 10 hours ago* (last edited 10 hours ago) (2 children)

So in a language with nullable types, are you against a boolean ever being nullable? Null means "empty, missing info". Let's say we have role variable with a enum type of possible roles. It could still reasonably be nullable, because in some scenarios you don't know the role yet, like before log in.

In any use case where we need to store some boolean, it's a common occurrence that we don't have the data and it's null. It would be overkill to use an enum with True, False, NoData for these cases, where there is already a language feature made just for that, nullable values.

I've never used TypeScript, just writing from experience in other languages.

[–] dev_null@lemmy.ml 5 points 12 hours ago (5 children)

This is quite reasonable, aside from the variable name which should be isAdmin. A user either is an admin, or isn't. Unless we don't know, then it's null. You are correct this is bad if the point was to represent roles, but it's not supposed to.