11 Replies - 13641 Views - Last Post: 23 November 2012 - 12:56 AM

#1 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

C vs C++ - Stroustrup Interview

Posted 14 August 2012 - 10:07 AM

Hey,

I just found this interview and being maybe a little naive, I'm not really sure how much of a joke it is... Some of it actually makes a little sense.

Having concluded that it's a joke, I'm a little curious about the arguments for C vs C++. I've noticed that many Linux enthusiasts, Linus Torvalds included, regard C as a their preference, but I've never really thought of them as very different. When I decided to learn C++, I considered C as well, but came to the conclusion that they were basically the same, except that C++ supports OOP and is generally an improved version of C. How wrong was I in assuming that?

Maybe this has to do with the fact that I never saw a computer until 1998 and am a little to young to have experienced this debate... I seem to be the product of the "OOP is everywhere" generation.

Is This A Good Question/Topic? 1
  • +

Replies To: C vs C++ - Stroustrup Interview

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2151
  • View blog
  • Posts: 3,306
  • Joined: 21-June 11

Re: C vs C++ - Stroustrup Interview

Posted 14 August 2012 - 11:09 AM

View PostCbeppe, on 14 August 2012 - 07:07 PM, said:

When I decided to learn C++, I considered C as well, but came to the conclusion that they were basically the same, except that C++ supports OOP and is generally an improved version of C. How wrong was I in assuming that?


Quite. C++ has lots of features that C doesn't have that aren't related to OOP programming: Function overloading, references, templates, namespaces, new+delete, etc.

Even when not designing your application in an object oriented way, a C++ application will look quite a bit different than a C application.
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: C vs C++ - Stroustrup Interview

Posted 14 August 2012 - 11:23 AM

