You are not logged in.

#1 2013-12-18 13:59:24

thiagowfx
Member
Registered: 2013-07-09
Posts: 532

C++ versus C: is C really "better"?

Update (2014-07-15): although this topic was originally about C/C++, people started to discuss about programming languages in general. I think this was  good luck (serendipity!), and I encourage you to keep using this thread to discuss about this (= programming languages in general) subject, since we don't have  another one dedicated to it. Happy programming!

Hello my fellow Arch Community,

Recently I read some books about open source and Unix (ESR's ones). I could conclude from them that, in general, "open source people" prefer C over C++. Furthermore: that C++ is a poorly design language, bloated, with overkill features (...). This should be a reason to programmers choose first C, before C++, when designing / creating new programs.

Besides, it is a known fact that Torvalds hates C++ (example). ESR seemed to me not to be a C++ fan either. Also, pacman, cower, yaourt are all written in C. Not to mention the Linux Kernel.

But when I learned C++ for the first time months ago, I found it to be so great, with classes, polymorphism, namespaces (...). It is so less annoying than C. With a bonus of being compatible with it!

I want to further specialize myself in one of these languages (C++, actually), but I'm not sure if C would be a really better language for that. I want to know why people seem to reject the C++ language. If you head to https://www.ohloh.net, for example, you'll find so much big projects written in C++ (firefox, for example, I think). So I don't really know why this "war".

Shouldn't us be writing all our programs in C++, since it is a more modern language? Why the strong resistance over C++?

OBS.: I know the differences between C and C++, at least in the programming level. I also did some research here, but they don't seem to discuss what I'm proposing; they are kinda old too, maybe something has changed since then. See (1), (2), (3), (4), (5) (not exactly) for example.

Last edited by thiagowfx (2014-07-17 22:04:14)

Offline

#2 2013-12-18 14:51:32

JohnnyDeacon
Member
From: Colombia
Registered: 2012-01-18
Posts: 81

Re: C++ versus C: is C really "better"?

I'm not an expert for this themes, but I think you can't compare C with C++ in fact C++ is a major release of C but with classes. C is an imperative (procedural) language, it means, you only can construct programs by functions. C++ has all of this, but adds classes (new data type) that can create software by creating templates, like real life. In fact, that was the final purpose of its developers. Make programs like you cooking for example. I better prefer that someone else that works with programming tell us the real differences, but I'm little sure that C is for hardware interactions developments Like Linux Core and C++ for general purposing.

Offline

#3 2013-12-18 14:52:51

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,424
Website

Re: C++ versus C: is C really "better"?

thiagowfx wrote:

Shouldn't us be writing all our programs in C++, since it is a more modern language?

No. C and C++ are different languages. I know that you already know this, but I don't think it gets emphasized enough: C and C++ are different languages.

I think the reason so many programmers think of them as pretty much the same is because of the similar names and that so much of the code looks similar. But all C code will not compile with a C++ compiler. And code compiled as C++ will produce a different binary than code compiled as C. And the same code can have different meaning in C and C++...

They're just different languages. Asking "is C or C++ better?" is no different than asking "is C or PHP better?", or "is Java or Ruby better?", or "is Bash or Objective-C better?" It all depends on what software you are making.

It will probably take you a lot longer to "master" C++ than it will C since C++ is a much more complicated language. If you want to know which one you should master, I don't know... Python? big_smile

Last edited by drcouzelis (2013-12-18 15:02:27)

Offline

#4 2013-12-18 14:57:26

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,378
Website

Re: C++ versus C: is C really "better"?

C++ is better!   big_smile

Offline

#5 2013-12-18 15:46:06

poiuyt23
Member
Registered: 2011-10-12
Posts: 75

Re: C++ versus C: is C really "better"?

Best comparison I can make is one is a car one is a utility van.  One can do the same jobs as the other but you either spend a lot more gas and upkeep than you need it you misuse the van or extra trips if you misuse the car.  In your case the question seems which would you like to learn.  Depends on what you want to do.  There are tons of opinions out there hold your nose and run a Google search.

Last edited by poiuyt23 (2013-12-18 15:47:05)

Offline

#6 2013-12-18 15:51:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 12,435

Re: C++ versus C: is C really "better"?

Have you looked at KDE?

It was suggested that this might be a BIKESHED topic, but I am willing to let it go for a while.

My 2 cents.  I use both, for different purposes.  I do a lot of embedded system development.  Often, memory is precious, and memory managers are, errr, less than mature. For embedded systems, I use C almost exclusively.  In my mind (and there are those who disagree with me) it is more deterministic in real time systems;  at least it is easier to prove that it is more deterministic.  On the other hand, on the occasions when I find myself designing GUI interfaces I really prefer the OO model.

The problem with C++ is that it is easy to forget what is happening on a real system.  Fledgeling programers might think nothing of using (or will unknowingly use) a copy constructor on some behemoth object and be oblivious to the time and memory overhead.  Likewise, in using overloaded or polymorphic functions, lose track of which code is actually executing resulting in a loss of visibility of processing time, memory, and other resources.   Not good when you are designing systems with hardware-in-the-loop safety critical real time requirements.

Last edited by ewaller (2013-12-18 15:53:43)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Like you, I have no idea what you are doing, but I am pretty sure it is wrong...Jasonwryan
----
How to Ask Questions the Smart Way

Offline

#7 2013-12-18 16:18:13

nomorewindows
Member
Registered: 2010-04-03
Posts: 2,963

Re: C++ versus C: is C really "better"?

I myself have a little trouble with the division between C and C++.  I write one fine in C, but then I try to do it in C++ and if it doesn't really require the complexity for C++ to write it, it becomes unbalanced quickly.  It seems that the compiler also wants to do things differently than you intend them.  I did a comparison one time between Basic (being the slowest), Turbo Pascal and Turbo C.  The same program using the different languages.  C was touted to be the fastest and most powerful.  But there was a quirk in the way that Turbo Pascal was designed and would actually outrun Turbo C.  Turbo Pascal did ok with ADT, but C++ was just better on Object Oriented programs by far.  But as far as C versus C++, unless there's really a reason to use C++, it starts becoming somewhat profound.  But now for a big project there's Qt which is it's own library on top of C++.

Last edited by nomorewindows (2013-12-19 14:56:04)


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#8 2013-12-18 16:45:56

srs5694
Member
From: Woonsocket, RI
Registered: 2012-11-06
Posts: 719
Website

Re: C++ versus C: is C really "better"?

Throughout history, bloody wars have been fought over religion -- the 30-years war, the Crusades, etc. Religion simply evokes strong emotional responses -- strong enough to motivate people to kill. To computer programmers, programming languages are like religions. Fortunately, though, computer programmers usually prefer playing with computers to playing with heavy weapons, otherwise we'd have actual wars between the followers of the Blessed Python and the Holy C. As it is, as far as it tends to go is things like the Torvalds diatribe which was referenced in the first post of this thread. Despite the technical reasons cited in many such opinions, though, there's also a lot of emotion and ego involved, so take such claims with a grain of salt.

Personally, I've used many languages over the years -- BASIC, Pascal, C, C++, LISP, bash scripts, and more. Each has its advantages and disadvantages. None is superior to all others for all things, and the ones that have survived the test of time tend to have something at which they're really good. LISP, for instance, is known as an AI language; but you probably wouldn't want to write an OS kernel in it. (I fear that somebody will respond with a link to just such a thing -- but if it exists, it's likely to be an academic project or something that's very specialized.)

As to C and C++ specifically, although the Linux kernel and many of its low-level utilities are written in C, there are plenty of important programs written in C++. Ewaller has mentioned KDE. IIRC, LibreOffice/OpenOffice.org is another. On a much smaller scale, so is my GPT fdisk (gdisk, cgdisk, and sgdisk). There may be a way to search on Sourceforge for language to find more, but if so, I couldn't find it, so I'll leave it there -- I simply don't know what most programs actually use.

So the bottom line, IMHO, is that you shouldn't worry about what Linus Torvalds, Eric S. Raymond, or anybody else thinks about C vs. C++. If you think that C++ has features that would be useful to your program, then go ahead and use it. The worst-case scenario is that you'll be wrong, and you'll discover that quickly enough when you get into trouble -- but that's not entirely bad, because you'll learn from that mistake, at least as much as you'll learn from whatever book or Web site(s) you use to read up on C++ language features. (This isn't to say, though, that you should ignore all advice; just don't get hung up on somebody's pseudo-religious biases for and against particular languages.)

Offline

#9 2013-12-18 16:55:05

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,532
Website

Re: C++ versus C: is C really "better"?

thiagowfx wrote:

"open source people" prefer C over C++.

I have two issues with this.  First, I'm not sure it's true.  Second, even if it's true, it wouldn't imply anything about the languages.

I prefer C to C++ for my own use, but I don't think it is better any more than I think a screw driver is better than a hammer.  I do tend to use screw drivers more often than hammers, but that's because I'm assembling and disassembling electronics more often than I am adding a deck to a house or building houses.

As has been said above there are different tools for different jobs.  The jobs that C and C++ are most suited to have a good degree of overlap, but they still are each tailored for different purposes.

I've used C++ when the task at hand called for it.  I've even used Objective-C when the task called for it, though I might try to deny it.  When C is a viable option or when either could be used, I use C because I am most comfortable with it not because it is "better" in some grand or fundamental way.

I suppose in short I like C because it "fits me".  But if I were to conclude that C was objectively better simply because it fit me better than C++, I would be implying that fitting me was an objective criteria that a language should acheive, and thus indirectly be saying that I was better than other programmers for whom C++ is a better fit.  I think we need to take care to separate what we *like* from what is objectively good/better.

Last edited by Trilby (2013-12-18 18:58:37)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#10 2013-12-18 18:06:39

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,033

Re: C++ versus C: is C really "better"?

srs5694 wrote:

you shouldn't worry about what Linus Torvalds, Eric S. Raymond, or anybody else thinks about C vs. C++ anything.

Fixed

Offline

#11 2013-12-18 18:37:53

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 5,633
Website

Re: C++ versus C: is C really "better"?

Trilby wrote:

redacted

This example is borderline flamebait. You know our rules.

EDIT: Removed flamebait material at request of Xyne ~fukawi2

Last edited by fukawi2 (2013-12-18 22:06:08)

Offline

#12 2013-12-18 18:52:25

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,424
Website

Re: C++ versus C: is C really "better"?

Xyne wrote:

This example is borderline flamebait.

Everything else in this thread is actual flamebait. big_smile

Offline

#13 2013-12-18 20:15:57

thiagowfx
Member
Registered: 2013-07-09
Posts: 532

Re: C++ versus C: is C really "better"?

Thank you so much to everyone who replied to this topic! Usually I comment every reply I receive, but I won't do this here *extensively* because (1) there are many of them (but, if you ask me, I'll gently do this) and (2) this topic doesn't really have an answer (therefore I won't mark it as SOLVED, too), I just wanted some clarification / opinion of the Arch community (this question could be asked elsewhere,  but maybe it wouldn't be much related to my context).

I won't extend this discussion here because it was suggested it could be BIKESHED, and because I'm satisfied with the existing replies.

--

My brief conclusion of your replies:

C++ is usually better to design GUI programs (like QT) or to model complex real-world problems (because of its classes and OOP philosophy).
For everything else, specially to embedded systems or in time/memory critical applications, C should be fine ("better") -- I am not considering other languages in this discussion.

But, it is always good to keep in mind that every different project has its own needs, so each case should be individually analyzed, independently of the main choice of person X or Y.

--

A few comments:

@drcouzelis: your emphasis is worth. Usually this doesn't look clear enough (although with C# it is completely clear, I've never seen anyone confusing C# with C or C++).
@poiuyt23: I love your analogy.

Offline

#14 2013-12-18 20:33:32

Glazy
Member
Registered: 2013-12-18
Posts: 7

Re: C++ versus C: is C really "better"?

You shouldn't worry about what other people think about the language that you decide to program in.

You have got to choose for yourself and decide which one you personally think is better smile

Offline

#15 2013-12-18 21:02:55

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: C++ versus C: is C really "better"?

One thing to consider is that if you're mainly interested in C++ because you like object orientation, well, Python can do that, often (almost always?) with fewer lines of code. So, if you're mainly interested in C++ because it combines speed and object orientation, an alternative is to consider embedding python in C.

I'm not saying C++ is no good. I've used it myself and enjoyed it. I'm only saying that there are more options out there. If I was starting a project from scratch, and if I decided I want to do it in an object oriented way, and the program needs to be fast, once upon a time I might have defaulted to C++, but I would now at least think about whether I could do it as a Python/C hybrid.

Learning C will have the added benefit that it will train you more in how to think about data structures and memory management. It will also put you in a better position to later contribute to the vast number of open source projects that use C rather than C++. (Yes, I know some such as Octave use C++, but they're a minority.)


thiagowfx wrote:

Shouldn't us be writing all our programs in C++, since it is a more modern language?

I can design a new language any time I feel like it. Just because it would be the most modern language available doesn't mean it would be any good.

If someone makes a car with fashionable square wheels, do the square wheels trump round ones because they're more modern?

Should you fly an airplane to the shops around the corner because airplanes are more modern than feet?

By such counter-examples, it's easy to see that appeals to modernity constitute a form of fallacious argument.


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#16 2013-12-19 00:13:49

AaronBP
Member
Registered: 2012-08-06
Posts: 140
Website

Re: C++ versus C: is C really "better"?

One thing to consider is that if you're mainly interested in C++ because you like object orientation, well, Python can do that, often (almost always?) with fewer lines of code.

That's the things for me. These days everything doesn't have to be compiled ahead-of-time to be (reasonably) fast. Most languages go out of their way to be compatible with C, so it makes sense to use it to mix it with a higher level language. What is C++'s place now when there are so many easier, safer languages to choose from?

Offline

#17 2013-12-19 13:56:39

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 986

Re: C++ versus C: is C really "better"?

thiagowfx wrote:

My brief conclusion of your replies:

C++ is usually better to design GUI programs (like QT) or to model complex real-world problems (because of its classes and OOP philosophy).
For everything else, specially to embedded systems or in time/memory critical applications, C should be fine ("better") -- I am not considering other languages in this discussion.

I think it is incorrect to disregard other languages, because other languages are the real reason people like me prefer C. (I don't claim to speak for everyone.) Saying C++ is better than C for GUIs is like saying that a Camry is better than a Civic for hauling gravel through a rainforest; it may be technically true, but that decision can only result from a long chain of terribly bad choices.

If C and C++ were the only two high-level languages we had, we'd probably use C++ for darn near everything, because it is a more expressive language -- I don't think anyone's debating that point.

But bring in one new language, say Perl, and suddenly you don't have to use C++ for text manipulation anymore, because you have a better tool. Then introduce Java, and now you don't have to use C++ for very big OO projects or enterprise desktop software. Then introduce Lua or Tcl or something, and you're free to add application scripting to the list of things you don't need C++ for. By the time you get around to Python, you've forgotten what you ever needed C++ for, because the only things you're left doing in C++ are things you can do just as well in plain C, which is a smaller language and better designed.

tl;dr: If you're using C for something and wonder if you should switch to C++, you probably shouldn't have picked C in the first place.

Last edited by Trent (2013-12-19 13:57:00)

Offline

#18 2013-12-19 14:19:39

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: C++ versus C: is C really "better"?

thiagowfx wrote:

I could conclude from them that, in general, "open source people" prefer C over C++

I'm sure that there are technical reasons everyone has for their preference, but I wonder if it's more accurate to say that Unix-like OS users (who may contribute more to the open-source ecosystem----don't quote me on that) prefer C because it's the predominant language in Unix-like operating systems. I'd be willing to bet that Windows users who create open-source programs use C++ to do it, since that's the predominant language in Windows.  I'd be willing to bet that people who want to program choose which of those two languages is most "relevant" to their OS of choice.

Offline

#19 2013-12-19 14:38:02

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,604

Re: C++ versus C: is C really "better"?

I wonder if we're approaching a point where newbie programmers might consider going with D rather than C++?


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#20 2013-12-19 14:41:57

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,532
Website

Re: C++ versus C: is C really "better"?

alphaniner wrote:

I wonder if we're approaching a point where newbie programmers might consider going with D rather than C++?

That is the trend among students at my university.  Oh wait, you're still talking about programming languages! wink


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#21 2013-12-19 14:43:35

nomorewindows
Member
Registered: 2010-04-03
Posts: 2,963

Re: C++ versus C: is C really "better"?

I think it has been that languages have moved away from machine language and become more human language.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#22 2014-01-12 03:58:24

mmix
Member
Registered: 2014-01-11
Posts: 33

Re: C++ versus C: is C really "better"?

c++ is harder, easy to be complex/messy,
vala/d/clojure/scala would be better alternative.

GNOME's Git Tool Has Been Ported To Vala
http://www.phoronix.com/scan.php?page=n … px=MTU2MTA

Offline

#23 2014-01-18 14:26:01

Exodus111
Member
Registered: 2013-12-28
Posts: 26

Re: C++ versus C: is C really "better"?

Why would anyone want to subject themselves to a non OOP language?
Maybe its cuz I mainly use Python, I mean I can see why you might want to use C if you want to make a library very efficiently but other then that I can't see the point.

Offline

#24 2014-01-18 14:54:18

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,424
Website

Re: C++ versus C: is C really "better"?

Exodus111 wrote:

Why would anyone want to subject themselves to a non OOP language?

Because object oriented programming is not always the best tool for every job.

Offline

#25 2014-01-18 15:08:03

Cloudef
Member
Registered: 2010-10-12
Posts: 636

Re: C++ versus C: is C really "better"?

Exodus111 wrote:

Why would anyone want to subject themselves to a non OOP language?

http://people.freebsd.org/~lstewart/art … memory.pdf

Rust will be the holy grail that saves us all.

Last edited by Cloudef (2014-01-18 15:10:51)

Offline

Board footer

Powered by FluxBB