4 ms·
It's not just Java! I see this all the time in C and C++ as well. Developers seem to be afraid to use types as they were intended. For example, look up any Open
by tXEHOKhd 9y ago
It's not just Java! I see this all the time in C and C++ as well. Developers seem to be afraid to use types as they were intended. For example, look up any OpenGL question on StackOverflow and you'll see things like what should be an array of 3D vertices with separate x, y, and z components passed as a 1D array of floats.
In C++ we see quite a bit of abuse of std::pair<> instead of just making a fucking struct to hold 2 properly named, easy to read pieces of useful data. Nope! Apparently calling all your data members "first" and "second" is better to some people.
I don't know if it's an educational problem, a language issue, or something else, but I see it so frequently that there must be some common underlying cause (or set of causes).
- leeter 9y agoIt's an educational problem, Chandler Caruth of LLVM gave a really good talk on POD type slicing and how useful it can be. More to the point that for PODs it's supported in the standard. I do agree on the abuse of pair... pair is there for implementers primarily and shouldn't be used outside of deliberately templated code. Ditto tuple. That said... with C++17 destructuring... it's a lot less painful since you can do the equivalent to a std::tie in a single line.
- apta 9y agoWhat was the title of the talk?
- throwaway613834 9y agoOne problem in C++ is if you define a struct then you have to define a bunch of operators yourself (operator<, etc.) which gets annoying after you've realized you've needed them a bunch of times.
- marcosdumay 9y agoDoes C++ Pair<> define operator< and operator>? That's surprising, and for me looks completely uncalled for. EDIT: Just looked into Haskell (because it's easier), and tuples do derive Ord there. Is there some universal convention I'm missing?
- throwaway613834 9y ago> Is there some universal convention I'm missing? Tuples are always compared lexicographically, is the universal convention. Not sure if that's what you might be missing?
- khedoros1 9y ago> Does C++ Pair<> define operator< and operator>? It does. std::sort(pairarray.begin(),pairarray.end()) works about how you'd expect, as long as operator< is defined for the constituent types of the pair.