M
Michael Doubez
On 22/03/2011 16:56, Michael Doubez wrote:
On 3/20/2011 7:42 AM, James Kanze wrote:
James Kanze wrote:
[...]
And in my experience, something like 95% of the programmers seem
to have learned it along the lines of what Stroustrup presents.
So, summed up, your position is that IF the first sheep jumped offof the
cliff and sheep have been following that precedent ever since, then that
should be the overriding basis for decision on what action to takegoing
forward, rather than the alternative, which is to think about it and then
make a decision. Yes?
No. My point is that if there is a generally accepted
convention, and there is no good arguments against it,
readability favors going along with the convention. The most
wide spread general convention is to use int, unless there is a
good reason to do otherwise.
I don't really believe this. We've seen two well known experts agreeing
with you, but that's it, and Meyers doesn't actually do C++ development
(except for his experimental stuff when he's trying to figure thingsout
or writing a presentation). I've personally seen a lot more application
developers, people using C++ to make products (whom you call "experts")
who believe that 'unsigned int' offers two clear advantages when it's a
reasonable option:
1) it clearly documents that the function is expected to only accept
positive numbers.
And at the next iteration, you may need a singular value; keeping the
parameter signed allows you to use negative values (and you avoid the
horrible std::string::npos notation).
There is nothing horrible about the std::string::npos "notation"; it is
perfectly fine.Except that it clutters the code and cannot be used as a start
position: you have to test against it along the whole chain for simple
parsing.
Any and all uses of symbols rather than values for constant expressions
"clutters" code. Had a boss once that told me the same thing about
new-style casts.
Well, new style cast are ugly but have the advantage of discouraging
their use and make them standout in the code (and grep for them).
I use boost:ptional on a regular basis. I probably wouldn't for the
suggested case here, but it has proved itself quite useful. You
shouldn't discount it so easily.
I use it as a return value and in some cases of variables and/or
asynchronous operation result (somewhat like an homespun future) but
not as a parameter.
I suppose it is a naming issue, Fallible<> if not a good parameter
type name while optional<> make somewhat sense.