8 ms·
Yeah, moving away from the abstract algebra names definitely improves clarity because ``template <typename HasABinaryAssociativeOperationAndIdentity>`` is a muc
by freyrs3 13y ago
Yeah, moving away from the abstract algebra names definitely improves clarity because ``template <typename HasABinaryAssociativeOperationAndIdentity>`` is a much better choice than Monoid.
- Pacabel 13y agoYour examples are either at the extreme of literalness, or at the extreme of abstractness. The most useful name is probably somewhere in the middle. It may not necessarily consist of everyday words, but it probably relates very obviously and clearly to the C++ functionality. "Monoid" is a very detached term. It doesn't obviously relate to the C++ construct or concept the way that terms like "typedef", "template", "stream" and so on do for other constructs/concepts.
- chongli 13y agoIt may not necessarily consist of everyday words, but it probably relates very obviously and clearly to the C++ functionality. Such as? "Monoid" is a very detached term. It doesn't obviously relate to the C++ construct or concept the way that terms like "typedef", "template", "stream" and so on do for other constructs/concepts. Well of course! Monoid is far more general than those other concepts. It's also a far better name, being unambiguous. Those other names are reused all over the place in different contexts and their meanings subtly shift between their uses. Monoid is not so overloaded; once you learn it, you know what it means every time you encounter it.
- Pacabel 13y agoI'm not going to claim to have a better name at this moment. However, I would like to think that there's somebody out there who could come up with a name that describes the concept sufficiently, while still using pragmatic C++-style terminology. All I'm saying is that "monoid" is terminology of a style that's very different from basically all other C++ terminology. To many C++ programmers, even those with a background in mathematics, it's no better than gibberish. At least the existing C++ keywords and terminology tend to be far more descriptive of what they're referring to, even if there is ambiguity in some cases. This is true even for the more abstract concepts in C++.
- chongli 13y ago"Monoid" is a very detached term. What does that mean? How is it any more detached than object or method?
- Pacabel 13y agoBoth "object" and "method" are common words with very obvious parallels between the programming language concepts and similar real-world concepts that are familiar to basically everyone. That's what makes them good terminology. An "object" is something specific that exists (implying it can likely also be created and destroyed), and can be distinguished from other objects. This applies equally well to a combination of a data structure and some related code as it does to a tennis ball, or to a car, or to a book. A "method" is a systematic way of doing something. That "something" could be the operations described by some source code, or it could be tying a shoe, or even brushing one's teeth. "Monoid" has no good real-world parallel. It has no related or relevant meaning outside of very, very specific contexts. That's what makes it "detached". It's off on its own, with an isolated and non-obvious meaning.
- freyrs3 13y agoIf you limit yourself to concepts you can express by relating them to the physical-world objects and human actions then you lack the language to express abstract concepts entirely. The words used by mathematicians are chosen to describe these structures have no real-world connotations because the ideas, in their-full generality, have no representation in our every-day experience. There's no way you'll ever be able to describe any reasonably complex structure from abstract algebra by concatenating a bunch of household adjectives, it doesn't capture the full-generality or convey any more information.
- eru 13y agoYou are being too optimistic about object and method. (They look familiar because of long exposure to OOP.) The Haskell people share your concerns. Simon Peyton Jones famously suggested "our biggest mistake [in designing Haskell was u]sing the scary term 'monad' rather than 'warm fuzzy thing'". (https://research.microsoft.com/en-us/um/people/simonpj/papers/haskell-retrospective/HaskellRetrospective-2.pdf https://research.microsoft.com/en-us/um/people/simonpj/paper...).
- freyrs3 13y agoThe former was chose to make a point, but I contest the fact that Monoid is extremely abstract. It's very concrete, it effectively describes an interface and if implemented according to certain laws it is a Monoid just like a Container or Iterator. The name has existed for nearly a hundred years in mathematics, it relates very obviously to any data structure that is a monoid.
- Pacabel 13y agoPerhaps the problem is that there's no good real-world equivalent of a "monoid" that basically everybody is familiar with. Most people are inherently familiar with the concept of a "container", in the sense of something that holds other things, regardless of whether it's a physical container or a data structure. "Iterator" might not be as clear as "container", but at least most people are familiar with the concept of doing something repeatedly, whether it's some physical action or executing some chunk of source code. "Monoid" just isn't like that. It may be concrete when constrained to the context of mathematics or programming, but it's quite meaningless outside of those very specific contexts.
- voyou 13y ago"the problem is that there's no good real-world equivalent of a "monoid" that basically everybody is familiar with." But that isn't really true. Addition and multiplication are both real-world examples of monoids that everyone is familiar with (obviously, these aren't physical things, but I don't see why that's relevant).
- voyou 13y agoJust realised I may have missed your point; anyway, you're right that "monoid" is harder to find an easily-understood counterpart for than "container". There are examples of monoids which everyone is probably familiar with, but we don't usually abstract from those everyday examples; whereas as well as there being everyday examples of containers (boxes, bags), we are familiar with abstracting away from those examples in everyday life to come up with the general concept of container.
- deleted 13y ago[deleted]
- jroesch 13y agoNot really I've had Java developers look me in the face and say that the nonsense names (very much like the one above) that Spring uses are somehow more readable than simple operators or abstract names. Monoid is NOT a detached term it says I have a type with an identity element, and an associative binary operator, and that that (id `op` elem) always is elem. Try to tell me that i complicated in the slightest. I can most definitely not give you a single line description of templates, or most C++ features. Abstraction makes things more general (i.e less specific) meaning it is easier to describe, reason about, and discuss because I can only talk about things that hold universally. If you doubt me let's show some things that form a Monoid right now, and how easy it is to define. 1) Strings - identity element = "" - associative operator = + 2) Lists - identity element = list<A>() //empty list - associative operator = concat and we can go on and on finding instances of Monoids simply from a one line description.
- Pacabel 13y agoI'm not sure that Java programmers are necessarily the best judges of good naming conventions. I've personally witnessed several of them immediately mention "gonads" when first hearing the term "monad". For most C++ terminology, you don't need to give a single-line description. The keyword or concept name alone generally embodies that information very well. To use your example, at a basic level a C++ "template" is quite similar to a form letter, stencil or other real-world "templates". It's a predefined mold that you inject your specific information/material into to get a final product with minimal effort. There just isn't a direct relation back to the real world with a term like "monoid". You end up with people who are confused at best, or more likely they're thinking of some other word that sounds similar but is totally unrelated.
- eru 13y ago> There just isn't a direct relation back to the real world with a term like "monoid". And that might even be a good thing. The stencil analogy for C++ templates gives you a warm fuzzy feeling, but doesn't actually help you program. Contrast: the one line definition of Monoids is all there is to them. That's all there is to know about Monoids.
- 13y ago
- dllthomas 13y agoMonoid is a semigroup with an identity, and also a group without inverses. Learning a small amount of algebra shouldn't be scary, and the vocabulary will help you in countless mathematical fields - many of which touch directly on programming.
- username223 13y ago> Monoid is a semigroup with an identity, and also a group without inverses. Classic. Sometimes Haskell fans have useful things to say, and sometimes they're just using terminology to try to win an intellectual dick-size war. The tricky part is telling the two apart.
- dllthomas 13y agoIt's basic abstract algebra - this is literally stuff I learned in a math class 12 years ago. It's used in hojillion papers, some abstract and some concrete and highly relevant to real world problems (including encryption and linear algebra - both of which can be directly useful to programmers), and they're not even hard. Just learn some math - this is undergrad stuff.
- Pacabel 13y agoThe concepts themselves aren't difficult to understand. It's just that some people go out of their way to use uncommon terminology that ends up obscuring what they're trying to say, rather than making it clearer.
- dllthomas 13y agoIs there more common terminology for "a set with a binary operation that is associative and has an identity"?
- freyrs3 13y agoAny name that we'd come up either wouldn't capture the general case or would be just as arbitrary as Monoid ( ignoring historical usage). The gist of this argument is that Pacabel and the like can't describe the concept using the traditional OOP evocative naming style but insist that term "Monoid" is wrong because of some irrational aversion to terms from abstract algebra. There's really nowhere for this argument to go... Imagine trying trying to describe a monoidal category or topoi in the OOP style, it's like trying to describe what a Fourier transform is to someone who insists on using roman numerals.
- dllthomas 13y ago"typedef" is one of the most misleadingly named constructs in the language. You can "define a type" without it, it just changes how things are tokenized. Giving it as an example of good naming is weird.
- jfischoff 13y agoDon't you mean template <typename HasABinaryAssociativeOperationAndLeftIdentityAndRightIdentity>