PDA

View Full Version : Why C Matters



Pages : [1] 2 3

DavidP
01-08-2008, 12:48 PM
I just read an amazing article about why C and C++ matter in today's software development world.

Here is the link:

http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html

I found it on Slashdot. I encourage all the read it (and comment if you want).

Go C/C++!

laserlight
01-08-2008, 01:09 PM
hmm... cannot seem to access the page. Perhaps it is being slashdotted.

Elysia
01-08-2008, 01:31 PM
It works for me.
I still don't see how C actually matters since C++ can produce the exactly same code with better compilers.

CornedBee
01-08-2008, 02:04 PM
It's good for teaching if you're not given the chance to avoid some work. In C, you have to deal with low-level string representation. Once you're at a level where you're able to learn this stuff, that's a good thing.

My own university's software engineering bachelor requires at least basic knowledge of Java (introduction to programming, object-oriented programming, software engineering), C (system programming), Haskell (functional programming), Prolog (logic-oriented programming), Assembly (prerequisite for compiler writing) and some web development language (web engineering course, typically PHP), and offers additional courses that touch on PostScript, Forth (stack-based languages), C++, and more.

Prelude
01-08-2008, 02:05 PM
>I found it on Slashdot.
So good things can be found on /.? That's more interesting than the article. ;)

>I still don't see how C actually matters since C++ can
>produce the exactly same code with better compilers.
C is kewler because. Anyone who's anyone knows why C matters. If you don't know why C matters, you're not a real programmer. <insert more fallacious logic for why C is better here>

But seriously, C matters because it's a royal .......... to translate oodles of legacy C to C++, and only an idiot or a gullible newbie believes that C++ compilers can compile real world C without significant changes.

Elysia
01-08-2008, 02:07 PM
It's good for teaching if you're not given the chance to avoid some work. In C, you have to deal with low-level string representation. Once you're at a level where you're able to learn this stuff, that's a good thing.

But the thing is, that it can be done in C++ too. There could be C++ (systems programming) instead of C, that teaches low-level, typical, "C" code in C++ instead of C.
That is what I don't get.

CornedBee
01-08-2008, 02:11 PM
What's the point? If you're writing C code, use C. What's the advantage of using C++ to write C code?

Prelude
01-08-2008, 02:12 PM
>What's the advantage of using C++ to write C code?
Why go out of your way to write C when C++ is right there? ;)

Daved
01-08-2008, 02:14 PM
As someone who generally recommends higher-level languages be taught first, I don't disagree with the gist of the article. Teaching Java is fine, but you can't teach it solely, nor can you do it at the expense of eventually teaching all the lower-level skills.

Elysia
01-08-2008, 02:15 PM
The obvious advantage is that C++ compilers are much more standard compliant and better at type safety too, and allows for additional things like constant numbers instead of defines.
Obviously, C is very old and C++ can do all C can and more, and with the very same speed and efficiency.
So I don't see why we use C to write C code and not try to use C++ to write it instead so we can get rid of C.

This I what I don't get.

CornedBee
01-08-2008, 02:18 PM
The obvious advantage is that C++ compilers are much more standard compliant
Bzuh?
First, unlike C++, C actually has compilers that are 100% conforming to the language standard.
Second, C++ compiler are certainly not compliant with the C standard.


and better at type safety too, and allows for additional things like constant numbers instead of defines.
Minor issues.


Obviously, C is very old
Latest full C revision: 1999. Latest full C++ revision: 1998. So C is more current than C++ ;)


and C++ can do all C can and more,
But we don't want more.


So I don't see why we use C to write C code and not try to use C++ to write it instead so we can get rid of C.
Get rid of C? You want to get rid of C, then use C++ to program C code? Again: why not just use C?

Prelude
01-08-2008, 02:19 PM
>The obvious advantage is that C++ compilers are much more standard compliant
I only know of one C++ compiler that supports standard C++ completely. On the other hand, most of the C compilers are C89 compliant. C99 is damn near worthless, so I wouldn't call lack of conformance to it a good argument against C.

>and allows for additional things like constant numbers instead of defines.
That's a personal preference, IMO.

>So I don't see why we use C to write C code and not try
>to use C++ to write it instead so we can get rid of C.
Probably because too many people are aware that it's impossible to "get rid" of a language that was as popular as C.

