3 ms·
The more general rule I follow is that there are only three cardinalities in software - 0, 1, and many. Default should be many. Any other limits you put is like
by vaidhy 4y ago
The more general rule I follow is that there are only three cardinalities in software - 0, 1, and many. Default should be many. Any other limits you put is likely to be incorrect.
- kragen 4y agoThis is appealing, but taking this advice seriously means that all your relationships are many-to-many, until you optimize some of them to be one-to-many or one-to-one. This clashes extremely strongly with the currently popular approaches to software development (OO, procedural, Lisp/ML-style functional, SQL, etc.), which have an extremely strong default of cardinality 1, inflicting lots of extra work on you for many-to-many relationships. You'd never have a member of a struct or a class start out as an int or a string; they would always be int lists, string lists, etc. Points would have a list of X coordinates rather than a single X coordinate; interpreters would interpret a list of programs; 3-D objects would have a list of transform matrices rather than a single transform matrix; files would have a list of owners. (And of course in languages like C and Golang when you nest a Foo object inside a Bar object, you are foreclosing the possibility of that Foo having the same relationship with some other Bar object as well; you need pointers.) Systems that do support that kind of thing in one way or another include Prolog, miniKANREN, the APL family, and Pick. But Prolog and APL only support it to a very limited extent, and I've never used Pick or miniKANREN.
- vaidhy 4y agoI am not sure I understood your arguments because of where these get applied. I generally mean to apply these when we talk about business constraints - in my field of supply chain optimizations, these kind of things come up often. How many trucks do you plan between nodes? If the answer is 2, it means many. Being explicit about 0 and 1 means that if that constraint is broken, it means a more through code analysis as it would lead to some unexpected breaks in various systems.
- kragen 4y agoI certainly agree that 2 should be "many".
- swyx 4y agowhat does a cardinality of 0 mean? i dont even think an attribute should be on the schema if the cardinality is 0? or am i experiencing a brain fart and missing something obvious
- Sohcahtoa82 4y agoThis comment reads like it's trying to disguise pedantry as confusion, which is an obnoxious trend on HN. Keeping with the original "user on a team" example, allowing a cardinality of zero means that you support a user not being on a team at all. This may be a bastardization of the definition of "cardinality", but I think you understood that.
- swyx 4y agono i didnt, and it was a sincere question. im the guy who wrote the post and i didnt understand cardinality zero lol.
- vaidhy 4y agoIt is what swyx said.. cardinality not in the mathematical sense.. but the fact it does not exisit, there is exactly one instance of it or there are many instances of it. Going from one to another means refactoring/through testing as there would be side effects all through the system.
- swyx 4y agoalso a list of known things that are cardinality 1 could be valuable, since someone coming across this advice people might swing too far over to the always-many side