tags:

views:

384

answers:

16

What is the best route to go for learning OOP if one has done some programming in C.

My intention was first to take the natural leap and "increment with one" and go for Stroustrup. But since I got my hands on the little old Bertrand Meyers OOSC2 and I qoute from the appendix page 1135 "..according to Donald Knuth, it would make Edsger Dijkstra 'physically ill to think of programming in C++" And Meyer himself "..that C++ is not the ideal OOP language..."

And what about this A critiqe on C++ on this question: A critique of C++

Should I skip C++ and go for C# and or Java directly if my intention is a great and deep understanding of a modern OOP-language, or do I miss good points on this subject in C++?

Well I know this is a discussion-thing but I mark it wiki and you're answers could mean a lot for me in choices to come.

A: 

For a Java centric introduction, I highly recommend Head First Object Oriented Analysis and Design from the excellent "Head First" series by O'Reilly.

I found the book to be very approachable and easy to understand, no matter what direction you're coming from. While the book uses Java, the OOP concepts discussed in the book are applicable to any OOP language.

Kevin
+4  A: 

C++ is not only an OOP language. It is multi-paradigm (procedural, OOP, functional, generic...)

So if you want to learn just OOP, maybe it is not the best choice.

Didier Trosset
A: 

Absolutely skip C++.

Matt Ball
Some background, or reason *why* would be helpful. :)
jalf
There are two areas where C++ falls short of being a true OO language.1. It lacks reflection.2. C++ runs in an unmanaged environment, so it is possible to write code that has hidden side effects, which violate encapsulation.
Jay Elston
+2  A: 

I would suggest C#. The syntax is similar, but it's different enough to keep you from falling back into old C habits. With C++ I always found myself writing C, with the occasional object thrown in.

C. Ross
I can recommend the heads first book on C# as well. I recently went back to it and found it doesn't cover advance things like threading, but is great way if you like the heads up way of learning.
optician
+1. This was the language that made me REALLY understand what OOP is all about. Though, of course, there may be others even better than C# at this.
Vilx-
the nice thing about c# is that it is nice and clean and OO like java, but it lets you get deep into the platform too. SO you get the best of both worlds. THis is what people used to love Delphi for (the man who did Delphi also did c#)
pm100
+2  A: 

Objective-C

Aito
Agreed. It's C, plus objects.
just_wes
Prepare to be locked in Mac/iPhoneOS(/GNUStep) programming if you go for ObjC.
KennyTM
A: 

Learn C++ only if you want to work on it, on projects that use it, in jobs maintaining C++ code (which will continue to exist for many years). C++ is far from a dead language.

But it probably ought to be considered a niche language these days for anyone starting a new project and doing something like a web application, rich client GUI, etc. Most typical applications, C++ would be a self-defeating choice, like deliberately making it difficult for yourself.

But if you like a real challenge, go for it.

Much longer answers from me on similar subjects:

Daniel Earwicker
But what about this new C++0x coming up Stroustrup says on his site that he is not able to make a new book before the "new" language is out?
Chris_45
It is the same language with a few dozen little additions here and there; he probably just means that it would be pointless to update his book until the committee agrees on the final standard.
Daniel Earwicker
@Chris_45: C+++0x is still the same language, just better. It doesn't change C++'s status as "not really a dedicated OOP language". It's good news for C++ programmers, but it doesn't really affect the answer to your question.
jalf
+3  A: 

Yes. If your intention is "a great and deep understanding of a modern OOP language", go for a modern OOP language. C# definitely qualifies on the "modern" count, and prides itself on being OOP. Something like Smalltalk would be the OOP language, but it is less modern. You could always learn both.

As for C++, it's hardly an OOP language. There are many good and valid reasons to learn C++, but not if you're only interested in OOP.

Today, C++ is characterized not by OOP, but by features such as generic programming and to some extent inspired by functional languages.

There are many useful lessons to be learned from C++. A few of them are:

  • some very nice techniques for managing resource lifetime, which "modern" languages like C# and Java could learn a lot from
  • The generic programming paradigm, and the extent to which it can make OOP completely pointless. The whole idea of thinking about types in terms of traits and concepts, rather than which interface they implement, and the preference for truly reusable non-member functions is interesting to someone who still thinks that OOP is the holy grail of programming.

