Most annoying aspects of C++

H

Howard

"For me, the most annoying aspects of C++ are:

- It's hard to spell.
- It's not Delphi (or Java, or VB).
- There's always that terrible nagging fear that, should I invoke Undefined
Behavior (TM), my hard drive might catch fire, my email system send nasty
messages to my boss, or I could accidently launch a Titan III missile at
China, starting World War 3.

Oh yeah, there's that annoying part about getting paid too much, too...

-Howard
 
M

Markus Schoder

Kirit said:
To me the single biggest problem is also what allowed it to get adopted
so quickly and that is C libraries.

To me, when I'm writing C++ a 'new' is just about acceptable but a
'delete' really isn't. I've had to work with too many APIs and
libraries that are designed for C and they're always a nightmare.

There are some other things I would like to see, a stronger version of
'typedef' which isn't just a synonym. And I'd like some better template
features so that I can do even more with them, but those are tiny
problems compared to interoperating with C libraries/APIs.

While I would agree that using C libraries can be a pain I fail to see
why this is a problem with C++.

Would you rather not be able to use C libraries at all? Or through some
convoluted mess as e.g. Java's JNI?

Or is this really about not enough C++ libraries being available.
 
C

Cy Edmunds

Michael Hopkins said:
Hi all

We all know that C++ is a cleverly conceived multi-paradigm language that
sacrifices very little in efficiency for what it delivers in terms of
type-safety, encapsulation and generic behaviour.

What I want to ask here is - what are the features that people most
dislike
about it i.e. that:

- make it more difficult than necessary to implement designs

- introduce subtle bugs

- force the developer to think in counter-intuitive ways

- make managing a software project more troublesome

- make using or producing libraries inconvenient

There may be others. I am not talking about subjective things like
syntax,
more concerned with tangible design & software engineering issues.

Michael


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Interesting that I didn't see this in the first few posts:

The worst thing about C++ is the syntax! Nobody who has ever programmed in a
Pascal variant language would think C++ has a decent syntax. How many
problems discussed in this newsgroup are directly related to the weird
syntax? "That isn't a variable declaration, that is a prototype of a
function!" doh

Cy
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

Markus said:
While I would agree that using C libraries can be a pain I fail to see
why this is a problem with C++.

Would you rather not be able to use C libraries at all? Or through some
convoluted mess as e.g. Java's JNI?

Or is this really about not enough C++ libraries being available.

As I say, I think the ability to use C libraries gave the language a
lot of possibilities at the start. I just think it's a shame that too
many libraries are still created with a C mentality when I suspect (I
have no evidence for this) that most people these days are using C++
compilers (ather than C only compilers).

I've been a big fan of the STL and the Boost libraries ever since I
started using them nearly ten years ago. These are proper C++
libraries. Even Microsoft's ATL is pretty good given the nightmare that
COM is. But look at what they did with ISAPI. It's a horror of C calls.
And then there's the examples of "proper code" they put up on web sites
which have horrid bugs in them because they've decided that exceptions
don't belong. Eugh!

Anyway, must /rant :)

In short, C++ libraries can be done really well or they can just be "a
better C". But, the fact that you can easily use old C libraries
without too much trouble is great. I'd still prefer better C++ versions
though.
 
B

BigBrian

Victor said:
As opposed to what?

Here is what I think of your current list
[
These are the most annoying aspects of cars, for what it's worth:
- need gas to run
- not enough room to carry all my belongings
- uncomfortable seats
- short warranty leading to expensive repairs later
- going too fast often leads to a speeding ticket
- not enough protection against crashes
- the need to keep many things in mind at once when driving
]

LOL! Exactly!
 
B

BigBrian

Nobody who has ever programmed in a Pascal variant language would think C++ has a decent syntax.

I've programmed in a Pascal variant language, and I think C++' has a
decent syntax. Thus what you've posted has been proven false.

-Brian
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

filox said:
check out the D language...
http://www.digitalmars.com/d/overview.html

pay attention to real typedef section

I'm not sure I'm ready to trade in my C++ for a D compiler - although I
admit to knowing nothing about D.

The committee went to all the trouble of introducing a new keyword,
typename, and then only using it in a few places. Using that for a
nonsynonymous typedef would be great (although I think the names would
be the wrong way around there's no changing that without breaking a lot
of legacy code).
 
