C++: 4 paradigms?

C

crichmon

I've perused the FAQ, found some mention of paradigm, but didn't really find
an answer to my question.

What is meant by "C++ is a 4 paradigm language?" What are the 4 paradigms
of C++ and what makes them paradigms? Is C++/CLI the 5th paradigm of C++?
why/why not?

thanks,
crichmon
 
P

Phlip

crichmon said:
I've perused the FAQ, found some mention of paradigm, but didn't really find
an answer to my question.

What is meant by "C++ is a 4 paradigm language?" What are the 4 paradigms
of C++ and what makes them paradigms? Is C++/CLI the 5th paradigm of C++?
why/why not?

- procedural. Programs control flow directly
- OO. Programs control flow indirectly, thru virtual methods
- generic. Like OO but bound at compile time

- declarative.

The last one is like SQL. You arrange elements in the shape of the result
you want, pull the rip cord, and the elements drive an engine to produce the
result.

I have no idea how that should work in C++ or if it's what they meant.

I have never learned a reason to distinguish these paradigms. Just write.
 
I

Ioannis Vranos

crichmon said:
I've perused the FAQ, found some mention of paradigm, but didn't really find
an answer to my question.

What is meant by "C++ is a 4 paradigm language?" What are the 4 paradigms
of C++ and what makes them paradigms? Is C++/CLI the 5th paradigm of C++?
why/why not?


Yes C++ is a multiparadigm language and currently supports 4 paradigms.
The procedural paradigm (functions etc), the modular paradigm
(namespaces), the object oriented paradigm and the generic programming
paradigm (templates). Each paradigm is supported well with optimal space
and time efficiencies.



Regarding C++/CLI, I have not seen anyone else call it as the 5th
paradigm except me. Perhaps you have seen it in my pages where I write
"We can dare to say that C++/CLI is the fifth paradigm of C++". However
I do not if this has much scientific basis, and I am going to remove
that line if I get many complaints about it. :)






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
A

Alf P. Steinbach

* Ioannis Vranos:
Yes C++ is a multiparadigm language and currently supports 4 paradigms.
The procedural paradigm (functions etc), the modular paradigm
(namespaces), the object oriented paradigm and the generic programming
paradigm (templates). Each paradigm is supported well with optimal space
and time efficiencies.

I didn't know that.

But certainly it's not something everyone agrees on.

For example, I absolutely do not agree that C++ "supports" modular
programming, since there _is_ no module concept in C++. However,
C++ allows you to fake some of it by strictly following some set of
conventions (header file guards etc.). That's in the same spirit
as assembler language supports object-orientation (even old TASM).
 
I

Ioannis Vranos

Alf said:
I didn't know that.

But certainly it's not something everyone agrees on.

For example, I absolutely do not agree that C++ "supports" modular
programming, since there _is_ no module concept in C++. However,
C++ allows you to fake some of it by strictly following some set of
conventions (header file guards etc.). That's in the same spirit
as assembler language supports object-orientation (even old TASM).



I have seen what I said above in TC++PL3 . In chapter 2 BS explains the
paradigms supported and you can find the modular paradigm on page 26 (2.4).






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
A

Alf P. Steinbach

* Ioannis Vranos:
I have seen what I said above in TC++PL3 . In chapter 2 BS explains the
paradigms supported and you can find the modular paradigm on page 26 (2.4).

Well I doubt that Bjarne says C++ supports modular programming in a
sense different from OO (e.g. like Modula or Pascal or Ada), but if he
really does then I for one disagree! ;-)
 
I

Ioannis Vranos

Alf said:
Well I doubt that Bjarne says C++ supports modular programming in a
sense different from OO (e.g. like Modula or Pascal or Ada), but if he
really does then I for one disagree! ;-)



Have you read the paragraph I provided you? In case you do not have this
book here is how it starts:



[It is placed after the procedural paradigm explanation and the topics
are placed in historical ordering].



"2.4 Modular Programming

Over the years, the emphasis in the design of programs has shifted from
the design of procedures and toward the organization of data. Among
other things, this reflects an increase in program size.

A set of related procedures with the data they manipulate is often
called a module. The programming paradigm becomes:


Decide which modules you want;
partition the program so that data is hidden within modules."



Then it has some more.





Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
A

Alf P. Steinbach

* Ioannis Vranos:
Have you read the paragraph I provided you?

Nope, cause you didn't provide it... :)

In case you do not have this book

I don't. I have the first edition, though.

here is how it starts:

[It is placed after the procedural paradigm explanation and the topics
are placed in historical ordering].

"2.4 Modular Programming

Over the years, the emphasis in the design of programs has shifted from
the design of procedures and toward the organization of data. Among
other things, this reflects an increase in program size.

A set of related procedures with the data they manipulate is often
called a module. The programming paradigm becomes:

Decide which modules you want; partition the program so that
data is hidden within modules."

Hum, well, that could refer to just about anything, including OO, and
it doesn't say that C++ supports _whatever_ it is, so as usual I think
Bjarne has not overstated the case, but here is being misinterpreted.
 
I

Ioannis Vranos

Alf said:
Nope, cause you didn't provide it... :)



