4 ms·
There's some cool mechanisms in type-forward languages that lead to minimal dynamism loss along with safety: For instance, you can do scientific programming tha
by hibikir 2y ago
There's some cool mechanisms in type-forward languages that lead to minimal dynamism loss along with safety: For instance, you can do scientific programming that carries units along. So you really can divide a length by a time with no problems: Your results just happens to be a velocity, and will come out in meters per second (or whichever your favorite units are). Adding meters to kilometers? Congrats, you might you have to say which physical representation you want in float-land. But then you are saved from adding seconds to milliliters, because then the types will tell you it's complete nonsense.
But note that to make all of that work well you really need your language to provide a lot of syntactic sugar features which are missing in most older languages, so all the operations read seamlessly, instead of being full of ceremony. One could do all of this in, say, old Java 1.4 or something, but the amount of type annotation, along with the massive mounts of boilerplate to get all of the operationg working right, and checked at compile time would make it all Not-Worth-It(tm) But with enough language features, and a smart enough compiler, `val acc = mySpeed / someSeconds` will work, straight up, with the safety included.
- bryanrasmussen 2y agothanks for saying it a lot better than I did!
- dataflow 2y ago> But then you are saved from adding seconds to milliliters, because then the types will tell you it's complete nonsense. I was thinking about this as I was reading your comment, and wondering: is it nonsense? If I have 5 seconds of time as well as 10 milliliters of water... I can consider them as being packaged together... which is addition. And I can subtract 3 milliliters and 6 seconds from them without running out of what I had. Nothing wrong with that, really. Five potatoes and a gallon of water is the same notion, just more familiar. Seems no more nonsensical than dividing length by time, right? Food for thought...
- schoen 2y agoBundling the time and the volume might be better called "forming a vector" or "forming an ordered pair" rather than "addition". You can then perform addition and subtraction with the resulting ordered pairs or vectors.
- dataflow 2y agoThere's no need for ordering (it's a bag rather than a vector), but yeah.
- deleted 2y ago[deleted]
- twixfel 2y agoThat's nonsense because addition loses the structure. 3 litres and 6 seconds becomes indistinguishable from 4 litres and 5 seconds. Maybe that's what you want, but it's realistically pretty much never what you want.
- dataflow 2y agoThat's not how it works. Addition losing structure doesn't mean "strip out everything from the textual description that isn't a number". It just loses some properties, like ordering. Which means, for example: (3 liters and (i.e. "+") 6 seconds) + (4 liters and 2 oranges) = (7 liters and 6 seconds and 2 oranges). Perfectly sensible addition, which you do all the time. There's no stipulation the output has to be a single number...
- twixfel 2y agoAlright you're just talking about a different operation entirely but have decided to give it the name "addition". Not particularly insightful, but thanks anyway.
- dataflow 2y agoWhat? Addition isn't just for numbers. This is literally no different from adding vectors. I'm sure you've seen that in school?
- twixfel 2y agoWhat do you mean subtracting a cat from a dog doesn't make sense? Heh, ackshualllyyy I was imagining a vector of pets, where we have still have a dog but now a cat deficit of one, because the cat died and now we have a big hole in our family... nothing personnel kid. surely you learnt that in school? The point is, making a vector, that's not addition.
- dataflow 2y ago