Future of C++

P

Pavel

Ian said:
Truly, I am not sure what I meant. Apparently thought of replacing
template parameters. Did not read clear :).
That's because a programmer can't write BigDecimal with natural
operators in Java, so the language has to provide it.
I think one of us is confused here. Java has BigDecimal as a regular
Java class -- it is in fact written in pure Java and the source is a
part of Sun's JDK distribution.

No, Java BigDecimal *cannot* be used with operators -- my point was
exactly that it cannot and nobody seems to suffer from it, and nobody
seems to even have voted or created a bug to add operator support there.
Other languages
have to add extra built in features because they lack the expressiveness
to enable programmer' to roll their own. Look at the hoops C had to go
through to add a complex number type.
Now what you refer to as expressiveness seems to be closer to what I
call syntax sugar. And my attitude to syntax sugar is: "nice to have
when it is safe". Safe includes unambiguous (not only technically, but
also from the point of view of some representative population of the
users -- that they understand the code and the consequences).
I think the above comment form James is very pertinent here.

well, you do not even want to know whether b*b - 4*a*c >= 0 and whether
a is a zero or very close to zero before taking sqrt?

In real programs, you have to introduce breaks often -- you almost never
just translate math formulas into a programming language. Not to mention
you often need to first re-factor formulas for reasons other than
catching pure domain errors; for example for numerical stability or for
efficiency reasons and after such re-factoring they often become
algorithms with much shorter formula-like pieces; but instead become
pliable to factoring out useful functions (think Horner scheme).

But even assuming such breaks are unnecessary, how really bad something
like

div(add(neg(b), sqrt(sub(mul(b, b), mul(4, mul(a, c))))), mul(2, a));

is (especially considering all editors now do parenthesis matching for
you)? Don't get me wrong, I would prefer operators and I will use them
in C++ myself for clearly numeric types -- unfortunately the language
does not limit their use for such types even though it has all the
information about the type at a point where an operator is used.

-Pavel
 
I

Ian Collins

Pavel said:
Truly, I am not sure what I meant. Apparently thought of replacing
template parameters. Did not read clear :).
OK.
I think one of us is confused here. Java has BigDecimal as a regular
Java class -- it is in fact written in pure Java and the source is a
part of Sun's JDK distribution.

No, Java BigDecimal *cannot* be used with operators -- my point was
exactly that it cannot and nobody seems to suffer from it, and nobody
seems to even have voted or created a bug to add operator support there.
I didn't realise it was a regular class (I don't do Java!).
Now what you refer to as expressiveness seems to be closer to what I
call syntax sugar. And my attitude to syntax sugar is: "nice to have
when it is safe". Safe includes unambiguous (not only technically, but
also from the point of view of some representative population of the
users -- that they understand the code and the consequences).
I still think most C++ programmers are familiar and at ease with
operator overloading. I'd even go so far as to saying they aren't C++
programmers if they are not. Don't forget the C++ design goal of
enabling user defined types to be as close to built in ones as possible.
well, you do not even want to know whether b*b - 4*a*c >= 0 and whether
a is a zero or very close to zero before taking sqrt?

Most of my types are integer and the operations used are basic arithmetic.
In real programs, you have to introduce breaks often -- you almost never
just translate math formulas into a programming language. Not to mention
you often need to first re-factor formulas for reasons other than
catching pure domain errors; for example for numerical stability or for
efficiency reasons and after such re-factoring they often become
algorithms with much shorter formula-like pieces; but instead become
pliable to factoring out useful functions (think Horner scheme).
I have a number of real world examples where I objects as parameters for
templates that perform basic arithmetic on their type. I'd hate to have
to specialise them for all non-POD types.
But even assuming such breaks are unnecessary, how really bad something
like

