• Advertisement
Sign in to follow this  

C++: multi-paradigm or just dual-paradigm?

This topic is 4326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just wanted some clarification on the matter. Seeing that I know that C++ can naturally do OOP and procedural programming, I figure it to be dual paradigm programming language (DDPL). I know you can do templates and somehow they're trying to make it functional (why I don't know). Is the number of paradigms determined by what it was meant to do (procedural and OOP) or what you hack into the library?

Share this post


Link to post
Share on other sites
Advertisement
I personaly think that it depends on how many layers it supports, lowest being procedural(basic), next being modular(C), highest being OO and/or functional (python, lisp, c++, and so on).

so, yeah, very multiparadigm.

Share this post


Link to post
Share on other sites
At least i think you can say C++ supports OOP, procedural and generic or metaprogramming paradigms, so that's three already. And isn't the standard library part of the specs that define what c++ is, so why wouldn't that count as support for some paradigm?

Maybe I have been brainwashed from reading Stroustrup's book.[grin]
Here's something from the man:
Quote:
Multiparadigm programming is a fancy way of saying "programming using more than one programming style, each to its best effect." For example, using object-oriented programming when run-time resolution between different object types is required and generic programming when static type safety and run-time performance is at a premium. Naturally, the main strength of multiparadigm programming is in programs where more than one paradigm (programming style) is used, so that it would be hard to get the same effect by composing a system out of parts written in languages supporting different paradigms.
(...)
Standard C++ and the design and programming styles it supports owe a debt to the functional languages, especially to ML. Early variants of ML's type deduction mechanisms were (together with much else) part of the inspiration of templates. Some of the more effective functional programming techniques were part of the inspiration of the STL and the use of function objects in C++
Bjarne Stroustrup

Share this post


Link to post
Share on other sites
I find it hard to call C++ anything other than procedural. Its OO is broken, and its functional features (most of the STL and boost), and template metaprogramming are inconsistent hacks. If people are determined, however, they can stretch C++ to support almost whatever 'paradigm' they want, but the result is always messy. This is not necessarily a criticism of C++, in fact it's the language I use most often. It just goes to show that it's best to use something for what it was made for. If you really want to use a functional / more OO / more dynamic approach to programming, look at other languages designed with that use in mind. Haskell, Smalltalk, Common Lisp and Python come to mind. However, if you're determined to stretch C++ to its limits, I guess you can say it "almost supports" other paradigms.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brobanx
I find it hard to call C++ anything other than procedural. Its OO is broken...


How so? I've been using C++ classes in an OO way for a while, and I would not consider them "broken". They encourage encapsualtion and polymorphism, which is really all you need for OOP. Templates count for Generic programming, so I would consider that making C++ multi-paradigm.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
lol, I just had a thought, maybe one of the reasons C++ is so popular is because you can "hack" it about & stuff, we can do every thing C did but now we've got even more to play with!

I think the OO part is abit broken as well, I was going to make a post here myself today asking almost or something similer to the OP "What is c++ about, how am I supposed to program in it?" when I try doing proper OO I feel like I'm trying to get square pegs into round holes all the time!!

But then again there has to be a reason its so popular with proffessional game studios & others, (not just hobbyists/ametears), so maybe it needs to be used where and how its needed, so for API's for instance (as in Interfaces etc), then yeah use the OO part and polymorphism, but for orther things use other techniques?

What does anyone think?

Share this post


Link to post
Share on other sites
In terms of C++'s OO, just look at what other languages offer you, that C++ doesn't. Namely, reflection (no, C++ RTTI doesn't count). Languages like C# also offer more practical things like static constructors / attributes. Yes those are really just syntactic sugar, the same things can be done in C++, but it is harder to read and understand. Now, my personal opinion is that OO in C# and Java is also broken, OO was meant to be done in a dynamically typed language like Smalltalk or Python, where methods and attributes can be added / edited / removed from classes and objects at runtime. However, people seem to love statically typed languages, and that won't change anytime soon. In this regard, C++ is only slightly behind langauges like C# and Java, reflection being the missing feature.

As for the functional paradigm, try using boost::lambda for anything worthwhile, you'll know what I mean about "hacks". I agree with the above post, I think C++'s popularity is due to the fact that you can hack your way to code in nearly any style you want. C++ doesn't do any ONE particular paradigm very well, except for procedural. Template metaprogramming? See lisp macros for the true power in metaprogramming. OO? See smalltalk. Functional? See SML / Haskell. Generic programming? It only serves a purpose in statically typed languages, and in this regard I think haskell's type inference is much more powerful than the use of templates. So C++ is essentially the jack of all trades. It'll do whatever you want, if you're willing to settle for less.

Share this post


Link to post
Share on other sites
Interesting. Yet I don't see why folks would want to make C++ a jack of all trades. Wouldn't you just want to improve on what you have? As opposed to make it simulate every language at once. How about easier bindings to other languages? Wouldn't that make more sense or be easier for the programmer?

Share this post


Link to post
Share on other sites
Obviously I don't know much about programming paradigms as I only have used C++ (and some Basic [dead]) and just recently started with python. However, I find the case that Bjarne Stroustrup makes quite reasonable: multiparadigm programming is about the combination of styles in close cooperation. So maybe lisp macro's is better for metaprogramming, smalltalk for OO and haskell for functional. Goal of C++ design is - correct me I'm wrong - to have a multiparadigm system level language.
This would then be why it's a jack of all trades, except that the combination of 'trades' and the flexibility in itself is kinda like a new trade. Now correct me if I'm wrong, this is just how I understand what Stroustrup says, I don't have any strong opinions about it, all this programming stuff still amazes me anyway at least if it's beyond basic.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement