4 ms·
We can easily distinguish between the two by calling them units.
by temac 10y ago
We can easily distinguish between the two by calling them units.
- Silhouette 10y agoIt's not necessarily just units, though that's one useful example. Types could also include things like whether a text string has been escaped in a certain way, whether data has come from a trusted or untrusted source, and countless other reasons you might want to ensure you don't use a value with a certain property in the wrong way. In modern languages where defining custom types and enforcing their use is easier, there is less need to distinguish these properties by convention. Twenty years ago, when we were doing more development with languages in the C family that don't have very powerful systems, it was a different story, and so naming conventions went some way to helping keep track of what data you were really passing around beyond just "It's an int" and the like.
- throwawayish 10y agoAll true, but if we say "type" then the default assumption will be "int", "string" etc. -- "pixels" and "millimeters on a piece of paper" are the same type then. This is, after all, exactly how systems hungarian misunderstanding came about.
- jschwartzi 10y agoI would also add that even in modern C++ it's possible to have the compiler check your usage of page and screen widths by creating separate types, ScreenWidth and PageWidth. You would then generate compiler errors on assignment, or provide single-argument constructors for implicit conversion. It's just that nobody ever actually does that in C++.
- fiddlerwoaroof 10y agoThe people that want to do this just use Haskell :)