5 ms·
I'd argue that unit would be just as cryptic as monostate, if you don't know what either is. Like, if we assume someone looking at code with `std::unit`, what
by sham1 2y ago
I'd argue that unit would be just as cryptic as monostate, if you don't know what either is.
Like, if we assume someone looking at code with `std::unit`, what might they think this is? If one is not aware of its use in ML or similar, it could just as easily be assumed that it could be something to do with units like meters or kilograms or whatnot. After all, the C++ standard library is vast so it wouldn't necessarily be all that far-fetched.
Then the only question would be to ask why it would be default-constructible. At which point you'd have to read the docs for the type anyway.
- lmm 2y ago> I'd argue that unit would be just as cryptic as monostate, if you don't know what either is. And if my grandmother had wheels she'd be a bicycle. Of course if there wasn't a standard name for this concept that had been used in the industry for 50+ years (and in theoretical work for over 100) then it wouldn't make any difference what name you used for it. But given that there is a standard name for this concept that has been used in the industry for 50+ years, making up a different name is pretty unfortunate.
- jcelerier 2y agoI mean, the industry is composed by much, much, much more C++ than ML programmers
- mananaysiempre 2y agoIt’s called “unit” because it is a unit of the operation of multiplication / constructing a tuple (up to a unique isomorphism): for any type 't the tuple types unit * 't and 't * unit are isomorphic to 't. When you don’t have that as a fundamental operation in your type system, like ML does, then it could be confusing.
- xdavidliu 2y agosure, but I would be surprised if a significant fraction of programmers knew that. When we hear the word "unit", that's not the first definition that comes to mind.
- omnicognate 2y agoThere is indeed a units library [0] aiming for standardisation in C++29. [0] https://github.com/mpusz/mp-units https://github.com/mpusz/mp-units