c / c++ : is it end of era ?

N

newsman654

August Karlstrom said:
(e-mail address removed) skrev:

And what features specific to C enabled you to make the program that
much more efficient?


August

1) My friend and I have noticed that working with arrays in C are much faster than anything we compile with any other language. The programming concepts are the same, but the implementation on systems make C run faster on average

(from our experience)

2) The built in library functions of bsearch and qsort work faster than using strings in C++ for doing much the same thing. (Obviously a lot faster then using BASH)


I must say that these are observations that we have seen. I'm not stating they're a universal experience, have
you had the same experience?
 
?

=?ISO-8859-1?Q?Jo=E3o_Jer=F3nimo?=

Keith said:
I hardly think that being able to refer to a type as "foo" rather than
"struct foo" makes compound types much simpler. And typedefs make
defining recursive types (structures with pointers to themselves)
*more* complicated.

I really shouldn't be discussing this kind of things with the little
experience I have...

Sorry!


Today I was for the first time trying to implement a linked list in C
and faced exactly this problem!
And then I started thinking about whether to abstract the structures
with typedefs or not!

JJ
 
?

=?ISO-8859-1?Q?Jo=E3o_Jer=F3nimo?=

Richard said:
Not agreed. The process is no more complicated than without typedef. The
important thing to remember is that the type synonym isn't usable until the
type exists.

But on the other hand, a structure (in the structures namespace) can be
used before completely defined... It doesn't need to be defined, either!


In fact, I tried that now:
typedef struct garbage garb;

gcc doesn't complain if I try to create an object from this code...
If I try to access it before struct garbage exists it complains that it
doesn't know the size (because it needs to allocate space on the stack)...

JJ
 
?

=?ISO-8859-1?Q?Jo=E3o_Jer=F3nimo?=

Richard said:

In my opinion (not very experienced, I admit), the types with imprecise
size aren't bad... Only there could *also* be the precise ones.

Remember that when programming in very low-level, one has sometimes to
adapt data structures to hardware-imposed patterns...


And typedefs allow working around this.
Wrong. Numerous counter-examples exist.

Can you give some of these examples?

JJ
 
R

Randy Howard

Mark McIntyre said:
On Wed, 27 Dec 2006 21:58:36 +0000, in comp.lang.c , Richard
[people] seem to think their programs will run quicker *per se* if they're
multithreaded,

Consider that most modern computer systems have multiple processors -
graphics controllers, dedicated HDD controllers, dedicated network
controllers etc.

Nevertheless, simply making your program multi-threaded will not mean that
it is guaranteed to run faster.

This is generally true. Most people, especially when first exposed to
threads usually manage to make their program run much slower. Of
course, that is no more the fault of threads than programmers having
problems with pointers are C's fault. :)
A user of a single-threaded program can nevertheless take at least *some*
advantage, because he can run that program on one CPU and some other
program on another.

True, but that's only a seat-of-the-pants speedup, whether a single
application runs faster or not, the system as a whole feels faster.
But my main point is that multithreading is not a magic wand you can wave at
any problem. It can certainly be used effectively, but it can also be used
ineffectually, and can even be counter-productive.

That's true of any programming methodology, language or even API.
 
J

jacob navia

Randy Howard a écrit :
They served a purpose at the time they were designed in. If you're too
young to understand why, that's not a reason to pretend they were never
needed.

I am just saying they are not needed any more. Why they are here?
Because a Danish manufacturer had problems with '{' and other
letters of the C alphabet. In the horse trading that goes behind
the publications of international standards they got into the
standard that trigraphs would be there to save them.

Then, time passes, the manufacturer has disappeared since a long
time, and we are stuck with a nonsense construct!!!!
OTOH, if you have a bug due to you as a programmer directly violating
the rules of the language itself, that is not the fault of the
language. That is not knowing what you're doing.

Ahh bugs are BAD BAD.

Great discovery. We are discussing how to avoid them if possible.
One of the ways to avoid them is to make things automatic
whenever possible so that the programmer has less to do, and less
possibilities of errors.

Why C is better than assembly?

Because the level of detail that you have to care about is less.

You just write:

c = a+b;

and you do not have to care about which register you use,
which address are b and c, etc etc.

If we have counted strings the length of the string is no longer
a problem you have to manage but the string library.

If you use the GC you do not care about free(). One problem
LESS to care about
 
J

jacob navia

Randy Howard a écrit :
Strawman. These are not equivalent at all. C gives you something
analogous to a Machete. Apparently, you would prefer a machete that is
never sharpened, only available with a special license, and has a hard
clear plastic cover such that it can't cut anything without melting it
off first with a blowtorch.

To answer you in terms of your own analogy:

C gives you a machette without a HANDLE.
You can't use it without cutting yourself the hand.

I want to add a HANDLE to the machette i.e. a BLUNT
side where I can handle it without getting my blood in my
fingers...

jacob
 
R

Richard Heathfield

João Jerónimo said:
But on the other hand, a structure (in the structures namespace) can be
used before completely defined... It doesn't need to be defined, either!

No, it can't be used before it is defined. But its *name* can be used in a
typedef, yes.
In fact, I tried that now:
typedef struct garbage garb;

Yes, that's legal.
gcc doesn't complain if I try to create an object from this code...

When invoked in conforming mode, it must complain.
If I try to access it before struct garbage exists it complains that it
doesn't know the size (because it needs to allocate space on the stack)...

C doesn't require implementations to allocate space on any kind of "stack",
but the type must be complete before you can define an object of that type.
 
R

Richard Heathfield

João Jerónimo said:
In my opinion (not very experienced, I admit), the types with imprecise
size aren't bad... Only there could *also* be the precise ones.

Fine, but eventually people will say "why does C have this
guaranteed-to-be-exactly-8-bits type? Nobody has used 8-bit bytes for
*decades*!" And we will not even have the excuse of "historical reasons",
since C started off *without* such a type.
Remember that when programming in very low-level, one has sometimes to
adapt data structures to hardware-imposed patterns...

....which is why C leaves the exact size of types up to the implementor.
And typedefs allow working around this.

No, they just let you create a new name for an existing type.
Can you give some of these examples?

I can give you one, because it's one that I have written C code for: the
Analog SHARC DSP (used in set-top boxes, e.g. DVD players, Web TV, that
sort of thing), which has 32-bit bytes. So sizeof(long), sizeof(short),
sizeof(int), and sizeof(char) are all the same: 1.

No doubt others here can tell you about other DSPs with 16- or 32-bit bytes.
They're hardly rare. Also, various dinosaurs have had very weird byte
sizes, e.g. 9, 36, and I believe there was once a 24 (BICBW).

All that C guarantees is that your bytes will be *at least* 8 bits wide, and
*exactly* CHAR_BIT bits wide, where the value of CHAR_BIT is set by the
implementation.
 
R

Richard Heathfield

jacob navia said:

I am just saying [trigraphs] are not needed any more. Why they are here?
Because a Danish manufacturer had problems with '{' and other
letters of the C alphabet. In the horse trading that goes behind
the publications of international standards they got into the
standard that trigraphs would be there to save them.

Then, time passes, the manufacturer has disappeared since a long
time, and we are stuck with a nonsense construct!!!!

So you claim. Nonetheless, trigraphs remain useful even now in, say,
mainframe environments. But if you don't like trigraphs, don't use them.

Great discovery. We are discussing how to avoid them if possible.
One of the ways to avoid [bugs] is to make things automatic
whenever possible so that the programmer has less to do, and less
possibilities of errors.

Quite so, but that automation comes at a cost (typically a performance
drop). So there's a trade-off here - you can automate some parts of your
program generation and reduce programmer time, or you can do it by hand and
reduce runtime. For people who want the former, there are already other
languages that cater for them. For people who want the latter, C caters for
them. If you change C so that it no longer caters for those people, they
will ignore the changes, and go on using the old C, because the old C meets
their needs better than the new C does.
Why C is better than assembly?

Because it's portable. Duh.

<snip>
 
R

Richard Heathfield

jacob navia said:
Randy Howard a écrit :

To answer you in terms of your own analogy:

C gives you a machette without a HANDLE.

Your handle came off? Poor you.
You can't use it without cutting yourself the hand.

Yes, he can. So can I. You're the one that's lost the handle.
I want to add a HANDLE to the machette i.e. a BLUNT
side where I can handle it without getting my blood in my
fingers...

A machete with a blunt long edge is only 50% effective. It's *supposed* to
be sharp on both the long edges. And it's a lousy analogy anyway.
 
M

Mark McIntyre

Mark McIntyre said:
On Wed, 27 Dec 2006 21:58:36 +0000, in comp.lang.c , Richard
[people] seem to think their programs will run quicker *per se* if they're
multithreaded,

Consider that most modern computer systems have multiple processors -
graphics controllers, dedicated HDD controllers, dedicated network
controllers etc.

Nevertheless, simply making your program multi-threaded will not mean that
it is guaranteed to run faster.

Although in many cases it may, simply because the OS can be cleverer
with the runtime process.

Such cases are of course likely to be the trivial ones but not always.
For example a multithreaded DB process may run considerably faster,
provided the threads don't need to access the same tables
simultaneously. This is a real-world example I worked on recently (in
Java I admit) which gained us several _hours_ off an overnight job.
But my main point is that multithreading is not a magic wand

Absolutely.
you can wave at
any problem. It can certainly be used effectively, but it can also be used
ineffectually, and can even be counter-productive.

Double-absolutely!
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

On Thu, 28 Dec 2006 10:18:33 +0100, in comp.lang.c , jacob navia

(of trigraphs, one of JN's favorite bugbears)
I am just saying they are not needed any more.

Okay, so persuade the ISO committee, either directly or via your
national standards agency. Posting over in comp.std.c might prove
productive.
Ahh bugs are BAD BAD.

Great discovery. We are discussing how to avoid them if possible.
One of the ways to avoid them is to make things automatic

Er, no. Remember the stock market crashes of the eighties?

The way to avoid bugs is to write bug-free code. :)
Why C is better than assembly?

Its not. Its merely different. Arguments based on language X being
"better" than language Y are the same as arguments that racial type Q
is better than racial type R, ie bullshit. Different languages serve
different purposes.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

Randy Howard a écrit :

To answer you in terms of your own analogy:

C gives you a machette without a HANDLE.

No, C gives you a machete with a sharp blade. Its got a handle, and
plenty of us manage perfectly well to use it without cutting
ourselves.
You can't use it without cutting yourself the hand.

if someone is incompetent, undertrained or lazy, sure. The same
argument can be applied to cars, toasters and pencil sharpeners by the
way.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
J

jacob navia

Mark McIntyre a écrit :
No, C gives you a machete with a sharp blade. Its got a handle, and
plenty of us manage perfectly well to use it without cutting
ourselves.




if someone is incompetent, undertrained or lazy, sure. The same
argument can be applied to cars, toasters and pencil sharpeners by the
way.

Yes sure. Anything that improves security and allows for
less error prone interfaces is doomed to fail in this atmosphere
of "macho" programming.

It is pointless to discuss this. You never make mistakes
and those that do are "incompetent, undertrained, and lazy".
 
R

Richard Heathfield

jacob navia said:
Mark McIntyre a écrit :
On Thu, 28 Dec 2006 11:08:48 +0100, in comp.lang.c , jacob navia
You can't use [C] without cutting yourself the hand.


if someone is incompetent, undertrained or lazy, sure. The same
argument can be applied to cars, toasters and pencil sharpeners by the
way.

Yes sure. Anything that improves security and allows for
less error prone interfaces is doomed to fail in this atmosphere
of "macho" programming.

Not at all. The point you are missing is that there is more to programming
than "making it as easy as possible". Programming languages have various
characteristics, of which "ease of use" is only one. Others include
performance, portability, flexibility, expressive power, and simplicity (a
non-exhaustive list).

