Hacker News new | past | comments | ask | show | jobs | submit login

I am not sure if your "I want a language where I can" is followed by an implicit ", and C++ is that language" or ", I wish it existed".

I am guessing the former as your example is possible with C++ but it doesn't seem like a great example as you are using units of measure for your types. There are languages that support those and obviously, in such a case, assigning centimeters or inches to a distance-typed variable is both ok. The type error would be in mixing distance and, say, weight.




I meant C++. I'm using this currently in C++ production code. Has saved me tons of debugging.

What I meant was that if I'm going to look at a new language, I would expect it to support this type of functionality.

I suppose I can enhance the classes and overload the operators to automatically convert from cm to inches when doing mixed arithmetic. But this will quickly become insanely complicated when considering all possible permutations of arithmetic operators.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: