Why C++ is vastly superior to C

S

Stefan Ram

gwowen said:
Really? What does .at() do?

It does not apply to arrays.
Are you suggesting C++ doesn't allow OOP?

In 2003, I asked Alan Kay, who coined the term
»object-oriented programming«, what this means.
He kindly answered:

»OOP to me means only messaging, local retention and
protection and hiding of state-process, and extreme
late-binding of all things. It can be done in Smalltalk
and in LISP. There are possibly other systems in which
this is possible, but I'm not aware of them.«

http://www.purl.org/stefan_ram/pub/doc_kay_oop_en
Which optimisation? Early binding is done where possible,
late binding is done where necessary. Where's the
optimisation.

The optimization is that the language had to become larger
and more complex to allow this gain of efficiency.
 
S

Stefan Ram

Michael Doubez said:
Are you talking about "name binding" vs "early bound method call" or
"compile time" vs "run time" ?

»Late« means to me: the decision which function body to call
is made depending on the run-time type of the participating
objects. (I guess, I would also have to require multimethods,
then. But multimethod lookup also has its drawbacks [complexity].)

Run-time polymorphism is possible in C++ (at least for one
object in an expression), but the C++ standard library is
based on templates. (I have not yet studied whether this
makes OOP harder in C++.)

In a real OOP language, like Smalltalk, blocks of statements
are also objects. This means, for example, one can define an
if method (in Smalltalk) as a method taking a boolean and a
block (of statements), then passing the block to the
boolean, where boolean objects of the class True execute
their blocks, while those of the class False do not. This
requires late binding, because the class of (x<y) is only
known as late as at run time (it might be the subclass True
of the class Boolean or the subclass False).

In C++, »if« is not a method at all, but a keyword
hard-coded in the programming language. (Possibly, in
Smalltalk, if also is hard-coded. But it could be defined as
described in the preceding paragraph.)

But maybe C++0x is getting closer to Smalltalk and LISP with
its new closure objects!
I wonder how many times C++ is chosen for its performances;
do you have numbers ?

No, but since C++ is very complex, there must be some reason
to use in instead of languages more simple and secure, so
performance is a good candidate.
 
N

Nobody

Design decision in C++ are usually decided in favor of
run-time efficiency.
Since this optimization is /always/ done, by pure /choice of
the language/, it can be called premature.

Only if you're really desperate to make a "premature optimisation"
argument.

The alternative, i.e. to use a higher-level but less efficient language,
results in the optimisation never being performed at all, even in the
finished product.

Some optimisations must inherently be performed at the outset, if they are
to be performed at all. If you adopt an approach which is structurally
inefficient, then the only way to get rid of the inefficiency is to start
over with a more efficient structure. That doesn't make such optimisations
"premature".

Premature optimisation means performing "optimisations" before you have
sufficient knowledge to determine what is actually optimal.