All of these characteristics are desirable, and programming languages
possess them in varying degrees. Sometimes, you can't increase one without
decreasing one or more of the others.

Programming language designers make choices which (whether they realise it
or not) enhance their language's "score" (to put it crudely) on some of
these characteristics but diminish it in others. Would that it were
possible to crank all of them up to the max! But it isn't.

And so we make trade-offs.

You appear to wish to promote one particular characteristic - ease of use -
without regard to the effect that such promotion will have on various other
characteristics. That's your choice, if you're implementing your own
language (or indeed if you are implementing extensions to C), but please
don't make the mistake of thinking that your choices should be binding on
everyone else just because *you* think they're good choices.
It is pointless to discuss this. You never make mistakes
and those that do are "incompetent, undertrained, and lazy".

It may indeed be pointless to discuss this with you, at least, because you
seem to be very ready to jump to conclusions that have little or no basis
in fact. Nobody in this discussion has claimed that they never make
mistakes, or that those who do are incompetent, undertrained, and lazy.
 
J

jacob navia

Richard Heathfield a écrit :
jacob navia said:

Mark McIntyre a écrit :
You can't use [C] without cutting yourself the hand.


if someone is incompetent, undertrained or lazy, sure. The same
argument can be applied to cars, toasters and pencil sharpeners by the
way.

Yes sure. Anything that improves security and allows for
less error prone interfaces is doomed to fail in this atmosphere
of "macho" programming.


Not at all. The point you are missing is that there is more to programming
than "making it as easy as possible". Programming languages have various
characteristics, of which "ease of use" is only one. Others include
performance, portability, flexibility, expressive power, and simplicity (a
non-exhaustive list).

I am speaking not about "making it as easy as possible" (do not know
where you got that) but about "less error prone interfaces"!

This means that mind-dumbing requirements like having to take
care of all the millions of string lengths that you have got
in your program are to be banned. Interfaces should take
care automatically of string lengths. A string is a single
OBJECT composed of data and a length (counted strings),
and maybe other fields.

This is by the way vastly more efficient than counting
the length of the string at each usage, as you may know.

Of course this efficiency is maybe not desired. Is that what
you mean?

:)

But anyway:

I have nothing against making it as easy AS POSSIBLE... Read well the
"AS POSSIBLE" part.

Simplifying, making interfaces less complex makes them less
error prone, and is surely a step in the right direction.

[snip]
You appear to wish to promote one particular characteristic - ease of use -
without regard to the effect that such promotion will have on various other
characteristics.

When implementing the extensions in lcc-win32 nothing is paid by other
software that does not use them. All the extensions do not affect
in any way the rest of the language.

The performance implications of calling

MyAdd(Number *a, Number *b);

or doing
a+b;

are ZERO.

In both cases there is a function call.

That's your choice, if you're implementing your own
language (or indeed if you are implementing extensions to C), but please
don't make the mistake of thinking that your choices should be binding on
everyone else just because *you* think they're good choices.

I haven't made any decision for others since if you do not want those
extensions C strings and old fashioned arrays are still there.

You only pay for what you *actually use*.
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield a écrit :
[...] The point you are missing is that there is more to
programming than "making it as easy as possible". Programming languages
have various characteristics, of which "ease of use" is only one. Others
include performance, portability, flexibility, expressive power, and
simplicity (a non-exhaustive list).

I am speaking not about "making it as easy as possible" (do not know
where you got that) but about "less error prone interfaces"!

I accept the correction (for I am not trying to misrepresent your view,
after all). To aim for less error-prone interfaces is a worthy goal, but
there are lots of worthy goals of which that is only one, and it is
unfortunately true that we cannot always get closer towards one goal
without moving further away from others.
This means that mind-dumbing requirements like having to take
care of all the millions of string lengths that you have got
in your program are to be banned.

