PDA

View Full Version : C better than C++? (POLL)



Lynux-Penguin
04-30-2002, 12:19 AM
Is C better than C++
Pro's of C:
Faster, more compatible with platforms, faster, not owned by Microsoft, was the US national Standard Programming Language, and free compilers (gcc).
Con: Not owned by Microsoft, not very object oriented, memory efficiency becomes a problem, cross-platform development through compilation is EXTREMELY difficult.

foniks munkee
04-30-2002, 12:47 AM
That is kinda like comparing a screwdriver with a spanner - different tools for different jobs.

And I am confused as to why not being owned by Microsoft is a both a pro and a con - and also why this thread is not in the general area where it is probably more appropriate seeing as though there is very little code being discussed here... :)

Oh and so what if it is/was the US national standard - how is that a pro for the billions of people who don't live in the US?

Fordy
04-30-2002, 02:37 AM
Oh Joy....another opportunity for this discussion :)


Originally posted by Lynux-Penguin

Pro's of C:
Faster,

Not really......some instances when using virtual functions.....but it depends largely on the compiler. There arent many situations where the speed is that critical......if you are programming games....why would you be really interested in virtual functions?
Those features that might slow things down are to make the structure of programming easier and they enforce the OOP principals of C++.

It all translates to the same op code........just depends how the job is done



more compatible with platforms,

No...that again would depend on the compiler.....and there arent many platforms that I know of without a C++ compiler



faster,

Is there an echo in here?



not owned by Microsoft,

Neither is c++!!!


was the US national Standard Programming Language,

And?????


and free compilers (gcc).

Ugh......http://www.compilers.net/

Shiro
04-30-2002, 04:05 AM
>Is C better than C++

There's no such as a language being better then the other.

>Pro's of C: <...> not owned by Microsoft
>Con: <...> Not owned by Microsoft

:-)

Some notes:
The GCC package also contains a C++ compiler.
C++ is also standardised.

It is not an disadvantage of C that it is not very object oriented. If you design your programs non-object oriented, then you don't need an object oriented language.

C and C++ are both portable if you write standard C and standard C++ code.


You forgot the option: there's no better.

hairyian
04-30-2002, 08:34 AM
Okay... let's analyse this question and make sure we know what we're all talking about before we begin. The question, as asked, is:

"C better than C++?"

Well, first thing - what do you mean by C and C++? In particular, the only canonical definitions of the language which are widely accepted by 'those in the know' are commonly referred to as ISO C99 and ISO C++ 98. I will assume that this is what was meant - these documents are the most recently published international standards for said languages and are not subject to the mishandling of compiler writers. (In fact, there are very few conforming C++ compilers out there AFAIK, though progress is, and has, been made since ISO C++ 98 was published. The same is true of ISO C99, but it's predecessor ANSI(/ISO?) C89 is widely supported.)

The hard bit: what do you mean by better?

Here's my take. The purpose of programming language is to allow programs to be developed more efficiently in terms of time and cost. The real objective is to reduce the time and cost of completing some project or task whether it's a personal project, a group collaboration for the public good or part of a profit making plan. So, 'better' programming languages allow programmers to develop software as part of the project faster and cheaper. The 'best' programming language then is the one which is yields greater productivity.

Now... here's the next problem. How do you measure how productive programmers are with a given language? That's not a trivial exercise, and the results are not going to be easy to generalise. In fact, I find C 'better' than C++ for many programming projects because I can achieve the project goals in less time and using fewer resources. Sometimes, C++ is 'better' for the task at hand.

Importantly, the level of proficiency of the programmer in question is very important. If a programmer knows C++ well and has only a passing acquantance with C then obviously C++ is 'better' for them. Likewise, the other way around is equally valid.

So... do you /really/ mean to ask the question "Is C better than C++?". If so, then surely the only reasonable answer is "depends."

I find the whole "Language X" vs "Language Y" discussions quite tiresome and very unproductive. Afterall, all you need is one zealot on either side and a lot of people get quite offended!

Ian Woods

zer0python
04-30-2002, 08:41 AM
...
I prefer c over c++, reason:

1. c isn't object oriented
2. I like the low levelness of c. /* I know levelness isn't a word! */
3. c if you ask me has a lot more potential the c++, /* why do you think its the crackers/hackers language. (other then asm) */
4. I prefer low level programming more then I prefer high level programming!
5. And if you ask me, its not so damn confusing when, you've programmed thousands of lines into a program!

Shiro
04-30-2002, 10:05 AM
>The purpose of programming language is to allow programs to
>be developed more efficiently in terms of time and cost.

That is from a managers point of view. But from a technicians point of view: the purpose of a programming language is to be able to develop software in such a way that it meets system requirements.

This means that in a lot of situations you don't depend on just one language, but use more languages. A small example: a mobile phone project. The very low level stuff is written in assembly (OS level and below OS level), the low level stuff is written in C and C++ (OS level) and the high level stuff is written in Java (application level / GUI level).

>How do you measure how productive programmers are with a
>given language?

The PSP has shown to be a quite good tool for measuring the productivity of programmers in different languages.

>In fact, I find C 'better' than C++ for many programming projects
>because I can achieve the project goals in less time and using
>fewer resources. Sometimes, C++ is 'better' for the task at
>hand.

It also depends on the design and underlying architecture. If these are object oriented, C++ would be 'better'.

>2. I like the low levelness of c.

C++ is as low level as C. It just depends on how you write your software.

>3. c if you ask me has a lot more potential the c++,

In fact C++ has more potential. It is not only possible to write procedural C code, but also object oriented C++ code. Note that C++ is based on C.

Govtcheez
04-30-2002, 12:02 PM
> 3. c if you ask me has a lot more potential the c++, /* why do you think its the crackers/hackers language. (other then asm) */

::snicker::

I dunno, since they wouldn't be 1337 if they used VB?

Clyde
04-30-2002, 01:38 PM
Surely, since you can use every C-command in a C++ program, C++ is better.

Fordy
04-30-2002, 01:46 PM
Originally posted by zer0python
...
I prefer c over c++, reason:

1. c isn't object oriented

LOL....and that is an advantage??? Perhaps its your naivety here with OPP more than any negative aspect of the language



2. I like the low levelness of c. /* I know levelness isn't a word! */

C++ is no less lowlevel than C....it all translates to machine code.....the difference is in he compilers & the OS and what they will allow you to do



3. c if you ask me has a lot more potential the c++, /* why do you think its the crackers/hackers language. (other then asm) */

More potential?? How the hell is that?? You can write procedural code in C++ as well as implement OOP principals.......and C still has more potential??



4. I prefer low level programming more then I prefer high level programming!

Fair enough.....



5. And if you ask me, its not so damn confusing when, you've programmed thousands of lines into a program!

Again its a matter of experience..........often its easier to understand the structure and purpose of code if you can see an object heirarchy....again this differs from person to person and the code that is being viewed - How well its organised and presented.

Aran
04-30-2002, 02:02 PM
This is a ridiculous thread because:

a.) both languages are C at their core.
b.) the people who are posting their opinions solidly are people who are not very experienced with C AND C++.
c.) there have been countless topics with the exact same purose that have gotten fairly no where.

Unregistered
04-30-2002, 02:21 PM
Nobody can look at 2000 pages of code in any language and be able to understand it. That's why there is a UML.

Imperito
04-30-2002, 02:34 PM
Clyde, there IS C code that is not C++ code. It is possible to write perfectly legal C that won't compile in C++.

quzah
04-30-2002, 02:35 PM
Originally posted by zer0python
...
I prefer c over c++, reason:

1. c isn't object oriented
2. I like the low levelness of c. /* I know levelness isn't a word! */
3. c if you ask me has a lot more potential the c++, /* why do you think its the crackers/hackers language. (other then asm) */
4. I prefer low level programming more then I prefer high level programming!
5. And if you ask me, its not so damn confusing when, you've programmed thousands of lines into a program!

1) Neither is C++. It can be, but it is not. C++ is not a true OO language.
2) Um... anything you can do in C, you can do in C++. (Except getting away with not typecasting malloc's return value. ;) )
3) Oh really? How do you figure?
4) Use ASM then. See #2.
5) This is simply a design issue. Although some classes and the like are hard to decypher.

If you don't like C++ for all of it's additions, you could always simply use it as a "better C" and use classes and the like, while using all of your standard "C" functions.

Quzah.

quzah
04-30-2002, 02:40 PM
Originally posted by Imperito
Clyde, there IS C code that is not C++ code. It is possible to write perfectly legal C that won't compile in C++.