div(add(neg(b), sqrt(sub(mul(b, b), mul(4, mul(a, c))))), mul(2, a));
Close to indecipherable!
is (especially considering all editors now do parenthesis matching for
you)? Don't get me wrong, I would prefer operators and I will use them
in C++ myself for clearly numeric types -- unfortunately the language
does not limit their use for such types even though it has all the
information about the type at a point where an operator is used.
The most important parser is the human reading the code. We are used to
seeing arithmetic expressed with standard operators and can pretty well
subconsciously parse them. With anything else we have to consciously
parse the expression.
 
P

Pavel

kwikius said:
Its a cinch to do in Java

Object_ref operator@(Object_ref, Object_ref)

Voila! youre done. who needs all that C++ complexity !

(Sort of like they did for templates)

:)

regards
Andy Little
See, they tried to confine themselves to smaller language.. They have
introduced a lot of other stuff later (like annotations) but for a long
time they were keeping the language small and it helped to attract
people and create useful libraries. Not they did not know operator
overloading, but they consciously rejected it. Generics IMHO is an
unfortunate addition to Java language; it is such additions that will
lead it to its death (given them out once, you cannot take them back);
but IMHO C++ is much ahead there, with operator overloading, implicit
template argument deduction and their intended and unintended
combinations with standard conversions being the worst culprits.

-Pavel
 
P

Pavel

Ian said:
I didn't realise it was a regular class (I don't do Java!).


I still think most C++ programmers are familiar and at ease with
operator overloading. I'd even go so far as to saying they aren't C++
programmers if they are not.
The problem is really not in unfamiliarity or uneasiness (in fact, the
easier a writers make a decision to overload an operator the worse,
IMHO) but in amount of information one needs to unambiguously say what
function or operator is called (not even what it does but what are the
parameters).
Don't forget the C++ design goal of
enabling user defined types to be as close to built in ones as possible.
I know.. I am not sure I would share this goal now -- not without some
checks and controls.
Most of my types are integer and the operations used are basic arithmetic.
integers can be < 0 or == 0. Also, what is sqrt then?
I have a number of real world examples where I objects as parameters for
templates that perform basic arithmetic on their type. I'd hate to have
to specialise them for all non-POD types.

Close to indecipherable!
Lisp guys would kill you (I am not one of those). Seriously, does not
look too bad for me.
The most important parser is the human reading the code. We are used to
seeing arithmetic expressed with standard operators and can pretty well
subconsciously parse them.
That's the issue. C++ makes it easy to preserve a familiar syntax but
give it unexpected semantics. '+' means add() for numeric apps and most
people, and '*' means "multiply" for same domain, but a set
theorist/algebraist would not spend a second thought to make them
"union" and "intersection" for some sets in his C++ library and will
think it is cool (because C++ does not provide those special symbols set
theorists use for these operations but algebraically they have same
properties with +/- on numbers). Maybe s/he even implements his/her sets
by lists or vectors (after all, many logically unordered containers in
programming have to be implemented with some sequence underneath) and
someone who used to using "+" for concatenation (see an "Examples" table
in http://en.wikipedia.org/wiki/Concatenation to see what symbol
programmers having different background may find natural for this
operation as well what other C++ operators they may easily confuse with
concatenation or decide it natural to overload them for concatenation of
their types) will read it as concatenation and so will decide that those
sequences are concatenated by '+' operator (whereas they are being
joined, without duplicates). This latter mistake can be discovered quite
late in the game and cost a firm a fortune.
With anything else we have to consciously
parse the expression.
Which is not necessarily a bad thing, especially considering how easy it
is to make a wrong assumption for the meaning of operators (see above).


-Pavel
 
I

Ian Collins

