how to design a replacement for C++

B

Bo Persson

Francesco said:
I will not enter into this kind of discussion, I still have a long
way to go before fully understanding the power of what C++ already
gives me.
If you feel strong enough on your feet as to suggest improvements
and additions to the language and its library, I'm sure you'll find
a lot of knowledgeable people ready to discuss them, refine them
and eventually consider them for inclusion: comp.std.c++

Most of these features already have papers written, and will be
included in C++0x.

Not all of us see it as a advantage to have compiler magic for all
specific features, but find it more useful to be able to express it as
a library. That enables more use of the building blocks provided by
the compiler .



Bo Persson
 
J

James Kanze

On 07/24/10 01:42 PM, Francesco S. Carta wrote:
I gave up at "C and C++ both get the job done in their respective
niches. And those niches are shrinking dramatically". I assume he
hasn't heard of embedded devices.

Or large scale servers. Or numeric applications.

My impression (based on working in a lot of different
environments) is that C++ is anything but a niche
language---rather, it's the language you use when the niche
you're working in doesn't have an appropriate niche language.
 
J

James Kanze

In practice, how often are pointers to member functions used?
I don't think I've ever had cause to use one except for exotic
RPC applications.

I've used them on occasion. And they're not that rare as
template arguments (or as a first argument to boost::bind).
 
Ö

Öö Tiib

"Öö Tiib" <[email protected]>
Especially long he goes on about std::map's operator []. His long
speech about its "Ha-ha" downsides felt longer than to read the <map>
header (350 lines or so).

Length of <map> is quite irrelevant. Do you defend its interface design?
In my experience it is pretty broken. Sure why stop at std::map, MOST of the
standard lib is poor quality, and it is very sad.  I try to think a list of
what is good, and nothing emerges except for vector.   And guess how many of
us had vector-like classes before the standard.

Yes it is true, std::map's operator [] is crap, but map itself is
useful. std::string i entirely avoid since it silently constructs from
char const* or char* (that are almost equal to void*). I prefer to use
std::wstring for holding text and std::vector<char> for holding binary
blocks of data.

I disagree that all standard lib is terrible. Too small it is
perhaps ... yes. underdocumented and underannounced. Standards text is
hard to read. All implementations push their non-standard crap more
than standard library.

I like the attitude that boost community carries. When something is
inconvenient or missing then why not to make it convenient and
present. One can not wait for a round table of intel, at&t, microsoft,
sun, apple and so on sit and to solve all the problems, especially
when the solutions contradict with their business interests.
The point f the standard lib would have been to give good support out of the
box -- and it more like creates pain only.    At least if used "alone".
Sure you can patch it up with your own exrtensions or popular existing
libs -- but that we could do without standard lib, could we?

