Okay, first I respect Disch as a programmer so this isn't an attack on him.
Did you even read the full thing or just see the title and blindly agree?
Disch from that link wrote: |
---|
I probably should've made the article less opinionated. I actually tried to tone it back (I really dislike MD arrays), but it is still pretty 1 sided.
In any event, I agree that in general arrays should be avoided and that a container class should be used. But since STL doesn't provide a MD container, you're better off getting one from somewhere else (boost?) or making your own (above). It's much more preferable to vectors of vectors, IMO... and that's really the point I was trying to get across here. |
Stroustrup quote from the article wrote: |
---|
The built-in arrays are a major source of errors – especially when they are used to build multidimensional arrays.
For novices, they are also a major source of confusion. Wherever possible, use vector, list, valarray, string, etc.
|
The article is based off Disch's opinion that they are evil. They are a major source of errors, but human error is also a major source of errors. For novices they're a source of confusion, but so is learning the driving laws and rules for getting your license. Confusion doesn't make something evil (otherwise anyone starting a new job would never get good as they would quit saying it was 'evil').
The first and most dominate error I can think of with arrays is declaring it to be a size (say 30 ints
int array[30];
, numbers 0 to 29) and then trying to access out of bounds on it
array[31];
.
Also, raw pointers, again opinion of preference. Everything Disch is saying is bad about them, others may not have a problem with. Lumpkin, you have to learn all aspects of C++ and form your own opinion of them and not blindly follow someone else's opinion on the feature. Just like I've seen mixed feelings on Boost here (for and against), but I've only used it once and it wasn't enough to form an opinion on it so I have not passed my judgement on it.
Lastly, Disch is right on the passing arrays to functions, but I can't say I've ever seen anyone use built-in arrays of different sizes often. When I code something and know my arrays are going to be separate sizes I either use vectors or just go through the added trouble of making separate special functions specifically for those arrays. Still doesn't make them evil, just adds a few extra lines and steps to your code.