Why does Java / C # exclude C ++ as the recommended language for learning OOP?

I noticed after reading the answers / discussion on this question (What is the best language for learning OOP?) - that more and more people recommend C # or Java over C ++ to learn OOP. A simple search query on this answer page yields 10 reverse results for C ++, 21 for C # and 27 for Java.

Now I understand that these 2 languages ​​fix a lot of quirks and problems with C ++, and looked at these , which are mainly related to performance, JVM and embedded implementation, focus systems and applications, manual memory management and automatic, etc.

My question is: are there fundamental differences in the features of OO Java / C # vs C ++? Or are the former recommended solely because of their general ease of use / improvement over the latter?

Thanks.

PS, I know about Java interface inheritance and C ++ multiple inheritance as a difference. I would think that implementation, not functional.


Wow, I did not expect such answers! Many thanks. Here I will talk about what I learned.

+4
source share
13 answers

Java is a higher level language than C ++. This abstracts you much more from the car, and it is great for learning. You DO NOT want students to encounter pointer problems, overflows, garbage collection, etc., Studying OOP concepts, since they are an orthogonal problem for OOP and distract students from the basic concept of OOP itself.

I have no experience using C #, so I can't talk much about it.

+13
source

C ++ does not make you program in OOP style, while Java does much more. If you want to learn how to program in an object-oriented way, it helps if the language pushes you in that direction.

+4
source

I can only speak for myself, but for learning OOP, I would recommend C # or Java over C ++, because C ++ is not an OOP language.

C ++ allows you to mix many styles, including several bits and fragments of OOP. But any robust C ++ code I've seen is not primarily OOP.

C # and Java are all about OOP. If your code does not comply with OOP rules, you are doing it wrong.

Another reason is almost obvious:
C ++ is a pain to learn. It is very subtle and difficult to do correctly. And if you mess up, you most likely won’t get a good compiler error or an exception that occurred at runtime. Most likely, your program will simply jump off the rails and do strange unpredictable things. Maybe the crash, maybe it seems to work, maybe it just seems like it is wrong. Or often seem to work, and then crash somewhere completely different after 5 minutes.

C # and Java pretty much eliminate undefined behavior. If you are doing something that is not permitted by the language, the error is caught anyway. This simplifies a lot, especially for beginners.

+4
source

You started asking, "Why are C # and Java recommended more?" This was a really good question with some potentially unexpected answers.

But then you asked, in essence, "What makes C # and Java better?" What more than anything shows, you had to wait to hear some answers to the first.

Well, one of the possible reasons for the predominance of C # and Java recommendations is that they are actually best suited for OOP. Better than C ++. Better than Haskell. Better than Smalltalk. This is probably not the right reason.

It is much more likely that people recommend what they know. This suggests that the best follow-up question is: "Why are more people doing object-oriented programming in C # and Java than in C ++?" Now that is a good question, I can only give a few answers.

The biggest answer: "Because that's what most universities teach." But that begs the question. "Why do universities learn C # and Java?" Two big factors.

Professors prefer Java and C # because the theoretical foundation is much simpler than C ++. The languages ​​themselves have much more interesting theoretical properties that simplify the proofs. Text input systems are much simpler, which leaves room for expansion, because if we add these markers to a system such as Java (for example, taint indicators based on user-provided data), we can write a little proof of the preliminary concept compiler and publish some scientific articles on our the new flavor of Java. With C ++, making your own taste is not so attractive. Partly because C ++ is already so flexible, and partly because the prototype parser / type color thingamajig is now REALLY tough because it needs to handle C ++ syntax.

Universities also love Java and C # because they attract students. Students go for what looks best on their resume. What works best in a resume depends on the advertising that bounty hunters swallow from well-known companies like, you guessed it, Sun, Microsoft, and Novell.

Then Java and C # are much easier to learn than C ++. It is not necessarily easier to do any specific work, although standard libraries, a garbage collector, and code refactoring tools (back to the difficulties of C ++ parsing) certainly help. But C ++ has much more features than Java or C #, that the number of true masters is much less, both in absolute numbers and in percent.

And, C ++ wizards are less inclined to either program OO or simply offer their own language for learning OOP, as they have so many paradigms. Instead, they will ask: "Why do you study OOP when generic programming is so powerful?"

So, you have half a dozen countercultural reasons for the popularity of C # and Java as an answer to the question "Which language is best to learn OOP?" which cannot be generalized as "they are better that all."

+4
source

One of the main advantages of C # and Java over C ++ when using it for OOP training is that the student does not need to worry about garbage collection problems , since garbage collection is automatic and is implied in both C # and Java.

+3
source

One of the great things you get with Java or C # over C ++ is the large standard environment.

Do you want to make network interaction? It's within the framework, in C ++ you need to roll your own or study, install and integrate some other frameworks that others may not necessarily use.

The same goes for any number of other feature sets.

Of course, C ++ has Boost, but as a rule, much lower level than you, you are baked into the Java or .NET infrastructure.

+3
source

Java / C # are almost pure OO languages. This means that they are mainly designed to implement programs exclusively using the OO methodology.

C ++ is a language with several paradigms and does not have a preferred methodology. You can implement OO using C ++, but there are significant deployment problems with this. This is due to the fact that there is no C ++ VM. The VM makes OO pretty much practical, as it can handle builds, runtime introspection, etc., which are needed to deploy OO modules. There were attempts to wrap C ++ in this way (COM, CORBA, SOM), but they did not work so well.

However, for academic purposes, I believe that the mechanism of virtual inheritance is how to teach OO. C ++ is one of the few languages ​​that allows multiple inheritance of cooperatives. And also the only one that correctly implements exceptions, i.e. In combination with a destructor.

So, if you only want to implement OO, then stick with Java / C #. If you want to implement OO and mix expression templates, DESL, political design, kernel hacks, assembler and the interface directly with FORTRAN binaries through shared memory, then select C ++.

+3
source

Because they are safe languages, and you do not need to worry about buffer overflows, memory leaks, causing undefined behavior, etc. Thus, you can focus on learning OOP and not worry about shooting yourself in the foot.

+2
source

Are there any fundamental differences in OO features for Java / C # vs C ++?

Yes. Generics, Properties, Events, etc. You mentioned yourself about yourself.

C # is probably the best language to learn, since properties provide a much clearer idea of ​​what encapsulation is and are much less confusing than methods for the same.

The question is, how do you define OOP. It can be argued that the events are related (I think the observer pattern), and therefore it is easy to handle events in Java and C # (especially C #) - this is the difference.

And then C ++ just sucks when it comes to OOP. I mean the header files? Please, this is 2010, they should already be generated!

Edit: also that Java and C # use Exceptions for everything, this is a big plus. The C ++ exception model is not that big.

+2
source

C # and Java are preferred for ease of use.

Are there fundamental differences? Not. You get all the basics of OO.

There are several differences, as you know, but not enough to treat Java or C # as "incomplete" OO languages.

+1
source

People recommend these languages ​​to learn, because C ++ is more about do-it-yourself-y, a trait that usually causes inconvenience to beginners. Java and C # manage many things for the programmer, while still providing reasonable language features for their specific problem areas. When a person is comfortable with the concepts of programming, the language is practically irrelevant, with the possible exception of a clearer solution to a specific problem. Therefore, for beginners, it makes more sense to learn languages ​​that they can easily understand and from which they can build their knowledge.

+1
source

You ignore the elephant in the room.

Answer # 1 (and # 4, and # 7, and # 9 and ...) to the question you linked says Java / C # to work, but Smalltalk / Self to really learn OOP and all its comments seem to be agree with the Smalltalk recommendation.

From this point of view, the answer is simple: C # and Java are much closer to Smalltalk than C ++.

+1
source

Although I think that almost every reason for learning OOP using C # or Java has been considered here (pro and con):

I also consider the main reason (and this is due to Ben Voigt commenting on his belief that Java and C # are languages ​​taught in computer science classes) - this is “size and momentum”: knowing that you have such resources like StackOverFlow and CodeProject, and a critical mass of programmers, some of whom will always “push the envelope” to explain how to use the latest “goodies” in this language ... is of great importance.

... as an example of “envelope pushers”: I think of WPF students, for example, “excellent FrameWork / DI / IOC software” and those discussions that were as mysterious to them as English cricket ...

Note. I would like to get statistics on the extent to which C # or Java are used in college graduate courses in the US and Europe: I think it can be very interesting. I would interpret Ben's comment as a very likely hypothesis, but still a hypothesis.

Interestingly, no one here proposed Objective-C as it was found on a Mac to teach OOP (acting as a fully programmed former member of Mac Cult).

I would also notice that many times when people talk about OOP, they say: not about OO design; not “design patterns”, but it’s about programming with built-in system objects, from utility libraries to GUI stuff, and often talks about the quirks and anomalies of their work in specific conditions in specific environments.

Anyone who has sweated with standard WinForms controls (ListView, TreeView, ComboBox, etc.) for several years has, imho, "learned a lot" about inconsistencies in the design of objects: from the "glass" is half full perspective, " however, is it possible that third-party software companies are thriving and innovating with ENABLES? This certainly prompted me to buy a third party toolkit that has a lot more “design consistency and integrity.”

In short: I would say that the best resources for learning OOP are a few few language books (for example, for C #, Skeet's masterpiece, "C # in Depth"). Which book would you recommend for Java-OOP? Hopefully, at best, using your key book (s) in the context of a course or mentoring. And then StackOverFlow and CodeProject come into play as fantastic resources that will help you in your own continuation of self-education.

Comment: in the study of music, you have the concept of "studies", which not only helps you (and makes you) master new techniques and musical concepts, but is also immediately useful (in the aesthetic sense in music: that is, please the ear).

imho "great book" in C # "Design Templates", using the idea of ​​a set of graduated progressive exercises, as in musical studies, and making full use of the evolution of the language in FrameWorks 3-4, is waiting to be written ... John Skeet or Eric Lippert, but I would be just as happy if he had Jesse Liberty or Matthew MacDonald, or Richter, or Troelsen, or Sells.

It would be valuable to single out two types of “educational goals” here: to develop competent programmers whose area of ​​expertise is platform-specific (for example, Mac, PC, Linux): and “computer scientists” come out who are able to analyze problems using a number of abstraction methods, which are oriented to algorithms and, perhaps, secondly, to the choice of which full-fledged equivalent Turing language is best suited for implementing a particular algorithm?

Or is there another "role" here of the "application model architect" that dreams in UML and works at the level of abstraction far beyond the scope of "simple coding" :)?

Meanwhile, fossils, like this writer, will continue to tinker with what they call "dinosaur dentistry," using the equivalent of duct tape and crazy glue so that archaic levels of outdated software (often from competing vendors) work together, kind of.

+1
source

Source: https://habr.com/ru/post/1306189/


All Articles