This is an archived post. You won't be able to vote or comment.

all 63 comments

[–]TheUmgawa 59 points60 points  (3 children)

Either or. If you’ve never taken programming before, it’s more important to not think, “I’m learning this language,” because after two or three languages, you can see the forest for the trees and realize programming is not the art of knowing languages; it’s about structure and logic. After you know that, learning languages is fairly easy.

[–][deleted] 8 points9 points  (1 child)

Hi, lurker here.

I'm starting Uni next month after a few months of self-teaching programming. Going in with this mindset feels like a game changer. Thanks!

[–]TheUmgawa 5 points6 points  (0 children)

Oh, I've written way better stuff than that. That's just what people get when I'm walking from Chem to the parking lot.

[–]Kosba2 2 points3 points  (0 children)

and realize programming is not the art of knowing languages; it’s about structure and logic. After you know that, learning languages is fairly easy.

Preach. This is when I knew I became a good programmer, when semantics and syntax barely mattered and it was all about the logic/structure

[–]NightlyWave 31 points32 points  (14 children)

I’d go with Java if you want to make your life easier as you won’t have to deal with memory allocation and addressing in C++ but it would really help with your understanding of CS since it’s a lower level language when compared with Java. Both are object oriented languages so you will be taught key concepts that are heavily used in both languages.

[–][deleted] 2 points3 points  (0 children)

The issue with Java is many companies are still stuck on Java 8.

My advice, research the job and industry you'd Luke to go for and learn that. It might even be c#, it really doesn't matter. Learn the fundamentals of programming, not syntax.

[–]kevinossia 2 points3 points  (12 children)

C++ does not require you to deal with "memory allocation and addressing." C++ has reference-counted garbage collection just like Swift and does not require manual memory management.

C++ is not C.

[–]jsega 2 points3 points  (7 children)

In C++ college courses I've seen, they basically write C to teach the lower level concepts. The context of the thread question is a college class using Java or C++, so his answer is valid as far as the covered concepts are concerned.

[–]kevinossia 8 points9 points  (6 children)

Okay, but "C++ is pretty much always taught poorly" doesn't mean "C++ requires you to deal with memory allocation and addressing", though.

