Le 22/12/10 21:28, Paavo Helde a écrit :
My gut feeling is this is just to mirror the std::copy interface.
However, given the more symmetric nature of std::mismatch() a more
symmetric interface would have not been unappropriate indeed.
Maybe it would be if it were not about such a remote corner of STL. I
have never seen anybody mentioning std::mismatch() in this group before.
Well, it is about software design. The ommission of end2 is the *result*
of a certain software deisgn, that you explain quite well here:
In C++, the program is responsible for ensuring that *all* parameters to
the standard library functions are valid, not only the third parameter of
std::mismatch(). For example, also the first range for std:mismatch()
must be valid, one may not pass a start iterator from one container and
end iterator from another, for example. However, STL does not guarantee
any protection against such errors, this is just UB.
Exactly. The programmer is supposed to never make any mistake, and any
mistake, even a completely trivial one, produces immediately a
catastrophe. Yes, there are debug versions, but they are optional,
the library itself doesn't even mention the errors even less specifies
what happens when an error occurs.
This means that a crash (at best) or memory corruption are considered
a "fact of life" just to avoid a negligible performance overhead.
Similarly, such an
error could be avoided by changing the interface to the function, for
example passing a start iterator and a count instead of the iterator
pair, or by passing a reference to the container plus start and end
indices. I do not see much difference to the missing end2 parameter case,
why are you so obsessed with this specific design decision?
Because I was writing that particular function for my container library.
I thought it would be a good idea to be compatible with C++, so I asked
here. I was startled that in C++ you pass a start point for an
iteration without passing the length or a way for the library to check
its arguments. Then I was appalled that there wasn't any error analysis
AT ALL. Nothing. It is just assumed that the programmer never makes
mistakes and that any mistake is fatal as a matter of course.
Incredible but true.
If you want to make a proposal of changing the standard and for example
add an overload with end2, there are ways to do that.
I know, but after the negative reaction here I think that it is not
really a good idea. People here seem to believe that fast execution
speed is the ONLY criteria for good software. Error analysis, software
rebustness and security are criteria that do not seem to interest
people, or at best they are an afterthought.
It is not just "mismtach". It is an example of a certain way of
designing software, that is why the discussion is so interesting.
We have witnessed a quantum leap in hardware performance, machines today
are 20-30 times FASTER than just 10-15 years ago but we go on as
programms would need only one criteria: raw performance. Then we get
into monstruosities that nobody understands any more and crash sometimes
for unknown reasons but there is just not any means of finding out what
happens.
Some programmer in a hurry left a "mismtach" call with an "off by one"
bug and left the company. The code part wasn't used very often, and the
wrong call produced only some missing data in the pipeline that nobody
noticed. The program would just crash sometimes but nobody can tell you
why.
Sounds like you have seen that kind of situation?
Error analysis is the first part of software maintenance. It AVOIDS
nightmare situations like that. Let's face it. There are good
programmers, and bad programmers. Good programmers are good most of
the time, bad programmers are bad most of the time. But even exceptional
programmers do mistakes. Mistakes are an INHERENT part of programming,
and good engineered libraries take this fact into account!
Again I would like to stress that I am exposing my personal point of
view, and I am not implying that people that do not agree with me are
bad programmers, etc.
Thanks for your contribution.
jacob