That's certainly an opinion, but I value freedom of choice. If you want to
offer people an extension which takes care of these "mind-numbing
requirements", that's entirely up to you, but let's not forget that it
comes at a cost - lock-in to a particular implementation - and not
everybody wants to pay that cost. It may also have other, less obvious
costs, such as performance degradation.
Interfaces should take
care automatically of string lengths. A string is a single
OBJECT composed of data and a length (counted strings),
and maybe other fields.

That's certainly an opinion, and it's not necessarily a bad one. It forms
the basis of typical third-party string libraries (including my own). But
to *force* people to use it is a step backwards. Your trade-off preferences
do not necessarily match everyone else's trade-off preferences.
This is by the way vastly more efficient than counting
the length of the string at each usage, as you may know.

That depends on how often you need the length of the string. It may be that
you don't need it often enough to justify the space or time overhead
involved in storing it.
Of course this efficiency is maybe not desired. Is that what
you mean?

No, I mean that it isn't *necessarily* the most efficient way. Often it will
be, but often isn't always.
But anyway:

I have nothing against making it as easy AS POSSIBLE... Read well the
"AS POSSIBLE" part.

Simplifying, making interfaces less complex makes them less
error prone, and is surely a step in the right direction.

It's a step in *a* right direction, but unfortunately that may involve it
being a step *away* from other right directions.
[snip]
You appear to wish to promote one particular characteristic - ease of use
- without regard to the effect that such promotion will have on various
other characteristics.

When implementing the extensions in lcc-win32 nothing is paid by other
software that does not use them. All the extensions do not affect
in any way the rest of the language.

I have no problem with any implementor choosing to provide extensions to the
language, but it is important for the programmer to remember that using
such extensions renders the program non-portable.
The performance implications of calling

MyAdd(Number *a, Number *b);

or doing
a+b;

are ZERO.

That depends on the implementation (including the machine architecture).
In both cases there is a function call.

No, there is no function call involved in a+b; (unless a and b are macros
that are concealing function calls in their definition).

<snip>
 
R

Richard Bos

Charlton Wilbur said:
You know, when Bjarne Stroustrup decided he didn't like some of the
limitations of C, he designed C++.

When Brad Cox didn't like some of the limitations of C, he designed
Objective-C.

The problem here is not that you see design flaws in C. The problem
is that you believe, in contravention of all evidence, that you can
singlehandedly redesign C *and still call it C*.

C is the language defined by K&R, K&R2, and the C89/90 and C99 standards.

If you want a language remarkably like C, but with length-counted
strings and garbage collection, hey, more power to you! It's likely
to be a fine language, and possibly more useful, more efficient, and
more resilient than C. But unless it conforms to the C standards, it
isn't C.

So why not design the language you really want, and call it something
else?

I suspect something similar is at play here as with the kind of person
who wants to change a game to fit their own playing style - say,
NetHack, of which that has happened repeatedly - but also want to keep
the same name. The real clueful complainants go off and implement their
changes, and then call the result something else (Slash'Em). The jokers
stand on the sideline, and complain bitterly about how unfair this game
is to them.

Richard
 
M

Mark McIntyre

Mark McIntyre a écrit :

Yes sure. Anything that improves security and allows for
less error prone interfaces is doomed to fail in this atmosphere
of "macho" programming.

I didn't say that, but then making false attributions seems to be a
forte of yours.
What I actually said is that your claim that its impossible to use C
without cutting yourself was generally untrue, that of course some
people will find it so depending on their level of skill and care, but
that the same could be said of many household objects.

Heck you can kill yourself with a cigarette lighter, yet they still
sell them without safety shields and with no requirement to have a
license to operate it.
It is pointless to discuss this.

I agree. You're so blinkered with your rage against the regulars here,
and RJH in particular, that you can't be rational about anything, I
fear.
You never make mistakes

Oh don't be silly. Of course I do, and I also accept that these may
lead to bugs. I do try to avoid them, and i do NOT rely on my toolset
to solve all my problems for me because I know that it too contains
bugs and is not omnipotent.
and those that do are "incompetent, undertrained, and lazy".

People who make frequent mistakes of the sort you describe are one of
the above, yes.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

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
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top