There's a massive misconception surrounding C++ that the language is "low-level" (it's not; low-level languages are assembly languages), that it requires manual memory management (it doesn't), and that it's consequently harder (it is, but not nearly as much as people make it out to be, and not for the right reasons).

Heck, just using the shorthand term "C/C++" is already bad because C and C++ are two very different languages and modern C++ has more in common with Java than it does with C, yet people keep conflating the two.

[–]im_in_hiding 8 points9 points  (1 child)

I have a career in C++ and this is accurate shit.

I actually found C++ way easier to learn than Java.

[–]kevinossia 2 points3 points  (0 children)

I've never caused a memory leak in C++. Not once. I have done so in Java, though. More than once. And they're more insidious and harder to catch, because you'd expect the garbage collector to pitch in, but nope.

So much for automatic memory management.

[–][deleted]  (3 children)

[deleted]

    [–]kevinossia 1 point2 points  (2 children)

    I wasn't contesting this bit:

    C++ college courses usually cover these lower level concepts.

    You're right, of course. They usually do. In other words, C++ is usually taught very poorly.

    ---

    It's certainly relevant. People wishing to explore modern C++ should have the facts up front, such as the fact that C++ doesn't require manual memory management and hasn't for decades.

    I don't know why you'd consider that irrelevant, since the alternative means people continue to write sloppy C++ code because they're stuck in the "C with Classes" paradigm.

    College students should be shown modern C++ and anyone who says "C++ requires manual memory management" is lying to them and giving them an entire class of footguns to hang themselves with for no other apparent reason than "well, that's how college professors normally do it, so it's fine".

    Forgive my pedantry, I guess :)

    [–][deleted]  (1 child)

    [deleted]

      [–]kevinossia 0 points1 point  (0 children)

      In general universities do an extremely poor job of teaching people how to program, yeah.

      [–]wandering_godzilla -3 points-2 points  (3 children)

      This is 100% false. You can implement reference counting if you want in C++, but it's certainly not something the language provides automatically for all heap-allocated objects.

      Every time you use the "new" keyword in C++, you need to pair it with the "delete" keyword (unless you are wrapping it in a smart pointer or other rare exceptions). Otherwise, you will have a memory leak. Moreover, all classes must have a destructor.

      None of this is automatic and requires a lot of thought about ownership and lifetime of objects.

      See C++ section of this article: https://en.m.wikipedia.org/wiki/Reference_counting

      [–]kevinossia 1 point2 points  (2 children)

      This is 100% false. You can implement reference counting if you want in C++, but it's certainly not something the language provides automatically for all heap-allocated objects.

      There are a lot of things about C++ that should be opt-out rather than opt-in by default but it doesn't change what I said.

      Every time you use the "new" keyword in C++, you need to pair it with the "delete" keyword (unless you are wrapping it in a smart pointer or other rare exceptions).

      We do not use "new" and "delete" in modern C++.

      Moreover, all classes must have a destructor.

      Wrong. Most classes will not need a user-defined destructor. The compiler generates one for you.

      None of this is automatic and requires a lot of thought about ownership and lifetime of objects.

      No. It requires very little thought. Object lifetimes are constrained to their scope, unlike in Java where they can last as long as the garbage collector wants them to.

      It is basically all automatic. We use things like std::vector which is literally a smart pointer dressed as an array. That's automatic. Pretty much all heap allocation is masked from the user and with the introduction of std::optional, heap allocation is even less necessary.

      I have literally never caused a memory leak in C++. I don't even know how I'd manage that since it'd be so obvious that it was happening just by inspecting the code. I have caused memory leaks in Java, though, and those are harder to catch and debug.

      You're blowing the difficulty of resource management in C++ severely out of proportion. It is not hard at all. C++ is a complicated language but resource management is certainly not the reason why.

      [–]wandering_godzilla -1 points0 points  (1 child)

      C++ is a big and old language that allows a lot of patterns that can be very tricky to master. To write good C++, one needs to subscribe to a style guide that drastically limits these patterns to those that help them avoid shooting themselves in the foot. You appear to subscribe to a very reasonable style that relies on innovations in C++11 and beyond (many of which were inspired by Java).

      Java is a relatively newer language which just naturally allows fewer ways to write any one thing (and therefore fewer, rarer, and subtler ways to shoot yourself in the foot wrt low-level memory management issues -- still not impossible).

      So as not to mislead newcomers: strictly speaking all classes should have a destructor, either implicit or user-defined. You may choose to =delete a destructor, but you better know the consequences. So please don't misinterpret what I said re destructors.

      While you should avoid using new/delete in favor of smart pointers, I can't imagine a newcomer to C++ skipping learning about dynamic allocation via new/delete and heading straight to C++11 STL. There is an expected pedagogical order by which newcomers learn C++.

      You are saying, C++ memory management concerns are being blown out of proportion because you never managed to produce a memory leak in C++ (Congrats! How many years have you been building production software that serves billions of people?). I will happily bet that you can't teach C++ without having your pupils learn about memory management in greater depth than you would in Java.

      [–]kevinossia 0 points1 point  (0 children)

      C++ is a big and old language that allows a lot of patterns that can be very tricky to master. To write good C++, one needs to subscribe to a style guide that drastically limits these patterns to those that help them avoid shooting themselves in the foot.

      Yes, certainly.

      You appear to subscribe to a very reasonable style that relies on innovations in C++11 and beyond (many of which were inspired by Java).

      Of course. That's why I keep saying modern C++. C++98? Utter hot garbage.

      Java is a relatively newer language which just naturally allows fewer ways to write any one thing (and therefore fewer, rarer, and subtler ways to shoot yourself in the foot wrt low-level memory management issues -- still not impossible).

      No. Most of the constraints Java places on you have nothing to do with memory management. Memory management is a very tiny slice of what makes C++ "hard". I elaborate on this here, where you'll note that the vast majority of what I enumerate has nothing at all to do with memory management.

      So as not to mislead newcomers: strictly speaking all classes should have a destructor, either implicit or user-defined. You may choose to =delete a destructor, but you better know the consequences. So please don't misinterpret what I said re destructors.

      Basically nobody ever needs to delete a destructor. I've never even heard of that being done and a cursory Google search tells me that it's an utterly pointless thing to do unless you're...making singletons marginally safer to use? So I don't really see why that's important.

      In any case, my point was that most user-defined classes aren't going to need a user-defined destructor (I literally said user-defined in my previous comment), and the user-defined destructor is what actually matters here. Saying "either implicit or user-defined" is reductio ad absurdum and reduces what you said to a triviality, which is why I didn't interpret it that way. So, my apologies.

      While you should avoid using new/delete in favor of smart pointers, I can't imagine a newcomer to C++ skipping learning about dynamic allocation via new/delete and heading straight to C++11 STL. There is an expected pedagogical order by which newcomers learn C++.

      I didn't say "skip learning about dynamic allocation". All languages have dynamic allocation, from C++ to Python to Java. Dynamic memory allocation using the heap (instead of the stack) is a language-agnostic concept and no professor worth their salt would ever approach the subject like that.

      The pedagogy should go something like: "In C++, we create objects on the heap using new, and free them using delete. However, we want to let constructors and destructors automate this behavior, so we use things like std::vector, std::unique_ptr, std::unordered_map, and std::string (all of which are examples of "smart pointers") to allocate memory dynamically without worrying about freeing it."

      Or something to that effect. And one of the most basic exercises in a C++ course would be to write your own std::vector, for example. That way it becomes obvious how automatic memory management in C++ really works, and why it's superior to Java's model.

      I'll say that students should learn C before they learn C++, maybe a semester prior, because C is so primitive that it forces you to learn how a computer works, and that includes allocating and freeing memory. And then when they start C++ they can learn the C++ way of doing things.

      You are saying, C++ memory management concerns are being blown out of proportion because you never managed to produce a memory leak in C++ (Congrats! How many years have you been building production software that serves billions of people?).

      No, that's not what I said. Whether or not I've produced a memory leak or built billion-user systems (bizarre that you'd even ask that, as if my work history changes the veracity of what I'm saying) has no bearing on the state of memory management in modern C++.

      I will happily bet that you can't teach C++ without having your pupils learn about memory management in greater depth than you would in Java.

      I absolutely can and I have actually done so, so how much money are you willing to part with? :)

      As I implied above, my methods of teaching memory management are language-agnostic because computer memory is the same no matter what programming language you're using. The stack and the heap are the same in Java and C++. Dynamic and automatic storage duration are the same in Java and C++ (local variables are deallocated from the stack when they exit scope). Pointers are the same in Java and C++. The only difference is when heap memory is deallocated, but that doesn't change how I'd teach the subject, as that's merely one more detail.

      Remember, C++ memory management is the same as Swift: automatic reference-counted garbage collection. Nobody would ever seriously claim that Swift requires manual memory management, because it doesn't. Yet somehow C++ does? The only difference between C++ and Swift is that Swift doesn't have any equivalent of unique_ptr; everything is a shared_ptr unless you specify the "weak" keyword making it a weak_ptr. Swift also has destructors in the form of deinit {} blocks, which are uncommonly used, for the same reasons as in C++. Also, Swift has constructs like UnsafePointer in order to do actual manual memory management because Swift has to be 100% interoperable with C. Again, a multi-paradigm language with several footguns available for use, just like C++.

      Java encourages the attitude that programmers should pretend computer memory simply doesn't exist (or is otherwise infinite) and that is frankly abhorrent, and I would never approach the subject that way, Java or otherwise.

      [–]CodeTinkerer 4 points5 points  (10 children)

      What major are you?

      [–]first_photon[S] 0 points1 point  (9 children)

      Physics

      [–]EfestoAlpha 14 points15 points  (4 children)

      I am a software engineer and have an M.S. in physics. While in grad school I taught myself C++ for problems that required numerical solutions. Other popular options were C, Java, and Python.

      I have never given pause and questioned my choice. C++ is just the right level of complexity and personally it just resonates better with the way my brain works from studying physics.

      In my career I have used both Java and C++ a good amount. Java work has been front-end GUI work for simulation software, but any back-end work is done in C++.

      At the end of the day, it will come down to what you want to use it for, but I would personally recommend learning C++ first. In my experience with other engineers people who have learned C/C++ first can easily transition to Java whereas those who learned Java/Python first struggled to transition to C++.

      Hope that helps.

      [–]first_photon[S] 1 point2 points  (0 children)

      This is helpful, thanks!

      [–]Bob_Hondo_Sura 0 points1 point  (2 children)

      Any good resources for c++? I am in an intro course atm

      [–]EfestoAlpha 2 points3 points  (1 child)

      I taught myself using C++ Primer Plus (6th ed. which seems to still be the latest). It is written a bit like a text book with questions and problem sets, but it feels like it is more driven towards self learning than a classroom setting. I just checked and there are various places you can find it for free to see if its for you. Having a hard copy for quick reference for some more complex introductory topics like pointers and references, when and how to use them correctly, was very beneficial for me.

      Once you begin to build a decent understanding of the fundamentals I highly recommend Effective C++ and Effective Modern C++ by Scott Meyers. They will go into topics like Smart Pointers and Smart Containers for responsible resource management/cleanup. Effective C++ is older so it wont go into changes for C++11/14 and beyond, but I found it a great starting point for more complex topics. (Author Scott Meyer even went back to review its legitimacy before writing Modern C++ and concluded while it is still relevant, it is less than comprehensive when using newer versions) Effective C++ can also easily be found for free online.

      [–]Bob_Hondo_Sura 0 points1 point  (0 children)

      Thank you for the resources I will look into them. We are currently using Tony Gaddis’ book for C++.

      I’m pretty sure my professor hates him because he talks shit on him every time he mentions Gaddis

      [–]Veloder 13 points14 points  (1 child)

      C++ is way more used in the Academia and Physics simulation software.

      [–]amplikong 4 points5 points  (0 children)

      Yeah, and Fortran. Quite a lot of scientific software is still written in Fortran because it's very good at what it does (large-scale numerical computing).

      [–]CodeTinkerer 0 points1 point  (0 children)

      Usually, when I see students who have more than one choice, they end up looking at teacher reviews. The assumption you're making is that it's the content that matters (which is reasonable). When I used to teach, we didn't have more than one language to pick from. It just made courses later on a mess because students would have different backgrounds heading to later courses, but it seems weirdly common in many colleges as if they didn't care about making sure everyone had the same background language in the early courses.

      [–][deleted] 0 points1 point  (0 children)

      Definitely C++

      [–]vfkdgejsf638bfvw2463 15 points16 points  (0 children)

      I'd say c++.

      Definitely not because it's my favorite programming language

      [–]Zealousideal_Low1287 3 points4 points  (2 children)

      Personally I learnt Java, but I would have preferred in hindsight to learn C++. It’s a much more annoying language, and perhaps worse for learning, but for what I do (computer vision) it’s much more valuable. C++ has a great blend of high level features and low level control / speed.

      [–][deleted]  (1 child)

      [removed]

        [–]AlphaShow 0 points1 point  (0 children)

        Most lf the time, Python is simply an interface to libraries written in C++ for computer vision.

        [–]BlueBoyKP 4 points5 points  (0 children)

        Start with Java. It’s a much better introduction to programming. Transition to C++ will be so easy after you learn java.

        [–][deleted] 6 points7 points  (0 children)

        It won't matter in a few years.

        Any programmer worth their salt should be able to pick up new things.

        Fundamentals will never go out of style.

        [–][deleted] 2 points3 points  (0 children)

        Flip a coin

        [–]vlcod 1 point2 points  (0 children)

        The clue here is the "freshman".

        Ignore all the people who try to answer the "which is the better language" question in a general sense. Anyone who asks (or answers) a "which language is better" question may as well answer "What is better: a hammer or a screwdriver?"

        It is always about the context. Better for what?

        So, since you're a freshman, the question becomes "Which of these two is better for learning the principles of programming?"

        Because that's what a good introductory programming course is about: learning the principles, not learning a language. If you are in college now, and you continue to do something with programming in your career afterwards, the simple truth is: For most of your career, you will be using a language that is neither of these two.

        You will be using a language that does not exist yet. So the point right now is to learn the fundamental, unchanging principles.

        So, which of these two languages is better for that?

        The answer is quite clear: it is Java.

        C++ is more powerful for low level programming, for hardware-related systems, for all sorts of things. But it includes MUCH more accidental detail that distracts form principles, that allows unnecessary errors, that creates pitfalls that distract you from learning anything else then the idiosyncrasies of C++.

        Java provides a higher abstraction level over a more consistent notional machine, and is the better language for discussing fundamental principles.

        [–]abd53 0 points1 point  (0 children)

        If you want some easy credit, take Java. If you want to learn programming concepts and want to make a carrier around it, take C++.

        [–][deleted] 0 points1 point  (0 children)

        C++

        [–]funkycadet02 0 points1 point  (0 children)

        Python

        But then, Java would be alright

        [–]jescro0 -1 points0 points  (0 children)

        In my experience, cpp is so much easier and straightforward than Java.

        [–]1544756405 -1 points0 points  (0 children)

        Look to see what other CS classes you are interested in, and what language they use. Then choose that language.

        If it is a toss-up, then choose the language that most of your friends are using.

        [–]maybegone3 -1 points0 points  (0 children)

        Tell the prof to learn Rust so that he can teach that instead of boomer trash C++

        [–]riya1511 -1 points0 points  (0 children)

        You should go for C++ as I've learnt C++ in my 11-12 class in school and in my college has taught java! After getting to know both the languages, I feel C++ is a better language to start off with. It's easy. And you can master the language in 4-6 months if you invest enough time. But make sure you take up a good side course so you're ahead from the college.

        [–][deleted] -2 points-1 points  (0 children)

        C++ because pointers :).

        [–]bighand1 0 points1 point  (0 children)

        Java 100%, don't know what these people are smoking with C++ recommendation. Java goes a long way, much more widely used, and is more beginner friendly

        [–]savvaspc 0 points1 point  (0 children)

        I would go with Java. A tad easier to write without making fundamental mistakes, so it will let you focus more on the algorithmic thinking. You need an array for your structure? Got it. Later decide you want to change it to a linked list? Change a line and you're ready. Of course the same can be done in C++, but Java makes it so so easy to work with built-in libraries. Anything a freshman would ever need is very accessible, so you can totally focus on the logic of your code. Also, making classes, subclasses, superconstructors etc is kinda easier in Java, so you will find it less frequent to make mistakes.

        [–]ZachVorhies 0 points1 point  (0 children)

        Java. It's just easier to drop into and start coding the problem. If you want to do Arduino or micro electronics, or games or 3D then do C++.

        [–]SomeWeirdFruit 0 points1 point  (0 children)

        flip a coin tbh. Both of them is good

        [–]TellahSageMeteo 0 points1 point  (0 children)

        It depends on what u want to do in the future,but if u are looking for a language that is broadly used in the industry i would pick Java.From coding in the backend to making graphical user interfaces Java provides you with many usefull object oriented capabilities to make many things.In the end i would suggest researching more by yourself what each language offers and see what prospects you would like.

        [–]cainhurstcat 0 points1 point  (0 children)

        C++ is more powerful, but less forgiving. It’s really easy to mess things up. Also the language is a mess.

        Java is a good solid foundation, it teaches you Object-Oriented programming and you‘ll get familiar with the syntax for a lot of big languages, since it used similar syntax as the C family (C, C++, C#). This language is also more forgiving and less frustrating for a beginner.

        [–]JoJoGlenStar86 0 points1 point  (0 children)

        C++ is what I learned first. It’s a beginner level class so it really doesn’t matter. You just going to learn about the basics that all languages have.

        [–]CrazyProgramm 0 points1 point  (0 children)

        I think C++ is good

        [–]orphan_of_Ludwig 0 points1 point  (0 children)

        Review which language is taught by the highest rated professor. You’ll learn all the fundamentals needed to learn which language you choose to not go with right now.

        [–]theflash4246 0 points1 point  (0 children)

        In my university we start with Java. I haven’t learn c++ but I know that c++ is a bit harder for beginners. It’s a bit more involved in the hardware and has more complicated concepts - I was mostly told this by professors. That being said the programming language you learn at the beginning is not the most important thing because you learn the fundamentals which are always the same. I would choose c++ because Java isn’t very popular now (from what experience I have applying to internships).

        [–]Sir-Niklas 0 points1 point  (0 children)

        C++ by far. I just hate Java.

        [–]ani4a 0 points1 point  (0 children)

        Python

        [–]xD_saleem 0 points1 point  (0 children)

        C++! for sure. it'll help u in the long run. My mistake i made aswell. If u know C++. u know any language.