5 ms·
A good chance to learn why people who write reliable software almost universally like static type systems.
by tazjin 2y ago
A good chance to learn why people who write reliable software almost universally like static type systems.
- viraptor 2y agoThis code would pass static type validation, there's nothing wrong with it at that level. It gets a default value to use and does exactly that.
- tazjin 2y agoSure, you can follow along the old meme: https://twitter.com/vbhvsgr/status/1419369352164372482 https://twitter.com/vbhvsgr/status/1419369352164372482 Though in practice in decent languages it's much less likely you'd write your own `any -> any, any`-typed library for whatever (in this case DB interactions), and use a strongly typed one in which this would at least have been a much more explicit mistake to make.
- bluepnume 2y agoBut this isn't an `any -> any` case. They passed in a default value, as a string, which is the correct type for a default value for this column. Even with very strong typing they wouldn't have got a type error here right?
- jowea 2y agoYou could make a special primary key column creation function that rejects static values.
- tazjin 2y agoYou don't even have to reject/forbid them, just make their use explicit.
- Nullabillity 2y agoYou can forbid static values and require it to be a function. Generally, static languages will just culturally be less likely to have this kind of invisible "T | (() -> T)" overload.
- paulmd 2y agoI thought this was going to be the xkcd ‘int rand() {return 6; //chosen by fair dice roll}’, which is more or less what they did lol.
- jrpelkonen 2y agoIf the language in question disallows function overloading, this distinction becomes very clear. For an example, see Rust option's unwrap_or[1] vs unwrap_or_else. [1] https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or https://doc.rust-lang.org/std/option/enum.Option.html#method...)