6 ms·
What I'd like to tell the author. Don't like null? Don't use it.. and you find null propagation ruining your abstraction then treat it as an error and fix you
by benjohnson 8y ago
What I'd like to tell the author.
Don't like null? Don't use it.. and you find null propagation ruining your abstraction then treat it as an error and fix your program.
- evocatus 8y agoPerhaps possible in isolation or on a small team. I don't think this is practically achievable on teams that have grown past a certain size, though. To paraphrase Carmack, "Any syntactically valid code, that the compiler will accept, will eventually make it into your code base." [1] [1] https://www.youtube.com/watch?v=Uooh0Y9fC_M https://www.youtube.com/watch?v=Uooh0Y9fC_M
- AstralStorm 8y agoNot if you review your code reasonably well and use static analysis plus some testing, making it a process to not get bad code into your codebase.
- occamrazor 8y agoAt some point one will include external libraries, written with different styles and standards. And then will modify the libraries, making them effectively part of the core code base.
- mamcx 8y agoSo, no use any OS, library or code-base on top of C, C++, Java, .NET, Javascript, Sql...???
- klodolph 8y agoIt actually turns out that there are better ways of solving problems with null that don't involve just telling programmers to go fix their programs. There are alternatives, like encoding whether a value can be NULL (or some semantic equivalent) into the type system. Rust and Haskell are examples of languages where this is the only way to do things, and C# and TypeScript are examples of languages where you can selectively (and under certain condutions) make distinctions between values which can be null and which cannot be null.
- cesarb 8y ago> Rust and Haskell are examples of languages where this is the only way to do things, You know Rust has null too, right? https://doc.rust-lang.org/std/ptr/fn.null.html https://doc.rust-lang.org/std/ptr/fn.null.html Rust has both references (which can't be null†) and pointers (which can be null, but can only be dereferenced within "unsafe" blocks or functions). † Actually, they sort of can: an Option<&T> takes the same space as a &T, with the None variant of the Option being represented as a null behind the covers.
- klodolph 8y agoRead the statement as "the only typical way to do things" or "the only safe way to do things" or "the only way to do things without using a completely different type which supports NULL". The fact that Rust has unsafe non-GC'd pointers which can be NULL or otherwise invalid puts it in the same camp as Haskell, Go, C#, etc. but in Rust you are more likely to use references which can't be NULL.
- pdpi 8y ago> Actually, they sort of can: an Option<&T> takes the same space as a &T, with the None variant of the Option being represented as a null behind the covers. There is no “sort of can” here. It just so happens that None uses the same representation as null, but by that logic you’d say that u64 can be null because 0 has the same representation as null.
- robconery 8y agoOP here - as a matter of fact I try to do just this, starting with the database. I'm mostly a data person so I try to think through, as deeply as I can, what I should expect in every table - there has to be a sensible default and if I can't find one then I rethink my design. You'll probably disagree with me and grunt out another single sentence missive, which is fine, but I think it's worth taking some extra time and using Null as a bit of a warning. It's a crutch! A way to stop thinking and say "whatever I don't know what this value is supposed to be so... it's null. Let's go shopping!"
- chris_wot 8y agoWhat do you use in a database when you have a field where you literally do not know what the value should be?
- SanityIsRare 8y agoStop mansplaining!!! He has 25 years of experience in OO and functionals!!!
- dragonwriter 8y ago> What do you use in a database when you have a field where you literally do not know what the value should be? You don't. If a value may not be present for an entity, it's not an attribute of the entity in question, it's an attribute of another entity that has a (0..1):1 relationship to the entity in question. Normalization eliminates NULL.
- AnimalMuppet 8y agoThat's great. Now I do a query. Maybe I use a join. If a row has the "0" case of that (0..1):1 relationship, what do I get? Or maybe I don't do a join. Maybe I do a separate query. If the query comes back with zero rows, then I... what?
- ErwinSmout 8y ago