The best learning route into Object Oriented Programming from C? [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this questionWhat 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 Meyer's 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.
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.
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.
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.
Objective-C
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.
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.
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.
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.
I would say Java. A good book that helped me is this one.
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).
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:
- What’s wrong with C++ compared to other languages?
- What are the differences between C, C# and C++ in terms of real-world application
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.
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.
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.
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.
forget about the tools or the past (C++, oop,C##,learning, thinking , trying). lets encourage creativity and momentum. Fresh approaches lets crash into the future.
What I love about technology is that it is only starting, Like art or Maths
I believe that lazy thick dyslexics (who cant be bothered to pretend to be smart) are the next step in evolution ;), the step after that will be the artificial brain. At that point we will all live forever and just enjoy ourselves :)
like a designer who looks at a design in real life to gain inspiration (A kettle, a door, A Lift or a building) I look at abstractions in real life to gain inspiration (or where there missing), A banks Risk systems (The Multi dimensional topology of flows and rules) or a spread sheet (cells, rows and columns) The simplicity increases visualness and abstractnesses (What do cells rows and columns have to do finance) is excessively agile, How quickly could you change a set of rules in a spreadsheet vs software so The visualness works with the human Brain while the simple abstractivity also help the brain understand the domain. Working with a complex and sophisticated system becomes the job for a lazy Thicko (me)
I look to include these same benefits in My APIs
Best Of Luck and God Bless
精彩评论