I was talking about this: "In chapter 2 BS explains the paradigms
supported and you can find the modular paradigm on page 26 (2.4)."



Hum, well, that could refer to just about anything, including OO, and
it doesn't say that C++ supports _whatever_ it is, so as usual I think
Bjarne has not overstated the case, but here is being misinterpreted.



OO paradigm is mentioned later and in this paragraph namespaces are
mentioned for implementing the paradigm:


"
[...]

C++ provides a mechanism for grouping related data, functions, etc.,
into separate namespaces. For example, the user interface of a Stack
module could be declared and used like this:


namespace Stack{ // interface
void push(char) ;
char pop() ;
}


void f()
{
Stack: :push(´c´) ;
if (Stack: :pop() != ´c´) error("impossible") ;
}


The Stack:: qualification indicates that the push() and pop() are those
from the Stack namespace. Other uses of those names will not interfere
or cause confusion.

The definition of the Stack could be provided in a separately-compiled
part of the program:
namespace Stack{ // implementation
const int max_size = 200;
char v[max_ size] ;
int top = 0;
void push(char c) { /* check for overflow and push c */ }
char pop() { /* check for underflow and pop */ }
}

The key point about this Stack module is that the user code is insulated
from the data representation of Stack by the code implementing
Stack::push() and Stack::pop(). The user doesn’t need to know that the
Stack is implemented using an array, and the implementation can be
changed without affecting user code.


[...]

"



Anyway it is an excellent book and I think every C++ programmer should
buy and *read* it.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
A

Alf P. Steinbach

* Ioannis Vranos:
Anyway it is an excellent book and I think every C++ programmer should
buy and *read* it.

Yes, I agree.

In fact it's even stronger: if you like the book then you're probably
a good C++ programmer or C++ programmer material, and if not, then
likely not. ;-)

And yes, as shown (I snipped that example) it's possible to implement
Modula/Pascal/Ada-like modules in C++, by use of conventions. Some
features are not possible to implement though. For example, transparent
module initialization requires language _support_. And in a language
with module support you get automatic checking of module dependencies
and such, which must be faked via brittle include guards in C++. Etc.

Cheers,

- Alf
 
T

Tommy McDaniel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ioannis Vranos said:
Regarding C++/CLI, I have not seen anyone else call it as the 5th
paradigm except me. Perhaps you have seen it in my pages where I write
"We can dare to say that C++/CLI is the fifth paradigm of C++". However
I do not if this has much scientific basis, and I am going to remove
that line if I get many complaints about it. :)

I saw it on your page the other day, and remember wondering what basis
you had to say that. I'm not telling you what to put and not put on
your page, but maybe the fact that that particular piece stood out to
me also well before reading this means something.

Tommy McDaniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA+0y2VB8FYP9YqDcRAmfrAJ9ON0tBcXG978LKKYekvkVHDbQ7fwCfc4Za
8OMIln9shItZlxgYC6rqN3U=
=bkCw
-----END PGP SIGNATURE-----
 
T

Tommy McDaniel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Phlip said:
- procedural. Programs control flow directly
- OO. Programs control flow indirectly, thru virtual methods
- generic. Like OO but bound at compile time

- declarative.

In that case it seems that there is disagreement on the fourth
paradigm. The one I have seen mentioned elsewhere is modular. Maybe
this makes five paradigms.
I have never learned a reason to distinguish these paradigms. Just write.

Amen.

Tommy McDaniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA+049VB8FYP9YqDcRAv7uAJ4xsvAVJpFCwScVCt/8bnTQ95Ia0QCfVQUJ
4YD46YE+TosdZty+Lkef0tg=
=LDHj
-----END PGP SIGNATURE-----
 
T

tom_usenet

Regarding C++/CLI, I have not seen anyone else call it as the 5th
paradigm except me. Perhaps you have seen it in my pages where I write
"We can dare to say that C++/CLI is the fifth paradigm of C++". However
I do not if this has much scientific basis, and I am going to remove
that line if I get many complaints about it. :)

Surely C++/CLI is just adds extensions to some of the already present
paradigms, particularly OOP.

Tom
 
C

crichmon

Ioannis Vranos said:
Yes C++ is a multiparadigm language and currently
supports 4 paradigms. The procedural paradigm
(functions etc), the modular paradigm (namespaces),
the object oriented paradigm and the generic
programming paradigm (templates). Each paradigm is
supported well with optimal space and time
efficiencies.

Thanks everyone for the answers!

Regarding C++/CLI, I have not seen anyone else call
it as the 5th paradigm except me. Perhaps you have
seen it in my pages where I write "We can dare to
say that C++/CLI is the fifth paradigm of C++".

Yup, that's where I got it. :)

However I do not if this has much scientific basis,
and I am going to remove that line if I get many
complaints about it. :)


crichmon
 
I

Ioannis Vranos

Tommy said:
I saw it on your page the other day, and remember wondering what basis
you had to say that. I'm not telling you what to put and not put on
your page, but maybe the fact that that particular piece stood out to
me also well before reading this means something.


