James said:
On Aug 12, 8:06 am, Pavel <dot_com_yahoo@paultolk_reverse.yourself>
wrote:
Google won't let me post a detailed answer to all your points;
it's too long. So I'll just summarize a few of the more
pertinent ones...
First, I won't bother going into which language is more popular,
or growing, or shrinking, or whatever. Neither of us have the
gift of prophecy, so in the end, the only real factual statement
we can make is "we'll see". I just don't see C++ dying out any
time soon, especially since Microsoft has embraced it (at least
in name---perhaps in the future, will all be programming in
C++/CLI
).
Second, with regards to the function "increment":
-- Even in the case of Percentage, the way C++ spells it is
Percentage:
perator++()
Does it? Did you solve my puzzle
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string a = "35" + 1;
cout << a << endl;
return 0;
}
?
Perl would give one of intuitively expected answers -- see
perl -e 'print "35" + 1'
and Java would give the second one (you can certainly come up with the
code itself). Bad enough (Python reports the error in clear language
(TypeError: cannot concatenate 'str' and 'int' objects) -- one of the
reasons it is my favorite from syntactic viewpoint), but none of these
goes as far as C++. Now tell me honestly C++ is most expressive here --
and I only used overloads The Standard Library offers. Of course your
"C++ way" goes much further:
To inter-operate between your Percentage class and other "glorified"
numbers (say, to multiply percentage to some quantity or whatever) you
will have to overload helluva lot of operators and/or allow same amount
of conversions. The consequences for a reader of the code including
<percentage.h> (and maybe <quantity.h> and all other thinkable types of
things of which percentage can be taken in a single source) is a
guaranteed headache. Plus I doubt an author can actually foresee all
such consequences. So, I would rather go with my version in C++, whether
it is "the way C++ spells.." or not, in your opinion. It is certainly
imperfect but IMHO much closer to "perfect" than introducing Percentage.
(but that's really neither here
nor there---there are definitely functions which modify
state, for which there is no pre-defined operator).
-- Functions which modify state are normally members. You
don't write increment( object ), but rather
object.increment(). At least in principle: there are times
when, for various reasons, it's not possible, but it does
mean that the number of times the question comes up is
greatly reduced.
No, you are confusing the number of times you would *use* the non-const
reference as a parameter and the number of times I had to review the
code using such references written by someone (who was not you).
Until there is no such sanction as disbarment in C++ as opposed to
legalese (even though the former might not be much simpler than the
latter), the easiness with which such mines are planted keeps and will
keep a lot of practitioners and managers away of C++. Not that I would
support such kind of regulation..
-- A function named "increment" increments, i.e. it modifies
state. Otherwise, it would have a different name, e.g.
"incrementedValue", or borrowing from Pascal "successor"
(which is better depends on the semantics of the object).
If for some reason it is not a member, it takes a non-const
reference as parameter. Period. You don't have to look
further.
Then why to look at all? Just assume (as you just did) and put your
signature?
-- A function which modifies state is not used in more
complicated expressions: if it returns a value, it is the
old value, to allow client code to restore it. In the case
of increment, this is silly, of course, because if you know
the new value, you know the old. But in the case of things
like std::ios_base::setf(), etc., it's very useful. In the
case of member functions of objects with identity, it's
sometimes useful to return *this, to allow chaining, but
that's about the only case I can conceive of where you'd
return the "new" value.
And so you would just assume the person who wrote the code you are
reviewing conceived same way as you and write your name on the dotted line?
For the rest, expressivity is there for you to use, when
appropriate. It can obviously be abused, but that's not the
point.
That exactly is my point that you are trying to avoid by all means. I
already agreed with all your points that C++ has a lot of powerful and
"cool" features (you can call them expressive but I would be more
comfortable if you used this term consistently with some definition
preliminary agreed on between us. ( think, for example, that overloading
is closer to anti-expressiveness than to an expressiveness as it creates
ambiguity about which you will probably agree that it is an opposite to
expressiveness). In fact, I have never argued with them.
But even accepting your language, here is an extreme example: Atomic
bomb is very powerful and expressive, maybe even more powerful and
expressive than C++ so let's let everybody use it; abuses are not the
points and their victims are not "correct" victims; they probably simply
needed more experience or did not understand something.
It is the responsibility of the development process to
ensure that it is not. And you need the development process,
regardless; abuse of expressivity isn't the only way you can
foul up a project, far from it.
Of course not; but in my experience it is an often way enough to be
concerned with it. "Development process" is not a legal subject of being
responsible; people are, but they happen to have different priorities
and different ideas about what the development process should be.
Expressivity is a positive
feature, always. (That doesn't mean that C++ doesn't have other
problems. But expressivity, or the lack of it, certainly isn't
one.) The most obvious proof (except that it probably doesn't
prove anything about software engineering, but more likely
something about social psychology) is that all languages evolve
in the direction of increasing expressivity: Java has corrected
some of its problems, for example, by adding to the language
(e.g. templates), and will doubtlessly continue to do so if it
is to survive (and even if it just survives---today's Fortran is
a far more expressive language than the one I learned in the
1970's).
If you want to discuss specific problems in C++, fine. There's
certainly no lack of subject matter. But too much expressivity
is NOT a defect, it's a definite advantage.
No, seriously, let's define "expressivity". If C++ has too much or too
many of anything, IMHO these are features (many of which are certainly
useful) and the ambiguities they create for a reader who cannot keep all
contents of all headers in his/her head (and I have never met anybody
who could in my life).
And for the most
part, the points you've raised are points where C++ has a
definite advantage. (You can't write your increment() function
at all in Java, for a built in type. So if even discussing the
function has any relevance, Java is at a disadvantage.)
Again, your definition of "advantage" seems to be different from mine
and close to "having more useful features" (please correct me if I am
wrong). Java has less (syntactic) features than C++, no doubts here;
however this is one of its properties that makes it attractive to
project managers (who need to hire people, maintain old code, all at
fixed costs, etc). BTW It can still express all the same programs except
for system-level ones (the latter is not due to the lack of features).
(One last comment, with respect to using forward declarations in
C. Been there, done that. While they're obviously the way to
go for entity objects, you can't implement true value semantics
using forward declarations. Which is a major drawback if you
want or need value semantics.)
Certainly not. If I need *pure* value semantics I can simply use
structures. And for "hybrids" (say, structures with integral and
variable-length strings data members) it is always safer and often more
efficient to honestly treat them as "entities" (I am not sure this is a
common term, I would use "objects" but let it be) which they are -- in
any language. C++ provides convenience here (in comparison to C), I am
not arguing -- but only a "constant size" convenience, so to say. If I
Objects (with constructors & destructors) were only differences in C++,
I would take it instead of C..
--
James Kanze (GABI Software) email:
[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
-Pavel