P

Phlip

BigBrian said:
I've programmed in a Pascal variant language, and I think C++' has a
decent syntax. Thus what you've posted has been proven false.

I think nobody who has programmed in a language with a decent syntax would
think C++ has a decent syntax.

<a beat>

Unfalsifiability strikes again!
 
J

JustBoo

What I want to ask here is - what are the features that people most dislike
about it i.e. that:

You guys (my fellow posters) do realize he's going to take this data
and use it to prove Java is the better language, right.

To paraphrase an old communist saying: "Don't worry about the west,
they will sell us the rope we will hang them with."

Not to mention you guys are doing his work for him.

"To perceive is to suffer." - Aristotle.
 
V

Victor Bazarov

Kirit said:
[...]

The committee went to all the trouble of introducing a new keyword,
typename, and then only using it in a few places. Using that for a
nonsynonymous typedef would be great (although I think the names would
be the wrong way around there's no changing that without breaking a
lot of legacy code).

Care to start a discussion on it in 'comp.std.c++'?

V
 
M

Michael Hopkins

You guys (my fellow posters) do realize he's going to take this data
and use it to prove Java is the better language, right.

To paraphrase an old communist saying: "Don't worry about the west,
they will sell us the rope we will hang them with."

Not to mention you guys are doing his work for him.

I have no interest in Java - why are you so paranoid?

M


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
 
K

kwikius

Michael said:
- error messages from template (i.e. STL) code.

This is an acknowledged problem.

[...]
- the need to keep so many concepts & types in mind all at once creates
unecessary complexity relative to the problem & reduces productivity

This is a result of a desire to catch errors at compile time rather
than runtime. Its an inevitable result of large complex software
systems with a high performance requirement.

Both these issues have had a bearing on what I think wil be the future
of C++... Check this out:

http://www.generic-programming.org/software/ConceptGCC/

regards
Andy Little
 
M

Michael Hopkins

May we then with all due respect ask what the reason for your question
is?

Exactly what I said in my initial post - to canvas opinion from other users.


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
 
P

Phlip

Michael said:
Exactly what I said in my initial post - to canvas opinion from other
users.

We frequently get questions - often by innocent newbies - cross-posted
between here and Java, asking us to compare them. Yours fit the profile of
a recent one, despite you didn't cross-post.

Comparing C++ to Java is like shooting a fish (Java) in a barrel.
 
W

wkaras

Michael said:
Hi all

We all know that C++ is a cleverly conceived multi-paradigm language that
sacrifices very little in efficiency for what it delivers in terms of
type-safety, encapsulation and generic behaviour.

What I want to ask here is - what are the features that people most dislike
about it i.e. that:

- make it more difficult than necessary to implement designs

- introduce subtle bugs

- force the developer to think in counter-intuitive ways

- make managing a software project more troublesome

- make using or producing libraries inconvenient

There may be others. I am not talking about subjective things like syntax,
more concerned with tangible design & software engineering issues.

Most of the "failings" are in fact tradeoffs -- "fixing" them would
create
new problems that are deemed to be worse than what is being fixed.

Perhaps one true failing is that the complexity of C++ has
overwhelmed the relative informal way that ISO standards are
written. ISO needs to pick some English dictionary as a
base standard, and require that all standards define
(directly or by reference) all words or phrases or notation
used in the standard with a meaning other than the one that
appears in the annointed dictionary. And it's not good enough
to say the specific meaning you're giving to a word like
"alignment" does not conflict with the general meaning,
so you don't need to define precisely your usage of it.
 
S

SuperKoko

Michael said:
Hi all

We all know that C++ is a cleverly conceived multi-paradigm language that
sacrifices very little in efficiency for what it delivers in terms of
type-safety, encapsulation and generic behaviour.

What I want to ask here is - what are the features that people most dislike
about it i.e. that: [...]
- make using or producing libraries inconvenient
Producing library is feasible in C++ but requires discipline and more
coding than it should be necessary.
I think that criticisims are totally pointless without an explanation
on "how to fix it", so, I'll give ways to fix it (My ideas are probably
not flawless, so feedback is welcome).