Really?

#ifdef __cplusplus
extern "C" {
#endif

Actually this statement is inaccurate though. Any "C" code you can write can be made to compile in C++. The reason it "won't compile" is due to the C++ compiler being strict in what it allows.

Quzah.

Clyde
04-30-2002, 02:59 PM
"Clyde, there IS C code that is not C++ code. It is possible to write perfectly legal C that won't compile in C++. "

I stand corrected.

Imperito
04-30-2002, 03:14 PM
Yes, there are instances of C does that is not C++. Stricter type checking, and a few subtle differences in grammar make these c++ no-no's:

Implicit int
assignment of int to enum
definition of struct in return type/argument type
calling function without previous declaration
function declared without argument types can take any arguments.
specifiy types of arguments after list of arguments
use a void* as rhs of pointer assignment (unqualified malloc())
Global const variable having external linkage
nested struct declaraction placed in scope of nesting struct
longer initialization of array than array has elements

There are also silent differences, obscure code that is valid in both languages, but does different things. This is irritating in that a compiler might not catch them. They are, however, unlikely in real code.


int foo (int a, int b)
return a //*Hmm*/b
; /* This is unlikely, but it isn't proper C*/
}




int x[99];
void foo() {
struct x {int a;};
sizeof(x) //Size of the array in C, size of the struct in C++
}


Lastly, and this is kind of cheating, but you could use C++ keywords as identifiers, and use C macros that are elevated to keywords in C++ in macro logic, such as:



int class = 0; /*OK in C, c++ would balk*/




#ifndef and
printf("This won't print in C, will in C++");
#endif

Lynux-Penguin
04-30-2002, 05:34 PM
All valid points, and good things, many people wondered why I said those things as pro's and con's I guess i should have mentioned that this is what I heard, not what I know.

However, I do know that the Pro and Con thing bout microsoft is true.
Mostly a joke though.

Thank you for all your comments and opinions, I learned a lot from this so I am sincerely gratefull

jdinger
04-30-2002, 06:53 PM
Originally posted by Lynux-Penguin
However, I do know that the Pro and Con thing bout microsoft is true.
Mostly a joke though.

I still don't get it. How does Microsoft own C++? They do make
one of the most popular compiler but VC++ is just that. A compiler.
They don't own any bit of C++. VB is a different story. That is their
proprietary language.

hairyian
04-30-2002, 07:13 PM
Originally posted by jdinger


I still don't get it. How does Microsoft own C++? They do make
one of the most popular compiler but VC++ is just that. A compiler.
They don't own any bit of C++. VB is a different story. That is their
proprietary language.

Importantly, VC++ isn't even a C++* compiler. For an interesting exercise... can anyone find any documentation on Microsofts site which says that they're VC++.Net offering actually compiles C++*?

Ian Woods

*The C++ programming language is defined in ISO/IEC 14882 as published in 1998 and often called C++98.

hairyian
04-30-2002, 07:40 PM
Originally posted by Shiro
>The purpose of programming language is to allow programs to
>be developed more efficiently in terms of time and cost.

That is from a managers point of view. But from a technicians point of view: the purpose of a programming language is to be able to develop software in such a way that it meets system requirements.


And why would a technician want to meet system requirements? By definition, anything which can be implemented in any programming language on a given platform can be implemented in machine code on that platform. So, machine code allows programmers to develop software in such a way that it meets system requirements - it isn't however the most appropriate or useful 'language' to use in almost all cases.

Importantly, it's not just the 'business case'. The issues involved and which I proposed (time and cost) are central to a business case but also have a significant effect on not-for-profit software development. Case in point: why don't you write all your software in machine code?

I don't know about you, but I like my experimental, learning and 'fun' projects completed in a reasonably timely fashion.



This means that in a lot of situations you don't depend on just one language, but use more languages. A small example: a mobile phone project. The very low level stuff is written in assembly (OS level and below OS level), the low level stuff is written in C and C++ (OS level) and the high level stuff is written in Java (application level / GUI level).


Indeed. I didn't want to promote the idea that any one language is better than any other: the "Depends" answer to which is best is equally true to subsystems as it is to whole projects.



>How do you measure how productive programmers are with a
>given language?

The PSP has shown to be a quite good tool for measuring the productivity of programmers in different languages.


I'm unfamiliar with 'PSP' whatever that happens to be. All performance metrics I've ran into in the real world (real development in and outside of business) depend almost entirely on:

designer competence
implementor competence
co-ordinators competence
amount of software reuse

The only one of those which can be effected by the language features is the amount of software reuse which is possible. Obviously, these aren't of equal 'strength' in terms of getting a project done within budget (if any) or in a timely fashion (if any)... or even 'done' at all. A discussion of these (and whatever I have missed out in my simple 'stick-man' consideration of direct factors for general development would be long winded!



>In fact, I find C 'better' than C++ for many programming projects
>because I can achieve the project goals in less time and using
>fewer resources. Sometimes, C++ is 'better' for the task at
>hand.

It also depends on the design and underlying architecture. If these are object oriented, C++ would be 'better'.


Not necessarilly. Object oriented design methodologies do not require the use of an object oriented programming language. Indeed, making a program in C followined an object oriented design is fairly trivial in C using various techniques including opaque types and dynamic typing.

Obviously, some of these techniques require intermediate C programmers a little time to learn whereas C++ programmers get this almost for 'free' by educating their intermediate programmers good object oriented analysis and design methodologies and concepts. That is certainly an advantage to object oriented languages - the time taken to go from intermediate to competent programmer is reduced for OO concepts to OO implementations.

Again, this is a quite in depth and possibly never ending discussion about object orientation and how it can be implemented in non-object oriented languages. Safe to say if it produces machine code then obviously the same goal can be achieved in several/many languages.



>2. I like the low levelness of c.

C++ is as low level as C. It just depends on how you write your software.


Indeed.



>3. c if you ask me has a lot more potential the c++,

In fact C++ has more potential. It is not only possible to write procedural C code, but also object oriented C++ code. Note that C++ is based on C.

IMO this is another of those questions that needs clarification of terms - 'potential' in this context could mean many things. Who know's what C or C++ may become (or not become) in a decades time? It is likely that the amount of developer interest in C++ may make it appear that C++ has more potential... but then, so did COBOL.

As far as I'm concerned, any language which is only a subjective practical improvement rather than a technological improvement is mere icing on the cake. The whole programming world does not revolve around languages: it revolves around the concepts in which programs and their designs and specifications are expressed. If I invented a language cleaner, simpler and equally as efficient as C++ then I'm not adding to the technology pile... though I might be adding to the practicallity pile. If I made a language which used a paradigm which allowed software reuse more than object orientation does, which allows your program to be proven against it's specification and is simpler and faster to program in then I /might/ be adding to the technology pile.

How is yet another object oriented or procedural or functional or aspect oriented programming language any better or worse other than in completley practical terms over any other in it's class?

Ian Woods

hairyian
04-30-2002, 08:05 PM
Originally posted by Imperito
[B]Yes, there are instances of C does that is not C++. Stricter type checking, and a few subtle differences in grammar make these c++ no-no's:


How's about:

o variable length arrays
o a whole new set of type generic maths functions
o a new meaning to word 'static' (with a famous quote)
o a number of new string processing functions (snprintf for example)
o many new integer types (including long long, int32_t, int_least32_t and so on)
o a boolean type whose semantics are different to C++'s
o expanded environmental and type limits
o a new character set abstraction
o universal character name support (may or may not be in C++, can't remember)
o variable argument preprocessor macros
o the 'restrict' type specifier
o different variable initialisation rules
o different preprocessor defines like __func__ and a set of standard pragmas

and I'm sure if I sat down and examined the difference between the C and C++ specs I'd come up with a few more gems. Here's a simple example of perfectly valid C code which is absolutely not C++ code:

#include <stdlib.h>
#include <stdint.h>

struct foo {
size_t len;
int_least32_t data[];
};


int main(void) {
struct foo * f;

f=malloc(sizeof(struct foo)+sizeof(int_least32_t)*500);
f->data[499]=42;

return EXIT_SUCCESS;
}

The thing to remember is that C and C++ went their seperate ways in the mid 90's, and C has changed a bit since then and the C++ specification has also been defined.

Ian Woods

Govtcheez
05-01-2002, 09:00 AM
> However, I do know that the Pro and Con thing bout microsoft is true.

MS doesn't own C++ anymore than Bell owns C. It's an open language. MS just has a compiler for it (I'd like to see proof that it's not a compiler, hairyian, and don't jsut say that it's not ANSI compliant. I've never seen a compiler that is.)

hairyian
05-01-2002, 09:37 AM
Originally posted by Govtcheez
> However, I do know that the Pro and Con thing bout microsoft is true.

MS doesn't own C++ anymore than Bell owns C. It's an open language. MS just has a compiler for it (I'd like to see proof that it's not a compiler, hairyian, and don't jsut say that it's not ANSI compliant. I've never seen a compiler that is.)

That wasn't quite what I was refering to.

If you go and take a look as MSs website and the promo text for Visual Studio .NET it's quite apparent that they don't even say it compiles C++ /at all/ and I don't mean they don't say "This compiles ANSI/ISO C++98". I mean they don't even say "This compiles C++" or even "C" or "VB". It compiles their new language Microsoft Visual C++ (R) .NET....... I was just playing jest with the notion that calling it a C++ compiler seems to be something MS are explicitely avoiding.

As for 'conforming' compilers, Borland have been claiming their compiler is compliant for a while. Whether or not you believe them is a different matter entirely of course. ;)

Ian Woods

Shiro
05-01-2002, 11:01 AM
>And why would a technician want to meet system
>requirements?

Since technicians are perfectionists. They want the thing they create to be perfect.

And since technicians who are working at a company need to meet system requirements. They have an agreement with the customer about the system requirements, if the product doesn't meet this requirements, the product is not the product the customer wished. So the customer may say: I don't accept this. This will cost the company money.

Why people don't write all software in machine code is mainly because of maintainability.

Perhaps I was not clear, but what I meant to say was that you have to look from different point of views when talking about 'better'. Technicians usually want other things than managers. A manager wants his project to be succesful, which is: the project be finished in time and within the budget. A technician wants to be the product perfect from a technological point of view. This usually doesn't lead to problems if the requirements are clear. The manager knows the requirements need to be met and the technician knows there is a limited time and budget.

I also like my home projects, but at my company I have to do projects in a different way.

>I'm unfamiliar with 'PSP' whatever that happens to be.

The PSP is the Personal Software Process, it's a lot of paperwork which you have to fill in. The main thing of PSP is learning how you function. When you know your weak points and strong points, you know how you can improve yourself.

The PSP is currently mainly implementor competence. I know there are more metrics systems, but I have only experience with PSP.

In my opinion, PSP is not always useful. For example, there is a metric in this system which is about the lines of code you write per hour. I don't think that is applicable, the lines of code you write per hour depends on the kind of task and the level of the task.

>Object oriented design methodologies do not require the use of
>an object oriented programming language.

Sure, object oriented designs don't require an object oriented language, but it makes things easier. Especially when advanced concepts like inheritance are being used. I've worked on a project where we implemented an object oriented design in C. It is possible, but I think it would have taken less time when we did it in C++.

I've heard about object oriented designs being implemented in assembly. I've never done that, but it seems quite a large project to me.

One of the most important things I've learned in programming is programming concepts (algorithms and datastructures) and design methods, since these are language independent.

Lynux-Penguin
05-01-2002, 06:10 PM
Geez...
I could have sworn C++ was from Microsoft... in fact I am sure of it!
IOSTREAM is owned by microsoft


note to self: don't tell anymore jokes

Dual-Catfish
05-01-2002, 09:32 PM
int C = 0;
C++;

dayknight
05-02-2002, 06:39 PM
Originally posted by Lynux-Penguin
Geez...
I could have sworn C++ was from Microsoft... in fact I am sure of it!
IOSTREAM is owned by microsoft
[/code]


hahahaha FUNNY hahahha lynx stay on linux

Sorensen
05-03-2002, 03:34 PM
Indeed, making a program in C followined an object oriented design is fairly trivial in C using various techniques including opaque types and dynamic typing...

snip

..Safe to say if it produces machine code then obviously the same goal can be achieved in several/many languages.


True, but a creating an object orientated design in C often requires far more runtime support than in C++, where alot of the details are resolved by the compiler.


The thing to remember is that C and C++ went their seperate ways in the mid 90's, and C has changed a bit since then and the C++ specification has also been defined.

Not really. C++ aimed for backward capability with C, with some stronger type checking, and then C got updated in C99. C++ will incorporate most of what you mention in C++ 0X to maintain that compatibility. Although, whether vendors decide to implement it is another matter.