The problem is really not in unfamiliarity or uneasiness (in fact, the
easier a writers make a decision to overload an operator the worse,
IMHO) but in amount of information one needs to unambiguously say what
function or operator is called (not even what it does but what are the
parameters).
That is provided by the context the expression is used in. If the
expression is inappropriate for the context, it will be rejected by the
programmer's peers.
I know.. I am not sure I would share this goal now -- not without some
checks and controls.
They are called good process. Hackers will hack no matter what.
professional programmers in a professionally run shop do not.
integers can be < 0 or == 0. Also, what is sqrt then?
Something I don't do on them!
Lisp guys would kill you (I am not one of those). Seriously, does not
look too bad for me.
Then I guess you re a Lisp programmer and no a C++ one :)
That's the issue. C++ makes it easy to preserve a familiar syntax but
give it unexpected semantics. '+' means add() for numeric apps and most
people, and '*' means "multiply" for same domain, but a set
theorist/algebraist would not spend a second thought to make them
"union" and "intersection" for some sets in his C++ library and will
think it is cool (because C++ does not provide those special symbols set
theorists use for these operations but algebraically they have same
properties with +/- on numbers). Maybe s/he even implements his/her sets
by lists or vectors (after all, many logically unordered containers in
programming have to be implemented with some sequence underneath) and
someone who used to using "+" for concatenation (see an "Examples" table
in http://en.wikipedia.org/wiki/Concatenation to see what symbol
programmers having different background may find natural for this
operation as well what other C++ operators they may easily confuse with
concatenation or decide it natural to overload them for concatenation of
their types) will read it as concatenation and so will decide that those
sequences are concatenated by '+' operator (whereas they are being
joined, without duplicates). This latter mistake can be discovered quite
late in the game and cost a firm a fortune.
Long paragraph simple answer: context.
 
P

Pavel

James said:
....



What does that have to do with the increment() function? You
seem to be mixing subthreads.
No, I was just trying (unsuccessfully) to return to the original topic
of passing by reference/value ambiguity and you were diverging by saying
that increment(), and even incrementPercentage() should actually be an
operator. I feel now we should have stayed with 'f()' because replacing
the majority of function names and purposes does not make sense (unless
you would state that relatively quite limited number of operators C++
has should be used to represent much bigger set of verbs and phrases
that function names can express) and I hoped to avoid discussion of
operators (simply because they would bring a whole new can of worms --
which they did :) ). I really dislike broad and generic discussions.

So, I just tried to discourage you from discussing operators by showing
how ambiguous their meaning could be but you saw it as a challenge and
decided to stay to it. :)
The "intuitively expected" answer will obviously depend on the
overall philosophy of the language:
No, for C++ programmer, it will depend on his/her background, including
other programming languages, broader professional/educational background
(see set example in another thread) and the purposes for which s/he
overloaded this operator in the past, if s/he did at all.
for untyped languages, such
as Perl, AWK, etc., the intuitively expected response is "36";
for typed languages, such as C++ and Java, the only intuitively
expected response is a compiler error. Which neither Java nor
C++ get right (for different reasons).
Let's admit there is no right/wrong here -- unless it is used in a sense
of more or less ambiguous and any C++ operator may mean the highest
number of different actions.

See, I can write:

// pgm.cpp
#include <iostream>
#include <string>
#include "myheader.h"
using namespace std;

int main() {
string s2 = "255" + 3;
string s1 = "255";
string s3 = s1 + 3;
cout << "s1=" << s1 << " s2=" << s2 << " s3=" << s3 << endl;
return 0;
}


// myheader.h or same code much deeper in included files
#include <sstream>
std::string operator+(const std::string &left, int right) {
std::eek:stringstream oss;
oss << left << right;
return oss.str();
}

And I would probably expect s1 equal to s3 as a result.

However, depending on how the + operator is defined, C++ can treat s3 as
in C, as in Java (as in the example), as in Perl or AWK or as in any
other way, some of them logical for different people and no writes or
wrongs -- at least for many definitions. And the best C++ programmer
will have no way to know until s/he reads the header file. And even
then, s/he needs to pickup the applicable definition -- which is
possible, but time consuming and requires lining up all included
overloads first. What's worse, the meaning may change after including
some other header file, directly or indirectly.