Mostly because standard library is very small toolset with weak
documentation so one can live without.
I recall back in 96-97 most voces pushed "give us a standard NOW", whatever
it takes.  Possibly me too.  Did not turned up as a good idea in retrospect.
:-((((


Sure, I have  bunch of my classes that are good, and used many libraries,
just if you work on a project where using the standard lib was decided, it
is pretty hard to go ahead.  Either having different classes side-by-side,
or replacing the existing ones.  (certainly the story of map is a dwarf
compared to std::string)

Everybody has their own tools. It is because when you write for some
specific niche then too over-bloated standard library may be also
nuisance. Single toolset can not be good for all jobs. i avoid
std::string (and char in other contexts but "a byte") it does help
more than hurt.
 
M

Miles Bader

Öö Tiib said:
Yes it is true, std::map's operator [] is crap, but map itself is
useful.

Wait, why is [] crap...? (I don't use std::map very much, but when I
have, I've used [], and it worked fine, just as one would expect)
I disagree that all standard lib is terrible.

In fact, in my experience, the STL is quite good -- very usable for many
common tasks, fast, and unbloated.

I dunno why Balog said that.

-Miles
 
J

James Kanze

Öö Tiib said:
Yes it is true, std::map's operator [] is crap, but map
itself is useful.
Wait, why is [] crap...?

The usual complaint is that it can't be used on a const
std::map, because it can modify the map.

Whether this is a good thing or not depends on the application.
There is no one correct solution.

[...]
In fact, in my experience, the STL is quite good -- very usable for many
common tasks, fast, and unbloated.

It's not that well designed, but let's not exagerate. It's
still quite usable. And the libraries in other languages aren't
without problems either.
 
J

Juha Nieminen

Lynn McGuire said:
Interesting article on why C++ development may be fading but it
will never go away: http://apenwarr.ca/log/?m=201007#22

"C++ has made templates a dirty word"

I have never quite understood the general aversion towards C++ templates
out there. Maybe I'm biased.

I find that C++ templates make writing programs simpler, not more
complicated. Many things can be done with simple one-liners which would
otherwise require dozens of lines of complicated code.

A common complaint about C++ templates is the error messages they
produce. I *am* definitely biased on this aspect because I have actually
learned to read those error messages and I can usually find quite quickly
what the real problem is. (Of course it helps that compilers have got a
lot better at synthesizing the most relevant parts of the error even in
complicated templated code.) I can see, however, how a beginner programmer
can get confused with them.

However, dissing C++ templates only because they produce complicated
error messages is throwing the baby out with the bath water.

When Java was designed as a "better C++" (which is the case, no matter
how much Java people deny this irrefutable fact), they naturally left any
kind of support for templates completely out because, you know, templates
are "evil" and produce bad code.

Many years later they came to regret this, as a lack for any kind of
generic code (besides what OOP offers) was a kind of limiting factor and
produced ugly code. So rather than to succumb to the lure of C++ templates
they introduced a "better template mechanism" (and because "template" is
a curseword they couldn't use that name, and hence they invented a new
name for it, namely "generics", to avoid any negative comparisons). Of
course these "better templates" are much less useful because they cannot
be used to eg. create generic containers which can support basic types
(such as ints).

I don't know how the "generics" in C# work, so maybe they are honestly
"better" there.
 
J

James Kanze

"C++ has made templates a dirty word"
I have never quite understood the general aversion towards C++ templates
out there. Maybe I'm biased.

People don't like power:).
I find that C++ templates make writing programs simpler, not more
complicated. Many things can be done with simple one-liners which would
otherwise require dozens of lines of complicated code.

There are many uses of C++ templates. For things like typesafe
containers, they are exceptionally good---it's not an accident
that Java duplicated the syntax exactly (including the mistake
of using <..>, rather than some other parenthesing). For things
like metaprogramming, the obvious objection is that they weren't
really designed for it, and the syntax required quickly makes
the code unreadable. But of course, this complaint generally
comes from supporters of languages which don't have any
metaprogramming possibilities at all. In the end, nothing is
free, and in every individual case, you have to weigh the cost
(in terms of readability, etc.) of using metaprogramming vs. the
advantages (less code, often simpler to use, etc.) Sometimes,
the balance will weigh one way, other times the other. When the
balance is against metaprogramming, don't use it.

[...]
When Java was designed as a "better C++" (which is the case, no matter
how much Java people deny this irrefutable fact), they naturally left any
kind of support for templates completely out because, you know, templates
are "evil" and produce bad code.

Or perhaps because when Java was being designed, they were still
largely unknown territory. Java was designed as a "better C++"
based on the experience we had with C++ around 1990. Some of
the things it incorporates from C++ are things we later learned
were errors, to be avoided (i.e. putting the function
definitions inside the class, or having an iterator in which
access and stepping were bound up in a single function).
Many years later they came to regret this, as a lack for any kind of
generic code (besides what OOP offers) was a kind of limiting factor and
produced ugly code. So rather than to succumb to the lure of C++ templates
they introduced a "better template mechanism" (and because "template" is
a curseword they couldn't use that name, and hence they invented a new
name for it, namely "generics", to avoid any negative comparisons).

The name "generics" precedes that of "templates". (I don't know
why C++ chose "template", rather than "generic".)
Of course these "better templates" are much less useful
because they cannot be used to eg. create generic containers
which can support basic types (such as ints).

That's part of a larger problem in Java. Java's authors clearly
recognized the need for types with value semantics, but decided
that they knew which ones you needed, for all time. A cleaner
design would have not had the built in types at all, but only
Integer and Double classes, pre-defined along the lines of
String. And operator overloading, so that you could add and
subtract them with a reasonable syntax.
I don't know how the "generics" in C# work, so maybe they are honestly
"better" there.

I don't know if there's a "better". Different might be a more
appropriate word. (In general---I don't know C# either.) Java
templates are very good for the problem they were designed to
solve. Almost as good as C++ templates for that problem. They
intentionally don't solve other problems. C++ templates can't
be said to have a congenial syntax for many of the
metaprogramming problems, but in the end, they're better than
nothing (which is what Java offers in this regard).
 
D

Daniel

Some of the things [Java] incorporates from C++ are things we later learned
were errors, to be avoided (i.e. putting the function definitions inside the
class...).
Not sure who are the "we", but I know a lot of people won't follow you
on that one. Do you know any more recent languages that have copied
the C++ idea of splitting the implementation of a class, putting some
of it in a "header" file and the rest in a "source" file? Do you see
an advantage in separating the class data members in one file and the
implementation in another, except for the inlined implementation which
goes in the header? This doesn't seem to me to be a particularly
useful way to organize code. More useful is to separate interface
from implementation, which is not the point of .h and .cpp.

-- Daniel
 
J

Joshua Maurice

  "C++ has made templates a dirty word"

  I have never quite understood the general aversion towards C++ templates
out there. Maybe I'm biased.

  I find that C++ templates make writing programs simpler, not more
complicated. Many things can be done with simple one-liners which would
otherwise require dozens of lines of complicated code.

  A common complaint about C++ templates is the error messages they
produce. I *am* definitely biased on this aspect because I have actually
learned to read those error messages and I can usually find quite quickly
what the real problem is. (Of course it helps that compilers have got a
lot better at synthesizing the most relevant parts of the error even in
complicated templated code.) I can see, however, how a beginner programmer
can get confused with them.

  However, dissing C++ templates only because they produce complicated
error messages is throwing the baby out with the bath water.

  When Java was designed as a "better C++" (which is the case, no matter
how much Java people deny this irrefutable fact), they naturally left any
kind of support for templates completely out because, you know, templates
are "evil" and produce bad code.

  Many years later they came to regret this, as a lack for any kind of
generic code (besides what OOP offers) was a kind of limiting factor and
produced ugly code. So rather than to succumb to the lure of C++ templates
they introduced a "better template mechanism" (and because "template" is
a curseword they couldn't use that name, and hence they invented a new
name for it, namely "generics", to avoid any negative comparisons). Of
course these "better templates" are much less useful because they cannot
be used to eg. create generic containers which can support basic types
(such as ints).

  I don't know how the "generics" in C# work, so maybe they are honestly
"better" there.

I feel the exact same way about the word "pointer". Oh how much I
loathe talking about Java "references". They should rightfully be
called pointers. I've had several fun conversations about how all Java
functions pass by value, and people will say "nu uh!" because it's "a
reference". The object is not copied, but the reference is copied.
Modifying a parameter reference will not modify the callers reference,
but modifying the pointed-to object in the function will modify the
caller's object. This sounds a whole lot like pointers to me.
 
R

ralph

I feel the exact same way about the word "pointer". Oh how much I
loathe talking about Java "references". They should rightfully be
called pointers. I've had several fun conversations about how all Java
functions pass by value, and people will say "nu uh!" because it's "a
reference". The object is not copied, but the reference is copied.
Modifying a parameter reference will not modify the callers reference,
but modifying the pointed-to object in the function will modify the
caller's object. This sounds a whole lot like pointers to me.

Java doesn't have 'pointers'. Period. Sorry that makes you ill, but it
is a simple fact. Java was deliberately designed to not have them.

The reason you think they exist in Java is because your definition is
too narrow. In general all elements of interest in computing exist
with two attributes - the block of memory that holds a value, and the
address for where that block of memory exists. In creating apps and
even languages the concept of de-referencing a value from its address
is universal. In common parlance that might be called a "pointer". But
that is only part of the story.

The other part is that a language that truly supports pointers must
also support pointer arithmetic. C and C++ support it, Java does not.

-ralph
 
M

Michael Doubez

Java doesn't have 'pointers'. Period.

I have not programmed in java for a long time but I clearly remember
getting a "null pointer exception".
Sorry that makes you ill, but it
is a simple fact. Java was deliberately designed to not have them.

What it doesn't have is pointer data types.
The reason you think they exist in Java is because your definition is
too narrow. In general all elements of interest in computing exist
with two attributes - the block of memory that holds a value, and the
address for where that block of memory exists. In creating apps and
even languages the concept of de-referencing a value from its address
is universal. In common parlance that might be called a "pointer". But
that is only part of the story.

It is not in common parlance, it is the definition of the concept of
'pointer': a physical entity that refer to another.
The other part is that a language that truly supports pointers must
also support pointer arithmetic.

Why ? We could redesign C and C++ without pointer arithmetic (making
arrays first class object by example).
C and C++ support it, Java does not.

Because Java cannot manipulate a type it doesn't have.
 
M

Michael Doubez

Not sure who are the "we", but I know a lot of people won't follow you
on that one.  Do you know any more recent languages that have copied
the C++ idea of splitting the implementation of a class, putting some
of it in a "header" file and the rest in a "source" file?

Do you know of any recent language that doesn't offer dynamic typing
and garbage collection ?

Most of them (all perhaps) are not general programming language but
tend to RAD or scripting. The paradigm are also geeraly not the same
(pure OOP and/or FP).
Do you see
an advantage in separating the class data members in one file and the
implementation in another, except for the inlined implementation which
goes in the header?

Having access to the data layout for composition, allowing cross
dependencies.

IMHO what would be an improvement would rather to be able to add non-
virtual member function outside the class defintion such that you
would not expose internal functions.
This doesn't seem to me to be a particularly
useful way to organize code.  More useful is to separate interface
from implementation, which is not the point of .h and .cpp.

The data layout is part of the interface. This is anathema to pure OOP
but C++ is not an OOP.
 
R

ralph

What it doesn't have is pointer data types.

I would have thought the light would have come on when you typed that.
It is not in common parlance, it is the definition of the concept of
'pointer': a physical entity that refer to another.

As such a limited definition would also include hunting dogs, I
suggest it would be obvious that something else needs to be included.
Why ? We could redesign C and C++ without pointer arithmetic (making
arrays first class object by example).

You certainly could come up with a redesigned programming language
that deliberately doesn't use or allow pointers - and Java is one of
them.
Because Java cannot manipulate a type it doesn't have.

Hello?

-ralph
 
B

Balog Pal

ralph said:
Java doesn't have 'pointers'. Period. Sorry that makes you ill, but it
is a simple fact. Java was deliberately designed to not have them.

You mean the java propaganda was constructed that way. What changes reality
very little: all what java has is equivalent to the pointers in C/C++,
bringing it all the problems, and lacking even the essential tools like
const. :-((

The one thing that is actually eliminated in java is pointer math.

The point java promised was they solved the *practical problems* related to
pointers by eliminating them, that certainly did not happen. Well having
full GC eliminates *technically* dongling pointers, and a couple cases that
are UB in C/C++ lead to defined misbehavior instead. What can be viewed as
better in sense you at least don't launch nukes. Or viewed as the same as in
you get the same crap instead of the quality you desired.
 
A

Alf P. Steinbach /Usenet

* Michael Doubez, on 29.07.2010 09:41:
Do you know of any recent language that doesn't offer dynamic typing
and garbage collection ?

I'm inferring that you think C++ doesn't offer dynamic typing, and that you
think C++ doesn't offer garbage collection.

On the contrary, objects of polymorphic classes are dynamically typed, the
effect of many built-in operations depend on dynamic type, and even C++98
enables garbage collection (some people do use the Boehm garbage collector).

The problems with C++ lacking proper support for creating and using libraries
are well known at least by most experts. Unfortunately Daveed's module proposal,
which could at least have eased some of the problems, didn't make into the first
version of C++0x. It would also be nice with a standard for binary compatibility
of compiled code; alas, AFAIK there's no proposal.


Cheers & hth.,

- Alf
 
A

Alf P. Steinbach /Usenet

* Michael Doubez, on 29.07.2010 09:32:
I have not programmed in java for a long time but I clearly remember
getting a "null pointer exception".

That is correct. In addition, the Java language specification employs the term
"pointer". Ralph is simply uninformed.


Cheers & hth.,

- Alf
 
I

Ian Collins

* Michael Doubez, on 29.07.2010 09:41:
of the things [Java] incorporates from C++ are things we later learned
were errors, to be avoided (i.e. putting the function definitions
inside the
class...).

Not sure who are the "we", but I know a lot of people won't follow you
on that one. Do you know any more recent languages that have copied
the C++ idea of splitting the implementation of a class, putting some
of it in a "header" file and the rest in a "source" file?

Do you know of any recent language that doesn't offer dynamic typing
and garbage collection ?

I'm inferring that you think C++ doesn't offer dynamic typing, and that
you think C++ doesn't offer garbage collection.

On the contrary, objects of polymorphic classes are dynamically typed,
the effect of many built-in operations depend on dynamic type, and even
C++98 enables garbage collection (some people do use the Boehm garbage
collector).

It's also not too hard to hard to implement scripting language style
dynamic typing. I'd just written this

Object object;

object["name"] = "fred";
object["size"] = 10L;
object["hasChildren"] = false;
object["attributes"]["sub"]["name"] = "child";

(which could be PHP or even JavaScript) when I read your post!
 
J

James Kanze

On Jul 27, 9:49 am, James Kanze <[email protected]>
wrote:> Some of the things [Java] incorporates from C++ are
things we later learned
were errors, to be avoided (i.e. putting the function definitions inside the
class...).
Not sure who are the "we",

Software engineers, concerned with reliably developing code on
large projects.
but I know a lot of people won't follow you
on that one. Do you know any more recent languages that have copied
the C++ idea of splitting the implementation of a class, putting some
of it in a "header" file and the rest in a "source" file?

Do you know of any recent language that is designed for large
scale software development, as opposed to animating web pages or
the like?

This is a serious question. I'm not familiar with all recent
languages, but the ones I do know are mostly scripting
languages, or only slightly above, and are not suited for large
scale development. The most recent languages I've seen designed
for large scale development are C++ and Ada 95, and Ada 95 has
an even stricter separation than C++.
Do you see an advantage in separating the class data members
in one file and the implementation in another, except for the
inlined implementation which goes in the header?

Different people work on them. Also, most build systems have
file level granularity; you don't want a change in the
implementation to trigger a recompilation of all of the client
code.
This doesn't seem to me to be a particularly
useful way to organize code. More useful is to separate interface
from implementation, which is not the point of .h and .cpp.

The separation could be better. Much better. (There's
a proposal to add modules to C++.) For example, it would be
better (although perhaps hard to implement) if the private part
of a class wasn't in the header file. The use of textual
inclusion for the separation of interface from implementation is
a hack. It works, sort of, but there are clearly better
solutions (e.g. Modula-2 or Ada). But it's also better than
nothing at all.
 
M

Michael Doubez

* Michael Doubez, on 29.07.2010 09:41:



I'm inferring that you think C++ doesn't offer dynamic typing, and that you
think C++ doesn't offer garbage collection.

The language doesn't offer it (not yet for garbage collection). I
didn't say it couldn't be implemented. AFAIK C++ is still a strong
typed language.
On the contrary, objects of polymorphic classes are dynamically typed, the
effect of many built-in operations depend on dynamic type, and even C++98
enables garbage collection (some people do use the Boehm garbage collector).

The problems with C++ lacking proper support for creating and using libraries
are well known at least by most experts. Unfortunately Daveed's module proposal,
which could at least have eased some of the problems, didn't make into the first
version of C++0x.

Yes, it would have been nice. I also would like to see support for
plugin .
It would also be nice with a standard for binary compatibility
of compiled code; alas, AFAIK there's no proposal.

Well, we already have better memory layout guarantees in c++0x with
standard-layout and layout-compatible.
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,241
Latest member
Lisa1997

Latest Threads

Top