This is primarily a problem with "code first, design later" development,
where you don't really know what you should be doing until you have a
working prototype (either because the problem isn't amenable to structured
development, or the programmer isn't).

OTOH, if you have a good understanding of the problem, it's entirely
possible (and reasonable) to make optimisation decisions long before you
start writing code.
 
J

Joshua Maurice

  In 2003, I asked Alan Kay, who coined the term
  »object-oriented programming«, what this means.
  He kindly answered:

      »OOP to me means only messaging, local retention and
      protection and hiding of state-process, and extreme
      late-binding of all things. It can be done in Smalltalk
      and in LISP. There are possibly other systems in which
      this is possible, but I'm not aware of them.«

http://www.purl.org/stefan_ram/pub/doc_kay_oop_en

I've been here before.

http://c2.com/cgi/wiki?DefinitionsForOo
http://c2.com/cgi/wiki?IsCeePlusPlusObjectOriented

This is nothing new, and I otherwise have nothing new to add to this
silly discussion.
 
S

Stefan Ram

Joshua Maurice said:
Do you have a source or citation of some kind for this quote, where it
was first said? I'm just kind of curious curious for no particular
reason at all.

My source is

Message-ID: <[email protected]>
From: (e-mail address removed) (Shinji Ikari)
Newsgroups: comp.theory.cell-automata,comp.lang.java.advocacy,comp.lang.scheme,comp.lang.misc
Subject: Re: Cellular automata benchmarks: Java vs C++ vs Java vs C++
Date: 22 Jul 2003 22:33:27 -0700
 
N

Nobody

For example, Java has decided to check array indices
at runtime, C++ not to.

Really? What does .at() do?

Checks vector indices. Vectors aren't arrays (and the default
indexing operation, operator[], doesn't do bounds-checking).

Err, exactly what makes it *default*?

It's the "natural" indexing operation. The one that has dedicated syntax
rather than being a normal method. The one you'll end up using if you
convert C code to C++ with minimal re-writing.
 
Ö

Öö Tiib

For example, Java has decided to check array indices
at runtime, C++ not to.
Really? What does .at() do?
Checks vector indices. Vectors aren't arrays (and the default
indexing operation, operator[], doesn't do bounds-checking).
Err, exactly what makes it *default*?

It's the "natural" indexing operation. The one that has dedicated syntax
rather than being a normal method. The one you'll end up using if you
convert C code to C++ with minimal re-writing.

Good C code has the bounds under explicit control anyway. Crap C is
not worth converting. So what is your issue?
 
R

Rui Maciel

Stefan said:
Design decision in C++ are usually decided in favor of
run-time efficiency.

For example, Java has decided to check array indices
at runtime, C++ not to.

»Learning C++ is equivalent to studying to be a NASA
test pilot. Its incredibly fast and effective, but takes
years to master the arcania and things tend to blowup in
your face if you're not very careful.«

What does this quote have to do with your statement on premature
optimization?

»I would rather compare it to learning how to drive a
racecar: yes, it can be fast. Most people tend to drive
it off track right away. Some people die in it.«

Again, what does this quote have to do with your statement on premature
optimization?

OOP: bind as /late/ as possible
C++: bind as /early/ as possible (generic programming)

Again, what does this quote have to do with your statement on premature
optimization?

Since this optimization is /always/ done, by pure /choice of
the language/, it can be called premature.

You clearly don't understand what premature optimization means.


Rui Maciel
 
R

Rui Maciel

Nobody said:
Premature optimisation means performing "optimisations" before you have
sufficient knowledge to determine what is actually optimal.

It's a bit more than that, as it also implies wasting human resources
(man*hour) in a futile task which provides questionable performance
improvements and ends up making it harder to develop and maintain the
code. So, considering this, compiling a program which is still in alpha
stage with the -O3 flag obviously isn't premature optimization. Nor using
CPP macros. Nor using templates. Nor using inline functions.


Rui Maciel
 
R

Rui Maciel

Stefan said:
My source is

Message-ID: <[email protected]>
From: (e-mail address removed) (Shinji Ikari)
Newsgroups:
comp.theory.cell- automata,comp.lang.java.advocacy,comp.lang.scheme,comp.lang.misc
Subject: Re: Cellular automata benchmarks: Java vs C++ vs Java vs C++
Date: 22 Jul 2003 22:33:27 -0700

When people quote someone, they do it with the hope that the aura of
authority that emits from that specific person is enough to force others
to simply swallow a statement without exercizing the faintest attempt at
critical thinking. You don't benefit from that by quoting some random
usenet post made by some anonymous person who posted a random message 8
years ago under a pseudonim inspired by an anime series.


Rui Maciel
 
R

Rui Maciel

Nobody said:
It's the "natural" indexing operation. The one that has dedicated syntax
rather than being a normal method. The one you'll end up using if you
convert C code to C++ with minimal re-writing.

As operator overloading amounts to nothing more than syntax sugar, a
method is as "natural" as a call to any operator defined for that class,
including the array subscript operator.


Rui Maciel
 
G

gwowen

It's the "natural" indexing operation. The one that has dedicated syntax
rather than being a normal method.

So, what you're saying is "C++ doesn't do bounds checking if you're
too lazy to you ask it to."
The one you'll end up using if you convert C code to C++ with minimal re-writing.

So, you're bad/lazy at porting, and seemingly don't know how to do a
regex-replace. How is this a problem with C++? You get the choice of
checked and unchecked, and you're complaining that the checked one
requires too much typing? (Also your implementation probably provides
a switch to access a bounds-checked operator[].)
 
H

hanukas

No, it doesn't LOOK like an array index.  Nevertheless, it *is* an
array index. And offering a checked and unchecked indexing

I'm fairly confident that it is a method of a class. I wouldn't be
surprised to find out that C++ was Turing Complete.
 
H

hanukas

I'm fairly confident that it is a method of a class. I wouldn't be
surprised to find out that C++ was Turing Complete.

I'll skip one iteration to save everyone's time. at() is a method of
class std::vector, for example. It's a method of a class. That's
great, but I was (indirectly) commenting on this:

"For example, Java has decided to check array indices at runtime, C++
not to. "

So, array indices == std::vector? I stand corrected, thank you
internet.
 
N

Nobody

As operator overloading amounts to nothing more than syntax sugar,

Use of the term "nothing more" minimises the significance of syntax.
There's a reason why C++ has "operator" methods when they don't provide
any additional functionality.

The fact that it provides a bounds-checked method does nothing to
eliminate the argument that they made the wrong choice for operator[].
FWIW, I'm not taking any particular side in that argument, I'm just saying
that it exists, and the existence of .at() doesn't change that.

Also, arrays don't have .at(), so if you want to write code which works
with either vectors or arrays, subscript notation is the only option.
 
B

Balog Pal

Nobody said:
Also, arrays don't have .at(), so if you want to write code which works
with either vectors or arrays, subscript notation is the only option.

Less ignorant people know that "do not use C-style arrays" is on the top of
C++ guidelines anywhere.
 
H

hanukas

Checks vector indices. Vectors aren't arrays (and the default
indexing operation, operator[], doesn't do bounds-checking).

Err, exactly what makes it *default*?

The context? I think the topic was arrays, until derailed to
std::vector.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top