....
I'm afraid that I don't see any real difference between Java and
C++ here. Not that it's really relevant; neither language is
perfect, and no reasonable person would pretend the contrary.
Both have their flaws. The basic question concerns the
totality, which depends on the application domain, but
doubtlessly favors C++ over Java most of the time.
see the example above
And? Designing a good interface does require a bit of typing.
And I'm not sure that you'd need that many overloads for
percentage. Not every operation makes sense on a percentage.
No, but adding a percentage makes sense for a values of different types.
Think of BigDecimals etc you introduced to the dis?ussion earlier; with
a slightly different semantics (say, rounding) of addition, then think
of people who will want to have a conversion from BigDecimals to, say,
doubles (isn't it natural -- all of these are numbers, after all), and
then think which particular operator '+' will be called if you have few
of them defined.

Also you correctly mentioned that the definition of some
application-specific numeric types like Price or Quantity or Money may
migrate from BigDecimal to double.. under all these possibilities do you
still want to use an operator and uniform syntax?
No. You're confusing your personal experience in poorly run
shops (where any language would fail) with absolute truths.
Well, this does not stand my experience:

1. I am not familiar with a single absolute truth.

2. There was no / is no pure failure -- there are costs related with the
projects in different languages. What you are essentially saying -- "if
you have never worked in a shop where C++ projects could be as
successful as the projects in C / Java etc ("success" can be defined
quite unambiguously in terms of meeting requirements in time at lower
cost etc) -- then you did not work for a well-run shop". I should
probably agree to you then -- I have to really think if I worked for
one, but I might as well agree that I have never worked for such a shop;
the only thing is I do not agree to define "well-run" in terms of
suitability for C++ specifically.
Exactly. Why look further.
And then, when the returned value will be (or not be -- whatever is
contrary to your assumption) the increased argument, you will share the
responsibility for not really reviewing the code; in fact, you will
carry greater responsibility as you were supposed to be a gatekeeper.
I would assume that any code which passed code review was
conform to the conventions in use in the company.
No, the code has not been reviewed yet, you are reviewing it now. Will
you just assume the effect corresponds to the name or you will go seek
the applicable definition? And if you have to go see the definition,
won't your performance be impeded by this (as comparing to C, in which
case you will not have to go see definition if you see the argument is
passed by value).
Which is, after all, exactly what software engineering is all
about. If you don't do that, you might as well pack it up and
go home; no language is going to work for you.



The ability to say exactly what you want, clearly and concisely.
Does it include the ability of the reader to understand what you wanted
to say, clearly, easily and unambiguously? If not, I agree with all you
said about expressivity but do not think it is an advantage; if yes, I
disagree that C++ is more expressive than other languages; I would
rather argue it is one of the least expressive languages as the
understanding is most difficult and ambiguous although sometimes
deceptively clear.
My definition of "advantage" is, in the end, something that
reduces the cost of software development. Expressing exactly
what you want, clearly and concisely, definitely reduces the
cost of software development, and so is an advantage.
See my answer above
There are two things which make Java attractive to project
managers: the first is simply that it is more or less
"in"---it's not a good reason, but it's probably the most wide
spread one. The second is the support structure which is
available for certain types of applications.
There are many reasons, I agree, but low entry barrier and simple, less
error-prone syntax are clearly a big one.

Most algorithm courses changed their algorithm-teaching classes from
everything (Algol/Pascal/C++/MIX) to Java -- why if not for Java is
easier to learn and does not make a student to think too much on a
syntax, by that leaving more brain power to think on the problem). If
C++ were just "more expressive" but did not carry prohibitive costs with
it, they would be taught in C++.

(And no, it is not only because students can nicely present their
results as applets -- I am saying that because most assignments I saw on
the Internet ask to output the results on the console or file, probably
to spare them having to learn a lot of things irrelevant to the
algorithm course).

