4 ms·
Ok, then blame it on the STL. Its API gives you extreme flexibility, but at the cost of extreme complexity. In a language like Java or C#, as the parent state
by kelnos 13y ago
Ok, then blame it on the STL. Its API gives you extreme flexibility, but at the cost of extreme complexity.
In a language like Java or C#, as the parent stated, a Map<String, String> is really more or less just that.
In "real" terms, I don't need a string of anything but char (say I only use utf-8, or perhaps I just don't care what std::string uses as its internal encoding and will expect there to be methods on it to give me encodings that I want), so std::string being a std::basic_string<char> underneath is useless to me. Kill that flexibility.
I don't care about the allocator used. Kill that flexibility.
Etc.
Ok, so then std::string is now just... std::string. Cool.
On to the map. The comparator? Not sure why that needs to be a template parameter (though I guess the type-safety is somewhat nice); why can't I construct and pass one into the constructor or a setter at runtime? Kill that from the template.
Again, with the allocators. I don't care. Kill them.
Ok, now the MapStringToString is really just std::map<std::string, std::string> and nothing more. Awesome.
Sure, you can't blame the complexity of C++ generics on C compat or manual memory management: it's the STL's very powerful API. A very powerful API that makes no effort to hide the complexity it exposes. Arguably generics themselves in C++ aren't to blame at all. And so it follows that generics in Go need not be complicated and painful either.
- AnimalMuppet 13y ago"I don't care" is not the same as "nobody cares", and especially not "nobody will ever care". Why would somebody care? Well, C++ gets used a lot in embedded systems. There, you can have different storage pools for different specialized kinds of memory. But if Go isn't trying to solve those kinds of problems, then Go doesn't need the same machinery that C++ does. It doesn't make C++ stupid, it makes it designed for a different environment. Also note that C++/STL templates default the allocators and comparators, so you don't need to supply them unless you really need them. That's pretty much what you're asking for... until you try to read a compiler or linker message.
- kelnos 13y agoSorry, I wasn't clear in my overall message. The only point I was trying to make is that "generics error messages are hard to read in C++" is false: it's really that STL-related error messages are hard to read. If someone wanted to build a simple standard library that omits a lot of the complexity provided by the STL, they could do so, and the error messages would likely be readable.