Hacker News new | past | comments | ask | show | jobs | submit login
Should I learn C++ or Python? (secretsofconsulting.blogspot.com)
43 points by discombobulate on Feb 14, 2017 | hide | past | favorite | 64 comments



Learn a language you can immediately do something fun with. If you're excited about desktop 3D video games, pick up C++ and, say, the Unreal Engine.

If you're excited about web servers, pick up Ruby/Rails - or if you think you might want to create a client side application, pick up Javascript and some framework like Angular or React and build something that you can deploy as soon as possible.

If you're into Machine Learning, pick up Python and start going through ML tutorials and jupyter notebooks while attempting to solve some problem in ML that you find interesting.

Don't pick a language based upon some esoteric development principle that undergirds it. Pick a first language based upon its ability to keep you banging away at the keyboard all night, doing something you think is cool.


This is the correct answer to that and every other "what tool should I learn" question. I'll add my two cents be expanding this answer a bit.

As crusso basically stated, the answer is actually twofold because you have to:

#1 Choose a problem that is fun to solve. #2 Learn the language that is the best suited to solve that problem.

Regarding #1 up there, the reason you choose something fun to solve is because programming is hard. But, if you are having fun, the enjoyment of solving will keep you motivated through the tough times. You'll find solutions, push through and level up.

Its the same reason you should pick a career you enjoy.


> if you are having fun, the enjoyment of solving will keep you motivated through the tough times. You'll find solutions, push through and level up.

You hit the nail on the head.


I always make the woodworking analogy. You don't hear people say "I'm a huge router fan." "I'm a tack hammer kind of gal." "I was born a radial arm saw user and I'll die one!"

Maybe you want to make cabinets, or houses, or decks. Pick the tools that help you make what you want to make.


To take an example, Java can be used for a great many things. It's nowhere near as specialized as a tack hammer. So this isn't as easy a decision as you are making out.


Technically, you should learn the most general tools first. Java is not one, it is designed to be explicitly limited.

Both Python and C++ are general albeit Python had a major disadvantage in performance while C++ in clarity. (That said, more modern versions of both have the disadvantages reduced.)


How is Java "designed to be explicitly limited"? It's a general purpose programming language with a huge number of libraries available.


It's really not that hard. First decide what kind of stuff you want to do, find some people currently doing it, use whatever tools they're using.


> If you're excited about desktop 3D video games, pick up C++ and, say, the Unreal Engine.

Or get Unity and learn their built-in scripting language. No need to spend years learning C++, OpenGL, etc. if you're not planning on being the next Carmack.


Even better. Many people start learning C# with Unity and can move on to other things from there if they wish to.


I think Unity's scripting options are C# and Javascript.


> If you're excited about web servers, pick up Ruby/Rails

Yes. After much reflection, I decided that I'm at the "fuck it, I'll use Rails" point for new projects. It's easy, batteries-included, and (mostly) fun.


Is it outdated though? I've been focused on using node/express and it straight forward and all JavaScript. But I have heard you can learn good practice from rails. Should I spend time learning rub/rails?


For five years Node has been excellently positioned to defeat Ruby on Rails as the goto framework of choice, but due to the community's fragmentation I still don't believe there is a web framework in the node ecosystem that is even close to being as complete, as handy, and as rapid for development as Ruby on Rails still is.

But I'm willing to stand corrected, because Node holds the capability to revolutionize writing single page web apps (SPA) the way rails did for database-backed server-side apps ten years ago.

(I.e. is there a Node SPA equivalent that can automagically build with a one line scaffold command what Rails did for CRUD?)


To throw a curve ball ... I actually use Elixir/Phoenix for all my new web projects. It's new, a bit Ruby/Railsish, functional, high performance. Combine it with Elm on the front end and you have a lot of power as well as programming tool goodness.


Can I scaffold CRUD together in Phoenix like I can in rails? How much "rougher" do you find the ecosystem and general process of writing apps?


Python can be used to make games as well. As well as any other language.

https://github.com/libgdx/libgdx/wiki/Using-libgdx-with-Pyth...

Here's a screenshot of something I prototyped. http://pasteboard.co/y6bxRPA3e.png


> "Should I learn saws or screwdrivers?"

The answer to this question is unequivocally "screwdrivers". The answer to the original question (if you find yourself asking it), is "Python."

The analogy is perfect for this situation, but the answer provided here is wrong.

The original question [1] is unqualified, so I will take a liberty or two here and assume that they're new to programming and want to learn more. And since there's no real dichotomy here, I'll infer they're really asking "should I learn C++ or Python [first]?"

Well, C++ is indeed a saw and while they're incredibly capable, injuries are included for free. Python, like a screwdriver offers maximum utility. Learn Python first.

> Do you think someone could be a top-flight carpenter knowing only one?

Who cares about being a top-flight carpenter? Just figure out how to open up the battery pack for your kids' toys and you will be a hero. Whether you're starting a career in CS or you just want to cleanup the data in the office's mega-spreadsheet-that-has-all-our-critical-info, start with Python. Get that productivity that enables a positive feedback loop of design/test.

I started with C/C++ before Python existed and it was just so easy to get stuck on several classes of failures that were difficult to understand without outside help. Python has some of those but IMO far fewer.

[1] https://www.quora.com/Should-I-learn-C++-or-Python


I would actually disagree if you're learning programming. C++ will teach you far more. Python, for all it's advantages, is C++, with all sorts of restrictions imposed on what you can do (e.g. shared_ptr for everything, with the pros and cons of that).

It'll be hard for a while, but you will have learned a lot when you get there.

Python is what everyone's switching to because it's easier. If that's your goal, just build stuff and don't care about how it works, then sure, go python. And I would encourage you to learn Python (and Java, and Go, and Haskell, and Prolog, ...) to get more tools in the toolbox eventually.


At many Universities and Colleges, Python is taken as their first programming course. Then for the second and/or third course you study Java and/or C++.


The Java course is a waste of time, the language does not bring anything new against Python when compared to C++.

Only a few Java specific things and an emphasis on patterns and workarounds for things you cannot do directly because the language is so limited.

Java is a decent first choice, but not a second one.


> "Should I learn saws or screwdrivers?"