BTW, the fact that most students study Java as their first language has
some significance for the future of C++, too. I mean, to be popular with
Universities would definitely help a language to survive / prevail /
stay in wide use / grow -- the right verb depends on its current
standing in the industry.
Sure. It's Turing complete. You just can't express them as
clearly and concisely.
Again see the paragraph above about your definition of expressivity.

A structure doesn't necessarily have the semantics you want in
your pure value.


And that's simply wrong. A value is a value, and has entirely
different characteristics than an entity. Look at
java.lang.String, for example, for an example of a well designed
value in Java. (Note that it is final, has no mutable members
and... has overloaded operators.)
You are confusing me. I think you are introducing new concepts to the
discussion on purpose. Please defined them first. You complained that
with C you have to cross your fingers that nobody manipulates the fields
of the structures which you only wanted to be manipulated via functions.
I told you it can be assured by exposing forward declaration only and
hiding definition in the implementation files. How does such code change
make these structures entities from values in this sense in which you
started using them now (still not sure what it is, precisely)?

Also, why I cannot represent the analog to Java string in C if I hide
its declaration (but, I assume, I can do it if I do not hide it?)?

-Pavel
 
P

Pavel

Ian said:
That is provided by the context the expression is used in. If the
expression is inappropriate for the context, it will be rejected by the
programmer's peers.


They are called good process. Hackers will hack no matter what.
professional programmers in a professionally run shop do not.


Something I don't do on them!


Then I guess you re a Lisp programmer and no a C++ one :)


Long paragraph simple answer: context.
I agree. I started this thread with the example where following C++ code
required studying the biggest non-local context -- as opposed to even an
equivalent C code. Can we at least agree that, given equal other
features, the language that requires studying less context to follow the
program wins in productivity and scalability?

-Pavel
 
L

LR

Pavel said:
Ian Collins wrote:


Too much, uh, context snipped?
I agree. I started this thread with the example where following C++ code
required studying the biggest non-local context -- as opposed to even an
equivalent C code.

Could you please comment on this little C snippet, as I'm curious to
know what you think of it.

int doWhat(char *s, int n) {
return printf(s,n);
}
Can we at least agree that, given equal other features,

What are these equal features? PL/I's varying string vs Fortran's
CHARACTER vs C++'s std::string vs C's strcpy etc?


the language that requires studying less context to follow the
program wins in productivity and scalability?

In context? I'm not sure. How would you prove this claim? It seems
like an argument about how programmers work vs how they claim they work
vs how they think they work.


LR
 
L

LR

Pavel wrote:

1. I am not familiar with a single absolute truth.

See 1. above.
Most algorithm courses changed their algorithm-teaching classes from
everything (Algol/Pascal/C++/MIX) to Java --

Can you please tell me what your source for this is?

why if not for Java is
easier to learn and does not make a student to think too much on a
syntax, by that leaving more brain power to think on the problem). If
C++ were just "more expressive" but did not carry prohibitive costs with
it, they would be taught in C++.

I was under the impression that universities pick languages for many
reasons and not just some "technical" superiority. For example, a
professor might like one language and not another, or because of
pressure from local industry or parents who are worried about, or at
least claim to be worried about, the careers of the students. But I'm
not an academic. I snipped it, but I think that you made a similar
point about why companies choose certain languages. In fact, I think
this is a FAQ.



BTW, the fact that most students study Java as their first language has
some significance for the future of C++, too. I mean, to be popular with
Universities would definitely help a language to survive / prevail /
stay in wide use / grow -- the right verb depends on its current
standing in the industry.

Yes. Of course. You might find what Joel Spolsky has to say about C and
pointers instructive:
http://www.joelonsoftware.com/articles/fog0000000073.html

Come to it, you might find what he has to say about Java as a teaching
tool instructive as well:
http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html





Also, why I cannot represent the analog to Java string in C if I hide
its declaration (but, I assume, I can do it if I do not hide it?)?

I'm not sure that I follow that, but assuming I do, how could you
accomplish that?


LR
 
M

Matthias Buelow