If you're asking whether you should learn C++, I'd say yes (along with 5-8 other languages. C++ is not "special" in any way. It's one of many languages that programmers can profit from learning).

If you're asking whether C++ is going to be a good introduction to OOP, I'd say NO. Which is exactly why it is worth learning.

jalf
I concur. C++ is not the best into to OOP, because it's so multiparadigm. It can really be a mess sometimes, which is not to say it's a bad language, it's just the complexity can be overwhelming.I know Java and I'm learning C#. Java wouldn't hurt to learn, it can feel a little constrictive, as the language seems to be designed to enforce a particular idea of best practices. C# is a little closer to C in style, and from what I know of it, it's a little more elegant in some cases.
jsn
A: 

I would say Java. A good book that helped me is this one.

Michael Kelley Jr.
A: 

I'm with the other commenters, in C++ it's far too easy to slip back into C. Structurally, Java and C# are similar to C, and the core languages are nearly identical to each other. Once you learn to think OO, C++ will come much easier.

Joel
+1  A: 

I would say start with Java. The Java tutorial is well written with lot of examples which you can (should) run and experiment with. Coming to books I would say check the Head First Java and Head First Object Oriented Analysis and Design from the Head First series. Once you get your feet wet with Java and get fair idea about Object Oriented Concepts invariably you would run into design patterns and for which the book Head First Design Patterns provides a good start. All these I think would provide good basic starting point for your exploration of object oriented programming.

sateesh
A: 

Even though I think a lot of those criticisms of C++ are fair, at the end of the day Java and C# did not diverge that significantly from C++ in OOP paradigms, which was clearly a huge influence on both of them. To say you will learn OOP wrong by learning C++ instead of Java is sort of stupid since their OOP models are extremely similar.

And to talk about a bunch of techniques that programmers in that language happen to use (template programming), and acting like it's something you have to use is silly. Saying that you could "fall back into C" is another stupid reason - you can avoid OOP in ANY language (for example, in Java, you can write a program within one class).

Want to know one of the best reasons to learn C++ over Java or C#? There are many more interesting projects that are already in C++ then in the other two. This is changing with time, but look around on SourceForge, and it seems C and C++ are still the predominant languages for the type of projects that I find interesting (games, web browsers, etc).

FranticPedantic
I do think C++ is worth learning, and that you can certainly learn the OOP model from it. But I still think it's not the best language for learning OOP. After the basic tutorial, I learn by reading code. The prevalence of other paradigms in the language means that to really read C++ code, you have to learn more than just the OOP stuff. You don't have to use it but you do have to learn what it is, distinguish it from the OOP stuff and understand how it complicates the programming model. This is useful in the long run, but not the best didactic strategy for learning just OOP.
jsn
+2  A: 

The fundamental idea of C++ is to reuse the C syntaxic idioms by applying OOP semantics on them. This leads to objects "on the stack", the use of ++ for iterators, and so on. The C syntax was developed mostly for ease of implementation of the C compiler, not for OOP, and the result is that C++ is quite complex a language and ill-suited to learning.

Java and C# are much simpler to learn, while still sticking to the class-based approach of OOP that C++ uses. Java is a bit simpler than C#, because C# designers knew Java and decided to have a similar syntax with a bunch of extra syntaxic goodies. Those goodies make C# syntax a bit more complex, hence less appropriate for learning.

There is another structural approach of OOP, which is the one of Smalltalk. A "modern" and widely used language which uses that approach is Javascript. You may want to try that. Javascript is quite cool in that you only need a Web browser to try it, and through the browser it has access to a rich graphical environment. In the same family, you may want to try Lua, which is said to be simple, and quite popular.

Thomas Pornin
A: 

I learned OOP in both Ada95 and C++ and coming from plain C and Ada83. I didn't think it was that hard to learn the concepts of OOP with C++ because I was already familiar with the syntactical elements and pointers.

What is your purpose though? To become a good C++ developer, or to just understand OOP?

If it is the latter, then pick a language that you understand and go from there. Java, C#, or even C++ would all be good choices. If it is the former, you will have to buckle down and learn a lot about C++ and how it works under the hood. It takes time and practice to become a good C++ developer.

Dr. Watson
+1  A: 

Any language will do if you learn it from a good book. I learned both C++ and Java starting from Bruce Eckel's books.

After you know some basics of OOP, I would suggest reading Object-Oriented Programming with ANSI-C. It will give you some deep insights on how OOP languages work, because it implements an OOP language from C.

Danilo Piazzalunga
A: 

As others have already mentioned here C++ supports more than one programming paradigm. Probably the most noticable is mixing classes and objects together with "global" functions which is easily possible within the same file and context.

But in my opinion there is enough OOP paradigm in C++ to use the language to learn OOP. It is much more important to have a good guide for OOP itself. Such a guide will teach you to use the object oriented elements in C++ and how and for what purpose and it won't tell you anything about C-style functions you could also create in C++.

For your decision what language to choose I'd recommend to look a bit further into the future what you actually want to do in programming. If it is web or rich UI desktop development you will have more use of Java or C#, is it rather something closer to system development, C++ might be the better choice. OOP you can learn with C++ and Java, C# or other languages as well.

For me it is a bit like the question: "I want to learn how to translate texts from my native language into other languages. What second language shall I learn? Icelandic or Swahili?" For this decision it might be more important whether you hate cold or hot climates. (At least I would consider this as more important than the arguments some linguists will probably have to prefer one of the languages.)

I think it is true that for instance C# will FORCE you much more than C++ to write OOP code but it does it only in terms of the language SYNTAX. But OOP is more about semantics and that is rather language independent. There is no semantic difference between sin(0.5) (a function without class context in C/C++) and Math.Sin(0.5) (a class method in C#). If you end up in C# to create lots of static classes something went wrong with learning OOP although you follow (necessarily) an object oriented syntax.

So my two cents: Try to find additional programming goals you have beyond learning OOP and add these goals to your decision for the language you want to dive in. Only for learning OOP C++ as an example language is fine and some other languages as well.

I need to add: I've said this from a "pragmatic" viewpoint presuming that you actually want to work and to create software with what you've learned. If you have a kind of pure scientific, structural interest my arguments might be all wrong. Then maybe the purest of all OO languages (Smalltalk?, probably not C++) is the right choice, no matter who actually "speaks" this language and for what purpose.

Slauma
A: 

After a year of reading books and trying examples by myself, I broke down and took a class "Object Oriented Programming in Java" from a local community college. I was able to learn in a classroom setting where I failed on my own. (This is unusual for me -- I have managed to learn a lot of technologies on my own). I think the classroom setting with a real teacher who could explain things, other students to discuss things with, and small but useful assignments and class projects to exercise the newly learned material were a good combination.

Many of the other students were IT professionals. I made some good contacts. Alas, this was 18 years ago, and I lost touch with almost all of them.

The downside -- this did cost money, but it was affordable, and when I got laid off a year later, I was able to get a job as a Java programmer.

Jay Elston