First, an extensible C++ library has to use, very often, the Pimpl
idiom (i.e. the class contains a pointer to the implementation's data
structure, and then, remains binary compatible even if new private
non-static data members are added or removed).
There is, a space & runtime overhead, that's why, even if the ISO
standard is written such as an implementation is allowed implement such
idiom automatically (i.e. for all classes having non-trivial
constructor or destructor), no sensible implementation would ever do
that. Furthermore such C++ implementation would not be binary
compatible with others.

That's why a "pimpl" specifier would ease library writing:
Here is how it would work:
The pimpl specifier would be used in class definition:

class __pimpl Class1 {
public:
void Func1();
protected:
virtual void Func2();
};

Instead of requiring that all definitions of the same class have the
same definition (including all private members), a __pimpl class could
be defined with missing members (except virtual functions for whom it
would be mandatory to define them all).
Thus, it would allow the library to expose only public and protected
members to users (and no private members).
Furthermore, it would also allow the library to add new members without
changing the ABI.
Constructors of __pimpl classes may launch std::bad_alloc exceptions
(even if the user-defined constructor doesn't seem throw anything).

Perhaps, it would be possible to allow one to define a __pimpl class
without all virtual members, but only a common starting sequence with
the true definition of the class.
In that case, for binary compatibility, it would require that vtables
(if it is the way virtual functions are implemented) for each class are
built from the vtable of the base class, whose size would be stored
somewhere in the vtable, and thus, allowing the copy of "unknown
pointer to functions of the vtable" from the base vtable to the derived
vtable.

So, it is probably complex to implement, but if it is well done, it
would probably really ease the conception of libraries.



Another problem when producing libraries (but that is not a language
issue, it is an implementation issue) is the fact that on the
IA-32/Win32 platform (which is widely used), there is no well-defined
ABI, and thus, linking C++ libraries of one compiler with libraries of
others is a real pain.
It can require a compilation of the source code of the library, which
is a bad thing, because, if the library is large, a user may have twice
the memory overhead of the library if he uses two different programs,
written with two different compilers, but using the same library,
compiled once for each compiler.
That's why, it could be wise for a C++ library writer, to write a C++
library, and then, a C interface to this C++ library, and finally, a
small C++ wrapper around this C interface, designed to be statically
linked to C++ programs which use this library.

On the GNU/Linux platform, there is a well-defined unique ABI, which
evolved around version 3, but is now quite stable.

I hope that in a near future, ABI compatibility will not be a problem
under x86-64 architecture under Windows.

This point is not at all a criticism of the C++ standard comittee. The
ABI is not a matter of the WG21, it is a platform-specific matter which
should be used by a platform-specific authority or consortium (i.e.
intel+compiler vendors for IA-32).
 
S

SuperKoko

Victor said:
Huh? What's the alternative? Virtual d-tors for every class? Or some
other RTTI mechanism to slow everything down?
virtual destructors for every class would be a huge memory overhead for
small objects (1-byte objects for instance).
Currently, C++ allows the object-based paradigm without overhead. And
it is fine for many many things, so I don't want it to be removed.

IMHO, this problem would be dramatically reduced if C++ implementations
had better diagnostic messages.
For instance, compilers should do a warning when:
1) A pointer to an incomplete type (or the void type) is the static
type of the argument of a delete-expression.
Actually, the behavior is undefined if such statement is executed.
2) A pointer to an abstract class having no virtual destructor is the
static type of the argument of a delete-expression.
Since one can't have instances of an abstract class whose dynamic type
is equal to the static type, behavior is always undefined if such
statement is executed.

These two warning messages would resolve a bit number of UB.
It would also be possible to add a warning message when defining a
class having virtual functions but a public non-virtual destructor
(protected non-virtual destructor and public virtual destructor would
be accepted).

Actually, these two or three warning messages would solve all problems
related to virtual destructors except if one derive from a concrete
class, which is often a bad idea.
However, there are classes which are conceptually abstract (such as
std::binary_function). In that case, such classes should have a
protected destructor (unfortunately, it has a public destructor).
And, it would be possible, for a compiler, to emit a warning message
when deriving from a class which is neither abstract nor have a
protected destructor.
I know, that this message should be sometimes ignored... But, at least,
you know where you do dangerous things.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top