One aspect of the C vs C++ debate is the "C++ hides what it is doing from you." What may look like a innocuous variable declaration maybe doing tons of work behind it because of its has a big hairy constructor. eg. char buffer[1024] vs. char vector<char>(256). (I think that the same theme is present in the C++ vs C# debate where a single line in C# that looks "cheap" is actually an expensive operation.)

On the other hand, C++ was designed with OOP in mind and one of the principles is encapsulation. And it's not just data that is encapsulated, but concepts are encapsulated as well. This lets the programmer start thinking in higher level concepts rather than being buried by the minutia.

On the same concept of hiding things, if you use a template function, how do you know ahead of time whether a brand new copy of the function will be created, or if the compiler and linker will take care of doing some code folding so that the same function will be used for types that are functionally the same.

I've worked on a project which demanded to be built in C, but at the same time had to object oriented. The objects we had begged to be polymorphic so we were building our v-tables by hand and calling into them. Not really a good use of a programmers time if you ask me. The C++ compiler hides that overhead of going into the v-table, but to C programmer it's obvious that there is overhead involved when going into the v-table.
Was This Post Helpful? 1
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C vs C++ - Stroustrup Interview

Posted 14 August 2012 - 01:58 PM

Quote

...except that C++ supports OOP and is generally an improved version of C. How wrong was I in assuming that?


Actually this is a pretty big gaff and one that is really common. I think much of the frustration C programmer's have with C++ is that they still think like this.

C++ is not a superset of C, it is a whole new language that happens to have a good amount of compatibility with C syntax. The big problem with C++ is that people still think it is C+somestuff.

C++ supports OOP-ish programming better than C does, it supports generic programming, is supports a great deal of functional programming, it is a pretty abstract language. For example Boost::Proto and Metaparse are libraries for "compile time parsing" which allow one to create sets of objects that behave like language syntax expansions -- This allows on to create DSL (Domain specific langauges) or kind of sub-languages embedded into C++ (for example Boost::Spirt or Boost::Xpressive).

C++ does not have any more functional power than C (ANYTHING you can do in C++ can be done in C - they are completely equal in computational power) but it does allow for far more abstract syntactic representations. It is a "higher level" language than C.

To achieve some of the things that it does, it does make some low-level design decisions that are not directly compatible with C. For example "Name mangling" and v-tables and member-function calls. All things that can make interoperability with C a little more difficult if you are used to working at the low-level of C.

I am a C++ programmer and not really a C programmer. I initially learned C++ as C-with-classes and that makes for a poor C++ programmer and a poor C programmer (although this is still the primary method of teaching C++). I may be a little bias on C++'s merits, but I do strive to understand what others feel that its shortcomings are. I think most of the problem comes when C programmers try to use C++ to write C-programs.
Was This Post Helpful? 4
  • +
  • -

#5 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 04:43 AM

Quote

I just found this interview and being maybe a little naive, I'm not really sure how much of a joke it is... Some of it actually makes a little sense.

The interview was a hoax. See what Bjarne Wrote about it here.

Quote

Linus Torvalds included, regard C as a their preference

Linus Torvalds has some very strong opinions of C and C++, and even though he is clearly a very talented programmer, I agree with this article when they say he's 'suffering' from so-called, "C hacker syndrome". Personally, I completely disagree with Linus and would usually prefer to use C++ over C, unless I'm working in embedded environments or writing very low level code (like a kernel for example), where using C++ is unnecessary (in my opinion).

Quote

When I decided to learn C++, I considered C as well, but came to the conclusion that they were basically the same, except that C++ supports OOP and is generally an improved version of C. How wrong was I in assuming that?

Well, yes, in an abstract sense, I would say that C++ is an improved version of C, and I think that Bjarne would agree. However, C++ is based more on the idea of being general purpose and as useful as C, but providing high level abstractions at minimal cost as well.

If you want a serious criticism of C++ (not that I agree with it), you might want to look at this. I won't go in to that right now though.
Was This Post Helpful? 2
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,806
  • Joined: 16-October 07

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 05:53 AM

Obviously, the link is from a disgruntled C programmer. Resulting in many responses from gruntled(?) C++ programmers. Which got me to thinking...

As pointed out, C++ is it's own language. However, it does compile C programs. With little or no tweaking. The tweaking is usually getting rid of warnings, casting things that MUST be cast in C++, etc. In this respect, C++ IS a superset of C, in that it can compile C. This gives C++ programmers an odd perspective on C. C becomes the limited subset of instructions that you're often not supposed to use.

Why would anyone use C, if C++ was available? Even if you weren't doing OOP, you could get "new" and "delete" and lots of other extras. Indeed, some people use C++ not as C with objects, but as C with extras. The result of which is usually a bad example of both C and C++.

Why use C at all? C is very simple language. A limited language. Lacking all the niceties of every other modern language. And yet, limitations aren't necessarily bad...

Writing a C program, in C, limits the programmer's options. Robert Frost once said that writing free verse was like playing tennis without a net. Meaning that the limitations of poetic structure allows for a more focus expression of ideas. Being forced into the domain of C, to think in that domain, requires a different sensibility than most languages.

C++ is a panacea. It can be all things to all people. There is no net. ( There is no spoon... ) It's unclear if this is better than C, worse than C, or just different. It theoretically means not reinventing the wheel. At the same time, when that wheel breaks, it can be apocalyptic. No one debates that C++ error messages are the absolute worst. In C you can take your debugger down to ASM level. Don't bother with C++, all those candy coated layers of abstraction mean you're usually tracing other people's code more often than your own.

I like C. I like C++. It's a different kind of like.

Later in Linus' epic rant, he says this:

Quote

IOW, C++ is in that inconvenient spot where it doesn't help make things
simple enough to be truly usable for prototyping or simple GUI
programming, and yet isn't the lean system programming language that C is
that actively encourags you to use simple and direct constructs.

-- http://article.gmane...ntrol.git/57960


There's something to that. It's hard to hurt yourself in Java or C# and tons of production code has been written in them. C++ straddles the divide between the high and the low. It's a strange place to be. There are days I feel this is fine and days I feel like switching languages.

I think every programmer should be exposed to as many languages as they can. And try to leave the baggage at home. Learn not just the language, but how the language does things. The more of this kind of exposure, but better you'll be at any given language.
Was This Post Helpful? 4
  • +
  • -

#7 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 06:38 AM

Thanks for all the replies so far.

For me at least, it seems that it will be worth learning C as well, separately from C++. The reason I learned C++ in the first place was to get into a low-level language that would help me develop my understanding of programming in general. C seems to be a valuable foundation to have to continue developing that knowledge.
EDIT: Baavgai's post seems to support this.

One of the key criticisms of C++ in the interview I posted was how C++ leads to a longer development time and more complexity, than if the same project was done in C. Is there really any merit to this argument? Normally, I'd think that OO code will speed up development as it keeps things more readable, but I don't really have the experience to say. At the same time though, I couldn't imagine writing anything longer than a small script in C++ without using OOP.

Any opinions on this?

This post has been edited by Cbeppe: 15 August 2012 - 06:43 AM

Was This Post Helpful? 0
  • +
  • -

#8 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,806
  • Joined: 16-October 07

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 07:51 AM

*
POPULAR

Don't use the "interview" as a guide; it's clearly slanderous satire. While there might be a kernel of truth in some C++ abuse, that one is mostly just trolling.

Complexity is the bugbear of all programming. Any project of any significant size gets messy. There is usually no clear solution to managing this mess, since programmers created it themselves.

The intent of OOP is to help control the chaos. It does this by creating little boxes filled with related code and data, often hiding much of that from everyone outside the box. From a bird's eye view, this means you only need be concerned with the stuff you can see in the box.

In non OOP, there is no box. Or, if there is, the box is open and everyone can look in. None of the functions that only work on the box are explicitly linked to it, they all exist for the programmer to wade through. There are non OO techniques of dealing with this. Many of methods for controlling this chaos lead to OO in the first place.

Make no mistake. Object Oriented techniques DO help with large projects. OOP can greatly enhance maintainability and provide a built in road map for future maintainers. However, such techniques aren't magic bullets and blindly following any ideology will get you burned.

The sneaky problem with OOP is that you can really get into making boxes. There are boxes in boxes and relatives of boxes and boxes that only talk to certain boxes. What often looks like really good organization early on can become an exercise in fighting that organization later on. One the other hand, a well done OO framework is a joy forever...

The only real solution is experience. Many of the critiques of languages come from going down bad paths with that language. Experience will teach you how to avoid those paths, regardless of language. You will still find your way to treacherous places, but hopefully you will learn to see the danger coming sooner.
Was This Post Helpful? 6
  • +
  • -

#9 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 915
  • View blog
  • Posts: 3,193
  • Joined: 12-May 09

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 08:50 AM

View Postbaavgai, on 15 August 2012 - 10:51 AM, said:

The sneaky problem with OOP is that you can really get into making boxes. There are boxes in boxes and relatives of boxes and boxes that only talk to certain boxes. What often looks like really good organization early on can become an exercise in fighting that organization later on. One the other hand, a well done OO framework is a joy forever...

And there are descendants of boxes whose sole purpose is to generate other boxes. Too much OO can be as bad as no OO. Good summary.
Was This Post Helpful? 1
  • +
  • -

#10 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 09:39 AM

@Baavgai & xclite:
That's some solid piece of advice. I know what you mean about the clutter of boxes that one can get into making. Java is a prime example of that IMO.
Was This Post Helpful? 0
  • +
  • -

#11 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: C vs C++ - Stroustrup Interview

Posted 15 August 2012 - 07:19 PM

rant about how I think "OOP" is a horrible misuse of C++:

there are 2 main features that support OOP in C++, polymorphism and inheritance. inheritance, IMO, is all too often a bad abstraction simply becuase most things don't fit in such a hierarchy(some do, and then it's a very nice abstraction). take iterators for instance, they were put in a hierarchy for some odd reason(albeit not using inheritance) and it makes iterators hard to work with in more abstract cases. the boost iterators library got it right by breaking up the features in to separate concepts and avoiding a hierarchy. polymorphism allows for runtime generic code, and that's something I like(mimicking interfaces tends to work out well). inheritance can get rid of a ton of boilerplate(look at policy based design); something I really like doing is inheriting from another specialization of the same class so that very little to nothing has to be reimplemented in each specialization. std::function is another amazing use of polymorphism(I wish they had something like it for iterators).

Point is, I really enjoy the use of polymorphism and inheritance but "OOP" in C++ is not something I enjoy. The key is to use the features of C++ together to form more powerful abstractions. If you look at a lot of use cases I just mentioned, you'll see templates or some other feature interacting with polymorphism/inheritance. That's the key to C++, don't use OOP, don't use functional programing, don't use generic programing, use C++. limiting your feature set and calling your code OOP like that makes it good is one of the stranger ideas I've ever heard.

This post has been edited by ishkabible: 15 August 2012 - 07:26 PM

Was This Post Helpful? 0
  • +
  • -

#12 Alisa1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-October 12

Re: C vs C++ - Stroustrup Interview

Posted 23 November 2012 - 12:56 AM

Nice Thread ..
Good information is share ...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1