4 ms·
... or you could just use a language which doesn't allow "null".
by lomnakkus 10y ago
... or you could just use a language which doesn't allow "null".
- recursive 10y agoOr use a null safe member access operator like the one in c#. player?.position.x
- douche 10y agoIf it's C#, you could also make Position be a struct that can't be null. Generally things like Points and Vectors are structs anyway in a lot of cases for performance reasons.
- lomnakkus 10y agoThat doesn't really solve the problem. What if "x" is a nullable type (i.e. not a primitive type)?
- recursive 10y agoThe nulls get coalesced. In what way is it not solved?
- lomnakkus 10y ago"x" could be of a nullable type.
- recursive 10y agoAnd the result of the entire expression is still nullable. I'm not seeing any problem.
- lomnakkus 10y agoHm. What do you think "42 + null" is?
- recursive 10y agoAccording to c# (the language I'm talking about) I think it's null. That seems correct to me. Arithmetic on null operands logically seems to have a null result to me. I'm not sure what you're getting at. https://dotnetfiddle.net/nQoEKu https://dotnetfiddle.net/nQoEKu
- lomnakkus 10y agoThat's OK, I.. guess. I don't think I should even be allowed to ask the question because it's an absurd question[1]. Does that position make sense to you? [1] Not for frivolous reasons. It's almost always nonsensical to ask this type of question with "null" values. For the sensical cases we have Maybe/Option.
- recursive 10y agoI think I see what you want now. In order to get the value out, you'd have to use pattern matching or a type guard or something, inside of which you'd know there was a value. That makes sense to me too. But compared to Maybe, a null-safe member accessing operator, along with null-lifted operators seems nearly as good from my point of view.
- debacle 10y agoI can't think of a programming language used for game development that doesn't have null.
- gpderetta 10y agoC++, unless pointers are explicitly used, which weren't in the OP example.
- lomnakkus 10y agoI'm not sure I understand exactly why this is specific to game development? (I see that the article uses a game-like example, but...) Even so: I'm pretty sure Rust is suitable for game development being essentially zero-overhead, non-GC and Rust effectively disallows "null". (That, and C++ if you allow only references like another poster mentioned.)
- kazagistar 10y agoIn Rust, an `&Thing` (reference to thing), `Option<&Thing>` (optional reference to thing), `Box<Thing>` (thing on the heap), and `Option<Box<Thing>>` (optional thing on the heap) all have the same in-memory representation of a single pointer, but prohibit accidentally dereferencing a null pointer, and make non-nullable pointers the default.
- coldtea 10y agoThat made my head hurt.
- coldtea 10y agoStill not solving all the problems that an accessor does. Say you suddenly want to change the position to another unit, or change how it uses position (perhaps return a different position on some cases). With direct access, you can't.