Well, I was thinking it in this way. C++ has already been open for a GC
(TC++PL C.9.1). However when it would get a mainstream supported one?

Only when one such VM had been standardised. So here we are, CLI is a
standard, C++/CLI is an upcoming standard on how to take advantage of
such a CLI when present, with *deterministic* destruction - explicit
delete on GC objects in the managed heap and creation of GC objects in
the stack - with the latest one to be the recommended style of
programming in C++/CLI, with generics (difference from templates is that
generics are executed at run-time while templates at compile-time and
some other restrictions of generics) etc. And of course the ability to
use ISO C++ and C++/CLI mixed (which makes the source code
compilation-portable, while the clean C++/CLI mode makes it possible the
executable itself to be portable across all CLI compliant VMs).

So I do not know if we can call the GC thing a paradigm, but C++/CLI is
a new concept for sure.


BTW yesterday I discovered that Mono ( http://www.mono-project.com )
exists for GNU/Linux, Unix, Mac OS X and Windows itself.

The download page fro this CLI VM is:

http://www.mono-project.com/downloads



Interesting stuff.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
P

Phlip

Tommy said:
Phlip wrote:

In that case it seems that there is disagreement on the fourth
paradigm. The one I have seen mentioned elsewhere is modular. Maybe
this makes five paradigms.

How could modular be a paradigm? How could a programming language not be
modular? JavaScript is modular.
 
U

Uwe Schnitker

Ioannis Vranos said:
I was talking about this: "In chapter 2 BS explains the paradigms
supported and you can find the modular paradigm on page 26 (2.4)."

Note that Stroustrup no longer emphasises "modular programming" in his
more recent interviews or writings. I'd suppose it was included in
TC++PL to show what he sees as the historical progression from
procedural prgramming to OO.

He writes and talks a lot about the 4 paradigms nowadays:

1) C-Style Programming

2) Data Abstraction

3) OO Prgramming

4) Generic Programming

see, e.g.

http://www.research.att.com/~bs/style_and_libraries.pdf

written in 2002.

What Stroustrup describes as "Data Abstraction" is programming with
standalone concrete classes like std::string. He considers this
programming style to be quite different from OO programming with class
hierarchies. He also thinks that an appropriate emphasis on this
programming style is important to avoid creating unnecessarily complex
class hierarchies. See this interview with him:

http://www.artima.com/intv/goldilocks.html

I happen to agree - even if I'd prefer to use a term like "Class-Based
Programming" to "Data Abstraction".
 
D

Don Kim

He writes and talks a lot about the 4 paradigms nowadays:
1) C-Style Programming

2) Data Abstraction

3) OO Prgramming

4) Generic Programming

That seems to fit the 4 most often used terms for the different paradigms
that C++ allows. Though, I've often seen the term "procedural" programming
for 1) and "Object Based" for 2). If I'm not mistaken, in Lippman's C++
Primer, the section before OO, is titled Object Based Programming.

There also is a lot of work going on to extend C++ into the functional
paradigm, such as Boost's Lamba library and another one called FC++. For
the latter, there is even a library extending FC++ to the declarative or
functional-logic paradigm. Its called LC++:

http://www.cc.gatech.edu/~yannis/lc++/

So it might be the case that C++ has 6 paradigms. If you include the work
going on in "template metaprogramming", which I'm not familiar with yet, and
it in fact extends the template mechanism beyond (good term "meta", since it
is the greek based term for beyond) its orginal design (which I heard it
does), then this might be another paradigm as well. On the new C++/CLI
extensions, its hard to say if it creates another paradigm, but I think it
might, since its goal is to allow all the C++ mechanisms to be run in a
managed run time enviroment and even the ability to run in both the managed
and unmanaged environment. This does in some sense, change the way you
program and the mental model you have of going about it.

Oh yeah, lets not forget there is also an extension to add Aspect Oriented
Programming to C++: http://www.aspectc.org/

So as I see it, here are the paradigms C++ allows:

(1) Proceedural
(2) Object Based (or Data Abstraction)
(3) Object Oriented
(4) Generic
(5) Functional
(6) Declarative
(7) Metaprogramming
(8) Aspect Oriented
(9) Managed Runtime (aka C++/CLI)

I would say the first 4 are the core paradigms, and the last 5 are yet to
have wide spread adoption, though (5), (7), and (9) are strong canidates for
it. Also, (9) is still fuzzy as to whether it is in fact a new paradigm or
just an extension to target a managed environment.

- Don Kim
 
J

jeffc

Alf P. Steinbach said:
* Ioannis Vranos:

Yes, I agree.

How can you agree if you've neither bought it nor read it? The guy provides
you with chapter and verse for you to look up, you fail to do so, yet keep
arguing with him.
 
J

jeffc

Uwe Schnitker said:
He writes and talks a lot about the 4 paradigms nowadays:

1) C-Style Programming

2) Data Abstraction

3) OO Prgramming

4) Generic Programming


I happen to agree - even if I'd prefer to use a term like "Class-Based
Programming" to "Data Abstraction".

class-based programming = object-based programming (as opposed to
object-oriented programming), so I don't really see how this is a separate
paradigm since OO "includes" it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top