I think when we talk about languages we talk about 2 different things. Some people talk about syntax and some about paradigms. Computer languages and some claim human ones too (see https://en.wikipedia.org/wiki/Linguistic_relativity) shape how we think about problems. They are not simply tools. Languages withing the same paradigm can probably be interchanged as tools. I programmed in C++, Java, Python and C#. I can switch between them effectively after a few weeks of remembering "how things are different", well ok maybe not C++... But I cannot switch easily to logic programming like that though. Even if it had a C like syntax instead of Prolog or LISP, because it requires a different way of thinking.

One you learn a paradigm you start solving problems differently and potentially a lot more efficiently, (Well and some less efficiently too). And also it may be hard to switch to another paradigm, because once everything is an object, and you keep state there, switching to functional language can be trickier than just starting with functional to begin with.


A craftsmen is never disserviced from having multiple tools in their toolbox and mastery of them all. With experience comes the wisdom and intuition of knowing which tool is appropriate for the problem at hand. Whether it matters how quickly you need to deliver or what level of performance is needed. Inevitably in any engineering problem, there are always multiple solutions, but having appropriate information to make a qualified judgement to provide a sufficient solution as cheaply as possible (often, in software, this may be qualified in terms of time to market) that meets stated requirements (functional requirements, performance - i.e. load, latency & minimal hardware requirements).


> "Should I learn saws or screwdrivers?"

The analogy is bad. One cannot use a screwdriver to cut boards. Those two tools serve completely different functions. But most of the things that one can do with C++, one can also do with Python. And considering you are just starting out, that "most" is virtually 100%.

A better analogy would be, "Should I learn band saws or circular saws or hand saws?" To become a master carpenter, one will of course need to learn them all. But when just starting out, picking one kind of saw is just fine.


Why not Java? I tend to find that anything larger than parsing and data collection Python/Nodejs becomes a bit of a maintainable mess for me.

Java/C# are boring, but once that little script grows into a massive beast you will be glad you can rely on the compiler doing a basic unit test of your program.

This is even considering that even though you have a huge amount of advantage with a dynamic type system most people don't end up using it. (http://neverworkintheory.org/2016/06/13/polymorphism-in-pyth...)


> once that little script grows into a massive beast you will be glad you can rely on the compiler doing a basic unit test of your program.

Not if I bother to write a few suitable unit tests, which I should really be doing anyway. Typechecking is absurdly far from substituting for checks that my code actually does what I intended it to do.


Tend not to write unit tests as most evidence show they have little or no impact (http://neverworkintheory.org/2016/10/05/test-driven-developm...)


Treat unit tests as a form of documentation in an executable format. It is invaluable in long running or larger projects.

(As opposed to automated functional tests or pure regression tests.)

Also that evidence was comparing test driven against test later, not against no test. That project tested was small enough and short enough to be ran by a single dev.


That is about TDD and not unit testing in general. And there sample population was graduates and undergraduates.

I'd say 90% of developers, which includes a lot of good ones too, never learned to write good unit tests. Poorly written unit tests are worse for productivity and no better for correctness than no unit tests.


I will add though after converting from a huge jpa spring boot rest service to just read since data from a database, node and graphql and plain SQL is a joy... That might have more to do with the fact that I'm starting this thing over and not inheriting design decisions..


Give it time. You can get a lot done with node, graphql and plain SQL. Although when you're working on a project with 50+ developers that is where the Spring JPA, Spring Boost, Tomcat, Maven come in their own managing less skilled developer to contribute to the team.

The other problem is when you're starting out you lose out on a lot of historic perspective. You get smashed over the head with Maven, Spring 1,2,3 (ORM, JPA) inverse versioning code, Hibernate, Transactions, Annotations, Servlet, JSP document/JSP pages.

Each collectively take about a year to get confident to give accurate quotes for large government projects. Let alone figuring what the hell the framework is doing.


This is why Ruby on Rails is running circles around the Java projects.


Free time i use mostly php/python. Havent given Ruby on Rails a go, how does it compare with connection pools? Oracle db connection drivers and Postgres databases?


A programming language is a door. It can be easy to open (Python) or take more effort (C++). The reason to open a door depends on what is on the other side.

The Python door opens to a large and playful room with about 100,000 packages ready for download on an incredible range of topics.

The C++ door opens to a room of lower level tools that can help you understand how your machine "thinks" about problems and how the data flows. It gives you more low level control but takes it also takes more effort to write multi-featured applications.

IMO, programmers should know at least one high level rapid application development language (such as Python, Ruby, or Perl) and at least one lower level language (such as C, D, Go, or Rust).

In addition, it is worthwhile to learn Javascript because it has a near monopoly on an enormous ecosystems of client-side tools.


You should learn to program and then get experiance using C++ and Python.

The language is fluff around the concepts. Get the concepts and you can go to any languages.


Learn C++.

If you learn C++ you will understand the collection of tradeoffs that go into making Python surface-level pretty and below-surface as ugly as anything else.

If you learn Python you will be wildly productive until you paint yourself into a corner.


After a few years playing around with BASIC I tried to teach myself proper programming with C++. I quickly ended up confused and bored at not getting anything non-trivial working that I gave up on programming all together. It wasn't before years later I when was introduced to Perl and then discovered Python before I started programming again. When I few years after that again took another stab at C++ it was so much easier.


That corner is very far though and showed up only in resource restricted systems.

Mind you, for a big enough problem any system currently available is restricted.


I was always told if you could be competent with C++ you could learn just about any other language, so wouldn't learning C++ make the most sense?


What's nice about Python is it so easy to get up and running. Plus its syntax is very expressive. If you're a Computer Science student, like you actually want to learn about data structures and computer organization, then you'll definitely want to study C++. Even as a secondary language to Python. However, you can start with Python to get any idea of what it means to be a programmer.


Python has many solid example's of properly applied data structures, with nice encapsulated high-level interfaces. It's a good language to learn if you're interested in the application of data structures.

For instance you have your standard list, which IIRC is implemented as a dynamically allocated array of pointers to Python objects. This gives very fast append and pop operations on it's right side, making it a wonderful stack. However it's interface specifically lacks a dedicated prepend/appendleft operation, because appending to the left of the array involves shifting the entire structure over one place in memory. This is a very slow operation, because it must copy the entire structure to simply insert a single element. Python get's away with append on the right, by allocating a bit of extra "padding" memory on the right side, to avoid having to copy the structure. For the situation where you want to append to either side, Python offers `collections.deque`. This structure is implemented with a linked list of pointers, IIRC. Which gives very fast append operations from either side, because adding a new element only involves "hooking" the new element to the preferred side, kind of like a chain.

However for understanding how these structures are implemented C based languages are the way to go.


> For instance you have your standard list, which IIRC is implemented as a dynamically allocated array of pointers to Python objects. This gives very fast append and pop operations on it's right side, making it a wonderful stack. However it's interface specifically lacks a dedicated prepend/appendleft operation, because appending to the left of the array involves shifting the entire structure over one place in memory. This is a very slow operation, because it must copy the entire structure to simply insert a single element. Python get's away with append on the right, by allocating a bit of extra "padding" memory on the right side, to avoid having to copy the structure.

Not quite sure I get this. What's this got to do with Python? Arrays, or more specifically resizing arrays, are supposed to work like what you just described. Appends are constant time and you almost always have extra memory because of the resizing nature. Is this different in other languages?


Basically Python offers many nice interfaces, which encourage relatively efficient use of the underlying implementation. It would be trivial to implement an `appendleft` method for Python's list type (you could compose `list.insert`), but its omission was a good design choice, in my opinion. The language tries to guide you toward using the more appropriate data structure for the task, in this case a dedicated queue type. There're are numerous other similar examples scattered throughout the language. The way Python applies it's data structures is really well though out, and shows a great deal of attention to detail. There's a lot of wisdom wrapped up in Python's design choices, which I believe helps aspiring coders pick up solid techniques.

This isn't to say that Python is somehow, the be-all end-all language, but it's a very nice language, with many nice aspects to learn from.


Thanks for the explanation. I think I might have slightly misunderstood your original comment.


The post you are challenging might make more sense if you understand, for example, that many people are using low-level languages that do not offer efficient implementations of data structures, or that "list" types are typically implemented as linked lists in a tradition that goes back to Lisp if not beyond.


Nothing stops you from implementing them in python, you will get toy performance but the concepts are teachable in Python: http://interactivepython.org/runestone/static/pythonds/index...


C is something you should learn because it is the foundation for so much of the industry.

C++ and python are something you may want to learn depending on your needs.


One should learn C if one wants to enter the world of highly resource constrained computing. Once the community matures and the ecosystem matures I'd recommend Rust for that domain, if they are serious about competing at the systems level.


Modern C++ does constrained resources better again than C, giving you more expressive options and compile time computation.

Rust might have a future or it might be dead in 10 years. Its main focus is a very narrow definition of safety (memory safety and partial data trace safety) at low cost.


C++ can do constrained resources better than C, it really depends on the context. In general, C will almost always be usable, though, even in cases where the use of C++ doesn't add anything because of severe constraints.

For Rust, I agree 100%, and that's why I qualified my statement the way I did. It's too immature a language used mainly by people who are vested in it and few others.


If you want to pick one to learn first, then whatever you decide will be the right choice, as long as you are committed to learning more. As the article states, being just a JavaScript developer, for instance, is a lot like being just a screwdriver operator. It's not easy to compete in the job market with just one skill and just one facet of understanding.


Neither; learn OCaml


C or Lisp would be better choices if maximum learning is the goal, or Haskell if hard core type fundamentalism appeals.


Bear in mind that the original question is 'Should I learn C++ or Python?' This suggests the asker already knows C and is looking for the next step. Given that, w.r.t. to Lisp, I believe an ML-family language like OCaml would be a strict superset of the learning offered by a Lisp, and w.r.t. Haskell--hard core type fundamentalism rarely appeals to people trying to decide between C++ and Python.

I suggested OCaml for its static typing features, speed (comparable to C++), potential to deploy universally (desktop, mobile, web), and last but not least because of its pragmatism--if you need to do some imperative programming, it gets out of your way.


Well, They teach ocaml as part of masters functional programming in uiuc.


I was going to suggest Go for its utility usefulness while not being quite as complicated as C or Haskell, though Python serves that well too


I agree, type inference, sane object and classes, modules and ADTs and MirageOS. Looking back i wish F# or OCaml was my first language


Yes.

On a serious note: these are the 2 primary languages at companies like Google, so it can't hurt.


Pick one, learn it. There are libraries to do what you want to do in both languages. If you get good at one, you'll figure out a way to shoehorn it into the problem you're trying to solve.


the answer is "the one you've heard of/touched upon first", or "the one you're familiar with", or "the one you're comfortable with".

typically, those new to programming have written in some language prior. it's usually just a few lines, but it's enough to get them hooked!

encouraging them to explore what they've already touched upon gives them something to latch onto. they presumably already had the tools set up, so what's wrong with continuing?


You should learn C++ and Javascript;


I'd recommend PHP instead of JS of you want to learn the truly worst language and ecosystem in the world. JS is just second place.


Great answer I completely agree.


Obviously, the most important skill for a programmer to learn is dogma. Dogma provides a perpetually frictionless path back to the primacy of your own ideas. Dogma obviates the need to become self aware, allowing you to pop out such gems as "So, stay out of this quasi-religious controversy", while portraying your own method as the One True Way.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: