[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

A question about C and its C++ descendant

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 8
Thread images: 0

What exactly could I benefit from learning C rather than C++?, I'd like to assume that C runs much more faster than C++ but googling that seems not to be the case, if C++ is a superset of C and has more functionality and can remove the lower level details while keeping the same execution time, is it pointless to learn C? Or is it because so many things have already been set in stone in C which is why we cannot "upgrade" to C++.

I would like historical background knowledge and an informative well explained answer, thanks for your time.

p.s I am an aspiring to-be C programmer that is about to click "Order now" of The C programming Language 2nd edition, but I'm contemplating whether to order a C/C++ book
>>
The main reason people hate C++ compared to C is that the added features temps a lot of shitty devs to over engineer everything.
Though a lot of these features are really useful when used in moderation.

C++ is fine, just don't go full pajeet.
>>
>>57141793
What do you mean by "over engineer everything", also what do you have to say about functionality programming vs object oriented? I personally dislike object oriented programming and the concept of it but when I start thinking about building guis and such I can't seem to think C is capable of doing this (It probably is but I don't know any better). Also what about execution time and overhead?
>>
1. C++ is not a supsetset of C. Although a lot of C code compiles as valid C++, not only are there numerous cases where this diverges (in particular with C++'s stronger typing), there are cases where C has expanded where C++ has not expanded in the same ways.

2. The reason to learn C over C++ as a beginner is due to its simplicity. It's easier to learn C++'s features in terms of C's features, than to start off from a position of heavy abstraction and work down. If you already know C++, however, the benefits of knowing C very well is simple: understanding the vast number of pre-existing codebases written in C.

3. C++ does not outright remove the low level details, it just offers high level alternatives. But regardless, if you are going to call yourself an effective C or C++ programmer, you HAVE to understand all of these low level details, regardless of how much abstraction you use. So don't make your decisions based on this weird notion that you can "remove low level details". C++ isn't Java, and if you treat it like Java, you should be programming something else.

4. Read C Primer Plus, rather than K&R. It's a bit less dated.

5. Pirate your goddamned textbook.
>>
>bikeshedding about useless things and contemplating about myths and stereotypes you saw on the internet instead of just picking one and learning it

You could have already finished a couple of chapters in any book, but instead you chose to inflate your ego by discussing things you as a beginner can't have any idea about (see >>57141815 and its talk about object oriented programming and creating GUIs).
>>
>>57141755
C is normally used to write portable low level libraries that you'll want to compile on many different platforms and architecture. Once you have the library working in C, you can write a C++ / Python / Java / PHP / whatever wrapper for it.

It's also used to write kernels and device drivers, because the assembler output of a C compiler is very predictable to an experienced programmer.

The C++ spec is very massive because of the feature it offers, and takes a huge effort to implement all of them. Not every platform supports the latest and greatest C++ standard, but you can bet all of them has a working C compiler that's pretty up to date.

C++ is normally used when creating large programs where performance is critical, or when you want to have the same fine control as C, at the possible cost of complexity.
>>
Another question, can someone tell me why Python is intrinsically slower than C/Java? IIRC Python is still compiled but to a lesser degree than C/Java but its just not optimized and still being interpreted line by line. Is this the only reason why its slow? Id like to know some under the hood stuff as to why its so slow
>>
>>57141755
There is one obvious advantage to C: it has a very stable ABI. This means that it's easy to use a precompiled C libraries in your program. With C++ libraries, things can get tricky due to some of the languages features. If you're using the same compiler the library was compiled with you're fine but otherwise.... well... you get problems. This also means that it's easier for other languages to use C libraries (not always easy, but that depends on the language itself).

The less obvious advantage is that it's harder to write unreadable code in C (not impossible mind you, just harder). Since you cannot overload operators, functions and there are no destructors and constructors, C needs to be more explicit by definition. This is a non-issue when you work alone, but can be a nightmare when reading somebody elses code (this is how you know good programmers from bad ones).

There are also some edge cases where C++ is a suboptimal solution due to its implicit memory management. Currently I'm dealing with an embedded project that has 3 different RAMs and I need various parts of code to execute from different kinds of RAM (the CPUs can barely do the task and crippling them with a slow RAM would spell doom to the project. Oh, and I can't fit all the data in the fast RAM, since it's on-chip and very small) - I'm sure I could do this in C++, but since I had to write my own memory allocator for C, I'm not sure this would work well with new() and delete(). Or STL.
Thread posts: 8
Thread images: 0


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.