Elysia
01-08-2008, 02:31 PM
Bzuh?
First, unlike C++, C actually has compilers that are 100% conforming to the language standard.
Second, C++ compiler are certainly not compliant with the C standard.
No, I believe someone corrected me before. Many C compilers allow stupid things that aren't actually allowed by the C standard. You can just as well pass a double to a function that wants void*. How's that for type safety? So far as I know, this is not allowed by the standard, but the code compiles nevertheless, but in C++ it would never work.
This is what I was referring to.


Minor issues.
True, true. But then again, it will keep newbies for making silly mistakes and ignoring warnings.


Latest full C revision: 1999. Latest full C++ revision: 1998. So C is more current than C++ ;)
C was invented before C++, though... I don't know if there's going to be anymore updates to C? Anyone know about that?


But we don't want more.
Get rid of C? You want to get rid of C, then use C++ to program C code? Again: why not just use C?
One language ;) Why have two that can do the same thing?
And besides, what if you want to do C+? I think in some situation you can get away with it. It's better to do C+ instead of pure C what you can't do full C++.
Anyway, that's just my opinion.


>The obvious advantage is that C++ compilers are much more standard compliant
I only know of one C++ compiler that supports standard C++ completely. On the other hand, most of the C compilers are C89 compliant. C99 is damn near worthless, so I wouldn't call lack of conformance to it a good argument against C.
Sure, but as I mentioned to CornedBee, at least it seems to follow the standard better on things such as type safety.


>and allows for additional things like constant numbers instead of defines.
That's a personal preference, IMO.
It is, it is. But then again, why use an old tool when you got a better, newer, shinier one? Shrug.


>So I don't see why we use C to write C code and not try
>to use C++ to write it instead so we can get rid of C.
Probably because too many people are aware that it's impossible to "get rid" of a language that was as popular as C.
I know... but if we keep teaching C, it will never go away. Best to start somewhere, isn't it?

CornedBee
01-08-2008, 02:41 PM
C1x is in the planning. The C and C++ working groups are always collaborating. When C++ gets multi-threading support, C will follow soon after. (Indeed, C interoperability concerns were the main reason thread cancellation in C++ got axed.)

whiteflags
01-08-2008, 02:43 PM
>I know... but if we keep teaching C, it will never go away. Best to start somewhere, isn't it?
I was looking over my college's IT program (again). You'll be happy to know there is no C course.

>It is, it is. But then again, why use an old tool when you got a better, newer, shinier one?
You are permitted constant numbers in C. That's nothing C++ did new.

>One language Why have two that can do the same thing?
C++ compiles C. Read what Bjarne said about developing his language to be sure, but I'm sure that this is just a happy coincidence of all the C stuff you might want to use in C++, like pointers, constants, structs or streams. But they do not do the same thing. If C is the foundation for a newer language, then C++ isn't just carrying C around for no reason.

Jaqui
01-08-2008, 02:46 PM
1) C done in C++ is not as fast as C done in C, the C++ compiler actually has to translate C into C++, or else it just calls the C compiler to handle the C code.

2) Systems level programming is done in any compiled language, Solaris is Java, windows is C++, every other os in C.
[ yes, java has the jit, but it can be compiled into ececutables and stored that way. ]

3) most rapid execution languages, like python, perl, php .. are actually WRITTEN in C.
[ download the sources and check for yourself, I know PHP* and Python are both written in C. }


* PHP's Zend engine being an exception, it is written in Java.

CornedBee
01-08-2008, 02:50 PM
Solaris's system level is C and C++, just like every other OS's.

Zend is also written in C.

Where do you get all these ideas?

Prelude
01-08-2008, 03:17 PM
>Sure, but as I mentioned to CornedBee, at least it seems to
>follow the standard better on things such as type safety.
C doesn't claim to be type safe. If you do something that the standard says is undefined, you should expect the result to be unpredictable. The compilers aren't to blame for bad code.

>But then again, why use an old tool when you got a better, newer, shinier one? Shrug.
http://www.codinghorror.com/blog/archives/000916.html

>I know... but if we keep teaching C, it will never go away. Best to start somewhere, isn't it?
Be my guest. If nobody knows C then I can make a killing maintaining old C code. :)

laserlight
01-08-2008, 03:21 PM
Be my guest. If nobody knows C then I can make a killing maintaining old C code.
Like the COBOL programmers just before Y2K?

Elysia
01-08-2008, 03:53 PM
C1x is in the planning. The C and C++ working groups are always collaborating. When C++ gets multi-threading support, C will follow soon after. (Indeed, C interoperability concerns were the main reason thread cancellation in C++ got axed.)
OH right, so now C is holding back C++. Sigh. Another reason to get rid of it IMO.


1) C done in C++ is not as fast as C done in C, the C++ compiler actually has to translate C into C++, or else it just calls the C compiler to handle the C code.
C++ code as C code is just as fast as pure C code. Several have stated that C++ can be as fast as C. You don't need to compile it as C. Compile it as C++ - it should be equally fast.


2) Systems level programming is done in any compiled language, Solaris is Java, windows is C++, every other os in C.
[ yes, java has the jit, but it can be compiled into ececutables and stored that way. ]
Yes :)
So why are they coded in C instead of C++, then? That's what I'm wondering.


C doesn't claim to be type safe. If you do something that the standard says is undefined, you should expect the result to be unpredictable. The compilers aren't to blame for bad code.
Weren't the standard supposed to say it wasn't allowed? I believe someone mentioned the compilers were to blame and no the standard.


>I know... but if we keep teaching C, it will never go away. Best to start somewhere, isn't it?
Be my guest. If nobody knows C then I can make a killing maintaining old C code. :)
There's no need to phase it out fast, just slowly :)
Eventually, some languages will go down into the history and fade away, like like QBasic and things. Just let the nature run its course, so to speak. If everyone stops teaching C, it will eventually fade away with time...

Salem
01-08-2008, 05:13 PM
What there seems to be a lack of is people being taught how to program. Sure there's lots of focus on teaching programming languages, but that's only half the story. Producing a working program is a lot more effort than simply pressing the keys in the right order.

But it seems that's all a lot of courses seem to require, because it's very easy to verify. Either you get the expected output or you don't. Assessing code quality, thoroughness of design etc etc is nowhere. If it were, perhaps we'd see less code posted here that looks like it was a dogs chew toy.

A fair proportion of very large programs require more than one language to begin with. Again, this comes from an engineering perspective and treating languages as nothing more than tools which are specialised in solving particular kinds of problems.

It's the car analogy I keep posting. There's way too many people rushing about who don't have a clue how to drive.

laserlight
01-08-2008, 05:33 PM
The way I see it is that people do need to learn how to use the tools, even as they learn how to say, build a wall (http://www.flounder.com/bricks.htm).

Sang-drax
01-08-2008, 09:47 PM
I think electrical engineers should primarily learn C. Computer scientists could have either language (C or Java) as their first. All other engineers should have Java as their first language.

"Then I started teaching C++ to the electrical engineers and when the EE students started to out-program the CS students, the CS department switched to C++."

Maybe this is because BS is an excellent teacher and not so much due to the superiority of C++ as a first language?

Rashakil Fol
01-08-2008, 11:34 PM
Go C/C++!

Edit: never mind.

matsp
01-09-2008, 04:04 AM
1) C done in C++ is not as fast as C done in C, the C++ compiler actually has to translate C into C++, or else it just calls the C compiler to handle the C code.

Can't avoid commenting on this one: It's complete and utter garbage. The same C code compiled by comparable C or C++ compiler will generate identical code [or sufficiently identical to not make difference performance-wise]. All C++ compilers [that I know of] have the capability of compiling plain C code as well as C++ code.


2) Systems level programming is done in any compiled language, Solaris is Java, windows is C++, every other os in C.
[ yes, java has the jit, but it can be compiled into ececutables and stored that way. ]

There is very little C++ in the Windows Kernel code, maybe 5% or less - there may be lots of it in utilities and libraries [certainly in the DirectX libraries]. Solaris Kernel code is not written in Java, that's for sure, it's C and possibly C++. Again, utilities and libraries may be a different story.

--
Mats

CornedBee
01-09-2008, 05:54 AM
The same C code compiled by comparable C or C++ compiler will generate identical code
Not quite true, depending on the compiler's exception handling strategy.

matsp
01-09-2008, 05:56 AM
Not quite true, depending on the compiler's exception handling strategy.

Can you please educate me on how that would make a (measurable) difference in a currently implemented [mainstream] compiler?

--
Mats

CornedBee
01-09-2008, 05:58 AM
It probably wouldn't. But the code would be larger.

matsp
01-09-2008, 06:03 AM
It probably wouldn't. But the code would be larger.

Yes, I agree with that, because the unwind information that needs to be stored on the stack - and that would potentially cause extra code to be executed as well - but only in lots of calls to small functions [that is, the overhead of unwind information affects the total run-time of the function]. Of course, for most such small function cases, the compiler would be able to infer that no exceptions would be thrown by the code in the function, and thus there is no reason to have any unwind info.

--
Mats

abachler
01-09-2008, 09:37 AM
Maybe this is because BS is an excellent teacher and not so much due to the superiority of C++ as a first language?

Having learned BASIC, then assembly, then C then C++ then java, I will say that I wish I had learned C++ first, even before 'C'. This is because code that is C++ compliant will also compile under C, excluding classes. Code that compiles under C may not necessarily compile as C++. Java is completely irrelevant to an EE except in so far as poor business decisions make it relevant, but its an entirely unnatural thing.

vart
01-09-2008, 10:52 AM
This is because code that is C++ compliant will also compile under C, excluding classes.
Excluding a lot of other things... These are 2 different languages

Where do you have new/delete in C?
Or function overloading?

DavidP
01-09-2008, 11:33 AM
This is because code that is C++ compliant will also compile under C, excluding classes. Code that compiles under C may not necessarily compile as C++.


Actually it is quite the other way around. For the most part, any C program will compile successfully with a C++ compiler...but there is no possible way for a C compiler to compile a pure C++ program.

This is growing less true, however. Although I have not tested any specific cases myself, I have heard lately that C++ has begun to diverge enough from C that not all C code is compilable in C++ compilers anymore.

Neo1
01-09-2008, 11:50 AM
This is because code that is C++ compliant will also compile under C, excluding classes.

Here's a list of why that is wrong...

# anonymous unions
# classes
# constructors and destructors
# exceptions and try/catch blocks
# external function linkages (e.g., extern "C")
# function overloading
# member functions
# namespaces
# new and delete operators and functions
# operator overloading
# reference types
# standard template library (STL)
# template classes
# template functions
# // comments

Salem
01-09-2008, 12:09 PM
> I have heard lately that C++ has begun to diverge enough from C that not all C code
> is compilable in C++ compilers anymore.
It was never true from the beginning, never mind now.

All those extra keywords added by C++, like class. They're perfectly valid C identifiers. So right from the beginning
int class;
would cause a C++ compiler to barf.

http://david.tribble.com/text/cdiffs.htm

Kennedy
01-09-2008, 03:12 PM
What there seems to be a lack of is people being taught how to program. Sure there's lots of focus on teaching programming languages, but that's only half the story. Producing a working program is a lot more effort than simply pressing the keys in the right order.

But it seems that's all a lot of courses seem to require, because it's very easy to verify. Either you get the expected output or you don't. Assessing code quality, thoroughness of design etc etc is nowhere. If it were, perhaps we'd see less code posted here that looks like it was a dogs chew toy.

A fair proportion of very large programs require more than one language to begin with. Again, this comes from an engineering perspective and treating languages as nothing more than tools which are specialised in solving particular kinds of problems.

It's the car analogy I keep posting. There's way too many people rushing about who don't have a clue how to drive.

15 years ago, when I was in college, there were people already in there that were saying
Computer Science wouldn't be so bad if there wasn't all that programming!(Please note that I know the difference between an idiot CS Student and a good CS Student).

I want to second Salem on this one. A "real" programmer would be one that 1) knows HOW to program, 2) knows HOW to learn a language, 3) knows HOW things work BEFORE he/she begins to work on the project, and 4) is not afraid to attempt to solve a problem in some other language -- even if he/she does not know that language.

It would seem that we are getting too far removed from the KISS model of programming. When one uses something like VB/Java to do hardware programming, one can expect problems to occur later.

My 0.02 USD.

abachler
01-09-2008, 04:19 PM
Excluding a lot of other things... These are 2 different languages

Where do you have new/delete in C?
Or function overloading?

since new/delete is primarily for creating/destroying classes new instantiations of classes, this woudl fall under classes. otherwise you can just use malloc/free which have the exact same effect when applied to things other than classes. Cry about malloc/free not being part of C, but they are in EVERY standard library out there. I know of no working implementation that does not include them, although im sure someone will find some little known example to try to 'prove' me wrong.

As for function overloading, its called function renaming, The C++ preprocessor just handles it automatically for you. So again, other than classes, there arent any intrinsic differences between C and C++. You can take a C compiler and easily add those features that woudl mke it a C++ compiler. Not so with a different language like Java or VB or COBOL, Fortran, Ada, ML etc. Try upgrading Clipper to C++ and you will understand what a different language means. Going from C to C++ is trivial.

whiteflags
01-09-2008, 05:45 PM
>Cry about malloc/free not being part of C, but they are in EVERY standard library out there.

Well, the only problem with that statement is that malloc and free are Standard functions. Sure, people will reimplement the Standard from time to time (dmalloc (http://www.dmalloc.com)) to add something, but that statement is just wrong. For all intents and purposes it is a part of C.

mike_g
01-09-2008, 05:49 PM
You can take a C compiler and easily add those features that woudl mke it a C++ compiler.
Wow, can you? I cant :( C++ has quite a lot of useful features. Templates rule!

dwks
01-09-2008, 06:30 PM
As for function overloading, its called function renaming, The C++ preprocessor just handles it automatically for you.
You're right, function overloading is usually implemented by "mangling" the names of the functions to include some information about the function's arguments. However, it's the compiler that does this, not the preprocessor. The preprocessor does very few things, among them:

File inclusion with #include.
Conditional compilation with #if etc.
Macros with #define.
Comments (the preprocessor strips them).
String literal concatenation.


The first C++ "compiler" was actually a source-to-source translator: it simply converted C++ into C. So every feature of C++ can be represented in C. In fact, every feature of C++ can be represented in assembly -- that's how compilers can exist.

But that doesn't mean we should be programming directly in assembly just because C++ can be converted into assembly. It's convenience, and abstraction, that makes us use higher-level languages.

vart
01-09-2008, 10:57 PM
since new/delete is primarily for creating/destroying classes
it is for dynamic memory allocation, what it has to do with classes? If you do not use classes?



int* arr = new int[15];

abachler
01-09-2008, 11:00 PM
I dont disagree with you dwks, but I dont see C++ as a seperate language from C. It has more features for sure, just as modern english is more descriptive than english of say 100 years ago. Both can be translated into grunts whistles and other basic phoenetic primitives. That doesnt make 19th century english and modern english 2 seperate languages, nor does it mean we should all go around speaking in phoenetics either. I can obviously translate any modern phrases into terms in use in the 19th century, granted it woudl take longer to express teh same concepts, just as it woudl take more lines of code to express the same behavior in C as in C++. Again, this does not make them seperate languages, merely differnt dialects at most.



it is for dynamic memory allocation, what it has to do with classes? If you do not use classes?


new/delete is the primary way to instantiate a class. it is a bit difficult to instantiate a class using malloc. I really fail to see what you are asking?



int* arr = new int[15];


can be just as easily expressed in C as



int* arr = malloc(15 * sizeof(int));

vart
01-09-2008, 11:10 PM
can be just as easily expressed in C as

That's the idea - use C when you need C, do not use C++ because you anyway will need to rewrite the code to compile it as C

CornedBee
01-10-2008, 01:10 AM
C and C++ are considerably less similar than C# and Java. Does that make Java and C# "merely dialects" of the same language?

laserlight
01-10-2008, 01:17 AM
heheh, geneticists argue that tracing common ancestry based on morphological features is less reliable than using DNA. Borrowing their point of view, can C++, C# and Java trace their ancestry from C (and so are part of one C family), or is only C++ a direct descendant from C and thus a dialect of C, whereas C# and Java are entirely different languages?

CornedBee
01-10-2008, 01:23 AM
Well, both C# and Java can directly trace their ancestry to C++. In the family of programming languages, C# and Java are siblings, children of C++ and Smalltalk, really. C++ is a child of mostly C and Simula.
The main difference is that C++ was developed with C source and binary compatibility in mind, whereas C# and Java had no such ambitions, neither with C++ nor with each other.

vart
01-10-2008, 01:30 AM
C and C++ are considerably less similar than C# and Java. Does that make Java and C# "merely dialects" of the same language?

YES! They're all just a dialects. So let's learn only the proper language - C!!!!

And leave the dialects to the morons who do not know how to speak the literary language!!!

(Followed by the Evil laughter )

Elysia
01-10-2008, 01:53 AM
Why use an old, deprecated dialect when you can use a newer one that not only sounds better, it can say everything the old one can, thus making there only one dialect to remember.

robwhit
01-10-2008, 02:05 AM
The flip side of that is that if you learn C, then you only have to learn part of a language to know a language. Thus making it easier to learn and remember.

Elysia
01-10-2008, 02:08 AM
But that won't do if you need to learn how to program typical applications, in which that knowledge just won't do. Not to mention you'd usually use C++ or a more modern language to code that.

robwhit
01-10-2008, 02:10 AM
Why not? Why?

edit: maybe that's a bad question... :p