For a untype language like js array, since it can be empty, you have to either always check the length, the item returned, or have a precondition to know the array is not empty.
All three of those cases is either code or context you’re holding in your head.
I lamented patterns of what I consider over-use of the type system in Rust (This applies to other languages as well). There is a balance: I prefer this over-use/strict use (e.g. implementing a custom non-empty Vec type) over not using typing at all, but a big margin!
You absolutely do have to deal with this in your untyped language otherwise you're just letting edge cases and runtime errors happen. The syntax will be different, it will have to happen at runtime instead of compile time, the chosen wording and language to represent the concepts and the work may even vary, but you are not exempt.
Everyone has to deal with this. The only question is whether you deal with it in the type system, through lots of checks at runtime, or buggy behavior when the user encounters cases you didn't envision.
victorpudeyev · · focus · HN ↗
pyrolistical · · focus · HN ↗
For a untype language like js array, since it can be empty, you have to either always check the length, the item returned, or have a precondition to know the array is not empty.
All three of those cases is either code or context you’re holding in your head.
All that stuff is equivalent to a type system
well_ackshually · · focus · HN ↗
the__alchemist · · focus · HN ↗
Balance in all things?
evilduck · · focus · HN ↗
bigstrat2003 · · focus · HN ↗
abc42 · · focus · HN ↗
bobbylarrybobby · · focus · HN ↗