![]() |
|
C++ over C? - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: C++ over C? (/Thread-C-over-C) |
C++ over C? - BORW3 - 05-09-2014 I don't see why till today people learn C. I think it's outdated as hell and C++ should become the universal usage and we do away with C completely, like the way we forgot floppy disks existed. Could someone please give me pointers to why C is important in this day and age. I am 50-50 about learning it. RE: C++ over C? - dropzon3 - 05-09-2014 "C++ is to C as Lung Cancer is to Lung." C is a fairly simple and elegant language. Just to give a (very) rough comparison of the language complexities both languages have books written by their creators documenting the language. For C this book is 'The C Programming Language' and in 274 pages you can learn everything you need to know about C - http://www.amazon.com/C-Programming-Language-2nd-Edition/dp/0131103628 For C++ the book is 'The C++ Programming Language' and 1368 pages long...that is a striking difference and is a a good indication of the different in complexity between the languages. Anyone that wants to promote C++ because it has OO functionality ought to refer to Alan Kay the guy who coined the term object-oriented: "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." — Alan Kay As mentioned earlier C is a very simple language, you have the normal control flow keywords, includes and compiler-time defines, you have the usual primitive types and you have structures, enums and unions. From that you can create everything and do so effectively with little overhead from the standard library. C is a great language that works for everything the only complicated part of it for some is memory management and pointers it is not a bloated language with unnecessary features. It also forces you tot think much more simply about your problems and consider how the the code is going to be executed which makes it a good choice for learning how the computer works. That said if you plan to go into industry programming C++ is quite common and a good choice to learn. There is nothing wrong with C though either; and odds are you could pick C up in a weekend after C++. I'll end with one last quote: "Historically, languages designed for other people to use have been bad: Cobol, PL/I, Pascal, Ada, C++. The good languages have been those that were designed for their own creators: C, Perl, Smalltalk, Lisp." — Paul Graham RE: C++ over C? - erpicci - 05-15-2014 One of the core concepts of C++ is that C code compiled with a C++ compiler is not less efficient than the same code compiled with a C compiler. This may leed to the wrong conclusion that C is a subset of C++. This example taken from bytes.com show that it is false: Code: #include <stdio.h>
struct A { char c[1000]; };
int main(void) {
struct B { struct A { char c[1]; } a;
char c[1]; };
printf("sizeof(struct A): %lu\n",
(unsigned long)sizeof(struct A));
return 0;
}Another issue is that valid C code which is not valid C++ may not compiled. Moreover, C++ is quite obscure under certain circumstances (i.e. virtual method overriding), and may lead to unexpected results. I do not have examples of these right now, but if someone is intereseted I can provide some. Of course these are technical considerations. For educational purposes in high school or first years university they are not significatively different. Quote:I don't see why till today people learn C. I think it's outdated as hellC isn't the most modern language out there, but still far to be "outdate". For instance, Google Go programming language is strongly influenced by C, both in its syntax both in the way shared memory is (internally) managed, and one implementation of the go compiler is able to link only with C, not C++. It is also worth to say that many so-called modern languages commonly have "outdated" mechanisms (i.e. parallelism in Java). I agree with @dropzon3 on almost everything he said, but I wouldn't consider the manual lenght as a indicator: the C manual he mentioned just covers the basics, to fully understand the language it takes much more. Still I agree C to be somehow simpler than C++. RE: C++ over C? - Inori - 05-16-2014 I don't know that much about the family but I feel like C is the base for all C strands as well as some other languages. I feel like it should be learned if you want to expand the languages you know. RE: C++ over C? - Souvarine - 05-19-2014 My personal opinion is that your statement is wrong: 'C++ or C?' C and C++ are two different languages. For some programs you will need C and in some other situations you'll use C++. When to use C? C is one of the fastest programming languages still in use. With good programmer programs written in C can be amazingly fast. C is used on almost all embedded platforms because C compiler is easy to integrate into that stuff. If you have time, patience and knowledge you can write everything you want in C, and your product can be ultra-fast and stable. What about C++? On the other hand, C++ started as C with some additions. Nowadays it has grown into much bigger and complex programming language. C++ is very high-level language compared to C. In C++ you can write more complicated things much faster and easier, but you lose some performance of program itself. Influence of C programming language C programming language influenced most popular and most widely used programming languages such as Ruby, Java, Python, etc. For example, when you have your project written in Ruby you can check for slowest parts of it and then rewrite them in C. After that you can easily integrate them into your Ruby project making it much faster. What about industry? Nowadays C++ is used for writing game engines, big and complex programs and other similar stuff (mostly really big programs). C is almost always used when it comes to embedded platforms and sometimes when better performances are needed. Neither is used for web or mobile development (recently Android released SDK which gives you option to use C++ for app development, but it still isn't in wide use). RE: C++ over C? - erpicci - 05-19-2014 (05-19-2014, 02:49 PM)Souvarine Wrote: In C++ [...] you lose some performance of program itself. What is the source for that? According to Bjarne Stroustrup, who designed C++, "C++ supports the styles of programming done using C [...] without loss of efficiency" (see What is the difference between C and C++?), and "Every C program can be written in essentially the same way in C++ with the same run-time and space efficiency" (see Is C a subset of C++?). Of course, in the same FAQ page, Stroustrup also explains differences between C and C++, and admits that C is not formally a subset of C++. RE: C++ over C? - Souvarine - 05-20-2014 (05-19-2014, 07:42 PM)erpicci Wrote:(05-19-2014, 02:49 PM)Souvarine Wrote: In C++ [...] you lose some performance of program itself. When I wrote that I was thinking about careless use of STL templates. Source: http://en.wikipedia.org/wiki/Standard_Template_Library#Quality_of_implementation_of_C.2B.2B_compilers Loss of performance in C++ wholly depends on the programmer. RE: C++ over C? - erpicci - 05-20-2014 I see, the point here is that the careless usage of a certain C++ feature (in this case STL template) may lead to problems (loss of efficiency, code bloat...). This can happen in C as well, for example abusing reallocs, gotos, void pointer and other "features". RE: C++ over C? - Souvarine - 05-20-2014 (05-20-2014, 02:28 PM)erpicci Wrote: I see, the point here is that the careless usage of a certain C++ feature (in this case STL template) may lead to problems (loss of efficiency, code bloat...). I totally agree with you, but somehow I think majority of beginners are making some omissions with bad usage of STL features rather than with memory allocation or gotos in C. I think it is easier to remember not to use goto and to be careful with memory allocation than carefully reading documentation about every STL feature you use. Now, when I look at this discussion, I can see that we have alienated ourselves from real question. Therefore I'm discarding my claim about performance. I think performance clearly depends on programmer, not on programming language in this case. RE: C++ over C? - kasakari - 05-20-2014 When I first began the programming part of my college education, the first thing that was thrown after the concepts class was a fundamental programming class which used C for everything. I think it was a perfect starting point as much of the methodology I gained from the class makes converting to other languages like c++ and java very smooth and I was able to pick up everything fairly quick. |