Ian said:
That's simply not true. My (and other teams) experience is that a pair
is more productive then two individuals.

You're insane, or your examples are trivial.
Do you really think you can make a programming job attractive to people
if they have someone else looking over their shoulder all the time?
Sounds like programmer's hell to me.
 
M

Matthias Buelow

James said:
And on what types of projects---I find
that at certain points, the limiting factor of my production is
typing speed.

If that is the case, then you're simply using a level of abstraction
that isn't high enough. I never found that _typing_ is a limiting factor
of programming, I'm not a secretary, after all.
 
J

Joe Greer

course, compared with all of the rest.) Get rid of pointer
arithmetic, and C++ does the right thing. Get rid of the
conversions of numeric types to string in Java, and the Java
version does the right thing.

I think the problem isn't so much pointer arithmetic as it is that C++
doesn't have a built-in string type and there is only so much you can do
with a library only solution. Personally, I think that strings are so
fundamental that we really need a literal that represents a string and not
an array of chars.

joe
 
I

Ian Collins

Matthias said:
You're insane, or your examples are trivial.
Do you really think you can make a programming job attractive to people
if they have someone else looking over their shoulder all the time?
Sounds like programmer's hell to me.

What part of working together don't you understand?
 
C

coal

-- and will with the probability increasing with the size of
the project. It is just an incredible luck to never have a
person who does not care enough or simply does not fully
understand the [complex] process on a team of a significant
size during a significant time period (both are required for
sizable projects).

I can see you've never worked with any sort of process.  It's
extremely rare to find someone who intentionally wants to make
life hard for others.


Twenty years ago I think there was some truth to that.
Increasingly though due to a drop in morality there are
problems like this:

Cockpit conflicts 'threatening safety'
Younger pilots allegedly bullying older airmen
into resigning or retiring to save their own jobs
http://www.aftenposten.no/english/local/article2615859.ece

I saw some of this coming years ago and started Ebenezer
Enterprises to avoid the crappy work environments those
pilots face. I'm thankful to G-d for leading me to start
the company.

Brian Wood
http://webEbenezer.net
 
J

James Kanze

If that is the case, then you're simply using a level of
abstraction that isn't high enough. I never found that
_typing_ is a limiting factor of programming, I'm not a
secretary, after all.

If you've done the design an analysis, the programming (coding)
itself is pretty much just typing. If it isn't, then you've not
done enough design up front.
 
S

Stefan Ram

James Kanze said:
If you've done the design an analysis, the programming (coding)
itself is pretty much just typing. If it isn't, then you've not
done enough design up front.

»Coding is design, testing and debugging are part of
design, and what we typically call software design is
still part of design.«

This quotation is a little bit out-of-context,
so I recommend the whole article:

http://www.developerdotstar.com/mag/articles/reeves_design.html
 
I

Ian Collins

James said:
If you've done the design an analysis, the programming (coding)
itself is pretty much just typing. If it isn't, then you've not
done enough design up front.

Or you follow a different process.
 
C

coal

I think this would be improved by taking out the words
"pretty much just." The typing process is more complicated
than any man-made system. A brain injury is helpful in
reminding you of the difficulty we endure to acquire
dexterity.

We go through an iterative process of design and
programming where we improve the design based on what we
learn from implementing the design and from testing both
the design and implementation. If you try to bite off
more than you can chew, you can become bogged down in
the design work.

Or you follow a different process.

I don't recommend putting monkeys in a room and
hoping they'll eventually solve the problem.


Brian Wood
http://webEbenezer.net
 
C

Chris H

kwikius said:
That said C++ and C will be around a long time. For windows they will be
around as long as its around I guess, but I don't see there being as much
demand for C++ programmers.

C and C++ are separate languages. C will be around for a very long
time and it is very widely used in some rather large areas. Particularly
those where there is no C++ It will outlast C++ by a long way as there
is nothing like Java, C#. .Net and other languages snapping at it's
heels
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top