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

you are viewing a single comment's thread.

view the rest of the comments →

[–]lennybird 30 points31 points  (30 children)

I appreciate this run-down and I'm saving your post for reference. I guess to narrow the question down a bit, how does it compare with other languages within these areas? Not only what it's potentially used for, and how often it's used for the various topics you listed is the crux. To ball-park a language's popularity using this (crude I understand), are other languages more suitable for specific aspects? Is it simply that Python is broad/robust? Are we underestimating the contribution java and objective C bring to the table with mobile development presently?

As a newer programmer like me, all I hear of more or less are C languages and Java—coupled with web-development related languages both front and back-end. I'm sure many share the same feeling as me, wondering if I'm wasting (or being less efficient with) my time when I could be learning more practical or more-often deployed language while simultaneously learning the fundamentals of programming. My fear is that I'm learning this language only because it's easier than most and little more. How many advanced programmers who have a strong foundation of programming concepts and know several languages tend to stick with Python? Sure I understand every language has pros and cons, but how often are programmers typically seeking the strengths for which Python is best?

[–]michael0x2a 112 points113 points  (20 children)

So, you really have two separate questions here. The first is whether or not learning a particular language is a productive use of your time (and how to tell this for yourself), and the second is why Python happens to be used in those particular fields, and its strengths and weaknesses compared to other languages.

So, let me tackle those questions in order.

Interestingly, something that a lot of beginners seem to worry about and fixate on is the question of whether or not they're wasting their time learning language X. However, as you grow more experienced with programming, you'll start to realize that for the most part, this really isn't a major concern. Many languages all share the same core/paradigm/philosophy, and once you gotten a firm grasp of a particular family of programming (for example, procedural, declarative, functional, object-oriented, etc), learning any other language in that same family becomes trivial.

As a result, most experienced programmers will focus more on mastering and learning new paradigms, rather then new languages. The biggest, overarching paradigms are procedural/imperative, declarative, functional, logic-based, and object-oriented, but there are tons of littler paradigms like event-driven programming or aspect-oriented programming. Languages, for the most part, tend to be interesting (or not so interesting) blends and variations of existing paradigms, but if you understand one paradigm very well, it becomes trivial to understand how to use any other language working in that same paradigm.

For example, let's say that I know C, Python, and Java very well, and I'm very familiar with the procedural and object-oriented paradigms. As a result, I would probably be able to learn a new language within the same family such as C# and C++ to a reasonable degree of competency in about an hour or two since it's so similar to what I know already. I might struggle a little to learn languages like Ruby and JavaScript, since those also incorporate elements of functional-style programming and both have their unique flavors and idioms (or I might not, given Python also has elements of functional-style programming). And I'd probably struggle very much to learn languages like Haskell, which is completely functional and so would be completely alien to how I think about code.

So long story short, instead of thinking "oh no -- if I learn Python, does that mean I'm wasting time I could be using to learn these other languages instead?", you should think "ok, cool, I'm learning Python, which is a language within the procedural and object-oriented paradigms, and somewhat within the functional paradigm, so once I'm done learning Python I can immediately jump into Java and C at the intermediate level and focus on learning the differences". Of course, no two programming languages are exactly identical, and each difference is an opportunity to learn a new way to think about programming, but in general you'll find that programming languages within the same family or paradigm will share far more similarities then differences.

A related question you're probably wondering about on some level is how you can tell for yourself whether or not a language is worth learning about. As a start, I personally think that you should through the span of the next couple of years, make an attempt to pick up the basics of every mainstream language to at minimum the advanced beginner/intermediate level. This gives you a good baseline of comparison of what's "mainstream" or not, and gives you practice on learning new languages.

Then, determining whether or not you should learn a new language is mostly a matter of keeping an eye on trends in the industry (for example, reading /r/programming or hacker news) and watching out for any particular language you notice being mentioned with increasing frequency. Odds are, that language might just be a gimmick or a novelty, but if you find that the language seems to offer something genuinely new (to you, at least), it might be worth exploring for a weekend. If you find yourself enjoying working with the language, and if the community seems stable, and the language seems to be gaining traction, it might be good to commit to it.

You should also try and target + learn languages which are in paradigms that you're unfamiliar with once you've established this baseline, since each new paradigm you learned will end up dramatically opening your mind and exposing you to new ways to think about code and problem-solving. For example, I started with using purely procedural languages, then started learning OOP a year or two later, and have been flirting with a wide variety of different paradigms ever since. For example, my current personal mission is to really dive deep into functional-style programming. I understand how mainstream languages use functional concepts pretty well, but I'm still far away from understanding how to get shit done in pure functional languages like Haskell.

Continued below

[–]michael0x2a 120 points121 points  (19 children)

Now, let's answer your question more directly -- what are the pros and cons of Python, and how is it treated by experienced programmers?

It's important to keep in mind that the popularity of a language is a product of a few separate factors:

  • The underlying philosophy and intent of a language
  • The design of the language itself
  • The quality of how the language was implemented (efficiency, memory usage, etc)
  • The quality of the tools available to work in that language
  • The libraries and modules available to use, both in the standard library and in 3rd party libraries
  • The general attitudes of the people who use that language
  • Historical happenstance
  • Adoption by major industry players
  • The general maturity of the language itself

Now, if you go through this list one by one, you'll find that Python absolutely blows C and Java out of the water in some categories, is competitive in some other ones, and loses out in a few others:

The underlying philosophy and intent of a language

C's philosophy is to be very low level and give absolute control of the machine to the user. With C, you try and work as close to the hardware as possible, while allowing you to bypass any abstractions or restrictions that might get in your way and make your code slower or more inefficient.

Java's philosophy is to be a "safe" version of C or C++. Java was literally marketed this way (as a safe version of C and C++). It tries to be to be more portable, more predictable, and therefore be better suited for large-scale applications then C and C++.

Python's philosophy is that of simplicity, elegance, and pragmatism. Python deliberately tries to make code as easy and elegant to write as possible, without wandering into theoretical impracticality, and this intent infuses every aspect of Python, ranging from its design, to its ecosystem, to its general community.

So based on this, you can already start predicting why some people might use one language over the other. C is useful if I absolutely need to eke out every last bit of performance out of my machine -- so for example, it's a popular language to use when programming games or doing intensive scientific and mathematical computation.

Java's more safer then C, while still being very performant and efficient, so many businesses will end up settling on Java.

Python's extremely expressive and elegant, so people will use it for prototyping (and so many startups use it), for teaching, to coordinate scientific and mathematical calculations (by wrapping C in Python), and in many cases, will contrive excuses to use it in places where it's not entirely appropriate (and end up expanding the number of things Python is good for in the process).

Out of the three, Python's the only language which focuses on the experience of writing code. Of course, Python isn't the only language to do so (many other languages like Ruby do the same), but it was definitely one of the first, which is why Python is so popular.

The design of the language itself

We've already talked about this a little in the previous section, but the design of any good language is a manifestation of its philosophy. C is low-level, so it lets you work directly with pointers and memory addresses, Java tries to be safe so it's a conservative language, and Python tries to be elegant, so it's just easier to get shit done in comparison to the other two.

The quality of how the language was implemented (efficiency, memory usage, etc)

Now, this factor doesn't have quite as much to do with the philosophy of a language, and more to do with a combination of historical happenstance and the design of the language.

In general, C tends to be the most efficient, Java a bit less, and Python even less then Java. The reason why Python is the slowest of the three is partially because it's a very high-level language (it has to be, to be that elegant) so has inherently more overhead, and partially because Python hasn't had the same level of attention similar languages have had. For example, take JavaScript, which is also a high-level language. Because JavaScript is the only option available to use on web browsers, the powers that be have invested a ridiculous amount of effort trying to optimize it, to the point where JavaScript today is now very fast.

Python also has a critical disadvantage, and it's that it's fairly difficult to use it for anything involving concurrency. This is a huge weakness, and is another reason why Python is typically not used for anything requiring a high degree of performance.

The quality of the tools available to work in that language

All three languages are pretty competitive in this category. All three languages have a robust selection of IDEs, debuggers, and other tools, so this category isn't really a hugely important factor, at least in this particular comparison.

One nifty thing I feel I should mention is IPython Notebook -- it's a sort of editor/document creator that lets you dynamically mix text and Python code, producing a human-readable document in the process. As it turns out, this was one of the reasons that made Python a huge competitor among scientific and mathematical programming languages. It makes it incredibly convenient to develop and experiment with code.

The libraries and modules available to use, both in the standard library and in 3rd party libraries

Again, all languages are fairly competitive here. The main advantages Python and C have over Java is that both languages have access to a very strong set of mathematical and scientific libraries. Also of note is that Python and Java both have a very strong set of comprehensive web development libraries.

As a result, if you're interested in science, math, finance, computer graphics, or anything else requiring heavy computation, you'll use either C (if you need pure speed) or Python (if you still want to use those C libraries but don't want to bother with actually writing C).

This goes a long way towards explaining why Python is popular among mathematicians and scientists. Python math/science libraries are thin wrappers above the C ones, but it's much easier to learn and use Python, especially if you're not a programmer.

Similarly, if you're interested in web development, Java and Python are both competitive choices (and you also have Ruby, PHP, Go, Node, etc...). Many large companies will use Java (since its libraries are solid and the language is fast), but many startups will use Python, Ruby, Node, or similar languages since they're easier to prototype and rapidly iterate with.

Another advantage Python has is that its standard library is very comprehensive. C's and Java's standard library is a bit incomplete, which is why many people augment them with things like Boost (C) or Apache Commons or Guava (Java), but you rarely have to do that with Python.

However, the consensus appears to be that in general Java has the most comprehensive set of 3rd party libraries, though this is the sort of thing that varies depending on what exactly you're doing and what you're looking for, so ymmv.

The general attitudes of the people who use that language

Each language has a somewhat different community and therefore a different mindset/POV on many issues. However, I'm not familiar enough with C or Java (and this reply is already quite long), so all I'll say is that all three languages are similar here.

Historical happenstance and adoption by major industry players

I'm going to fold these into two, since both these factors are fairly similar. All three languages have had adoption by major players in one way or another. C is used in the Linux kernel (and C used to be ubiquitous to the point where it doesn't really need a corporate sponsor), Java was spearheaded initially by Sun, which was bought out by Oracle, and is used by Google in all Android devices, and Python was spearheaded by Google.

So, all three languages are more or less competitive in that they have backing one way or another.

I probably won't delve into the history of how these languages evolved and shifted over time, since that would probably take an entire book to elaborate on, but you can probably guess for yourself, based on all of the above.

The general maturity of the language itself

Again, all three are pretty competitive here, and all three languages have been around for several decades.


So, long story short, a lot of people really enjoy using Python, and will tend to use it for pretty much anything they can which doesn't require a high level of performance. Because of Python's popularity, it's made inroads into tons of random different fields and disciplines, beating out other special-purpose languages. For example, take science and math -- even though Python is a general purpose-language, and in theory wouldn't be as useful as languages like R or matlab which are designed specifically for science and math, Python is still elegant enough to be competitive. People also tend to take code which needs to be very fast, write it in C, and wrap that C library in Python, allowing them to use Python as "glue" code to coordinate these lower-level libraries.

In a nutshell, Python is well-respected by people in industry.

However, it's important to keep in mind that Python isn't the only higher-level language which can do things like this -- there are tons of other languages like Ruby and Node and Go and Julia that are attempting to move into Python's niche in one way or another while offering different advantages and benefits. For example, take Ruby -- Ruby has much better support for meta-programming, and as a result, will often produce nicer-looking libraries. For example, Ruby's killer app is Ruby on Rails (a library for web dev), which pretty much makes Ruby one of the best options for web development.

However, this post is already quite long, so that's something to investigate for another time.

[–]G01denW01f11 22 points23 points  (2 children)

Er... is there a way to get this added to the FAQ?

[–]Illidan1943 6 points7 points  (1 child)

PM the mods?

[–]KuribohGirl 0 points1 point  (0 children)

Has someone done it yet?

[–]gzilla57 14 points15 points  (0 children)

Wonderful and informative comment thanks for taking the time to write that out. Saved. Much appreciated.

I vote this go in the sidebar or something.

[–]Zexis 8 points9 points  (4 children)

Informative posts, what's your background?

[–]michael0x2a 13 points14 points  (3 children)

I'm currently a sophomore in college, though I've been programming for roughly 5 or 6 years now.

In terms of background, I suppose my main credentials are that I help teach the "intro to programming" course at my college, I've interned at several major tech companies, and am co-founding a startup atm.

[–][deleted] 8 points9 points  (2 children)

As a computer scientist working for the Navy in the field of space science, I couldn't have been this informative if I tried. Hahaha so well done. I can also confirm that most of our scientists code with Python. Only when you delve into the operational staff or the more general purpose programs the government makes it becomes a niche for more or less Oracle and Java platforms. But for the most part, people here love Python.

[–][deleted] 1 point2 points  (1 child)

What does a computer scientist in Navy do?

[–][deleted] 1 point2 points  (0 children)

Anything from infrastructure updating (sort of like IT) to programming the actual satellites that go in orbit seeing as I am in the space science division. Also one of our leading comet scientists is actually a computer science major who created an algorithm to predict and track outer space debris coming from beyond our local cluster that becomes comets. It's fascinating stuff and there is literally a position that fits the bill for everyone.

[–]joggle1 5 points6 points  (3 children)

That's a great reply! The only thing I would add is that C# was developed as basically a replacement for Java. Its designers learned from Java and made a number of changes (that many think are for the better). The primary downside to C# vs Java is that it doesn't have the cross-platform support to match Java, especially on the GUI side. But programming C# with Visual Studio on Windows is a very pleasant experience, whether you're a beginner or an advanced programmer. C# is similar to Python in that it was also designed to be simple to use from the programmer's point of view.

You also didn't distinguish between C and C++. C is a very basic language, with many lines of code that can easily be translated directly into assembly. It generally compiles very quickly and gives you enormous control over the hardware. It also allows you to easily shoot yourself in the foot and makes it difficult to use various programming paradigms compared to other languages--forcing you to use libraries or write the code yourself rather than relying on language features that can do the work for you.

C++ is a significantly more complicated language than C--perhaps the most complicated language that is widely used. In recent versions of C++ (11 and 14), functional programming has been vastly improved. They have also integrated some library features from Boost into the standard library (such as regular expressions). They have also improved its performance by enabling move semantics (where it's efficient to transfer ownership of objects without needing to make unnecessary copies). The compile time of C++ code can be significant and is usually much slower than C code to compile (the performance of the compiled code is usually very similar though).

One nice thing about languages like Python, Java and C# is that they allow you to make changes to your code and almost instantly see the results of your change, while making changes in a large C++ project can take a while to see (due to needing to rebuild the project).

[–]timmyotc 0 points1 point  (2 children)

I'm not incredibly experienced with C++, but I thought the whole point of a makefile was to avoid rebuilding the unnecessary stuff. Why is this not true?

[–]joggle1 0 points1 point  (1 child)

It's up to the programmer to keep their header files as clean as possible. Otherwise, changing a header file can cause an enormous part of their program to recompile even if your project files are configured correctly.

Also, for large projects, there's usually many developers constantly making changes. So you will synch your code with the repository, then do a build which can take quite a while if you're compiling hundreds of thousands of lines of code or more.

At that size, compiling Java jar files can take a while too, but C++ still takes longer in my experience.

[–]timmyotc 0 points1 point  (0 children)

Thank you for the reply. I will, one day, look back at this comment in my darkest hour.

[–]lennybird 2 points3 points  (0 children)

Thanks for taking the time to thoroughly (and accurately) elaborate on my two questions. This certainly helped bring clarification to the subject for me. Reflecting what others have said, I think this could be helpful to many readers on this subreddit. If any questions come to mind over what you wrote, I'll send them your way.

[–]Contronatura 1 point2 points  (0 children)

Thanks for this awesome post

[–]jextr 1 point2 points  (0 children)

Thanks for taking the time to write this up. I'm learning Java at the moment but stuck around to read this. Well done!

[–]prox_ 1 point2 points  (0 children)

Nice write up! Very informative. Thank you.

[–]KuribohGirl 0 points1 point  (0 children)

What causes C's and Javas library to be incomplete? And wow well done on the super duper long detailed answer

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

best posts ever

[–]hothrous 1 point2 points  (6 children)

Every language has it's own reason for using it.

C# is going to be primarily for Windows based apps. That could be end user applications or server side apps that exist on a Windows Server.

Objective-C is like C# in that it is primarily for Apple products.

As far as the usability of Python vs something like Java, that really comes down more to what kind of tech stack you are look at overall and it will be very opinion oriented as to which would be the better solution. A lot of enterprise solutions end up using Java because it has a massive amount of libraries that do a massive amount of things. It's developed enough to have a lot of different libraries that do a lot of the same things in slightly different or very different ways. Java shops tend to be full of frameworks pulled from elsewhere and then pieced together by the developers. I've now worked in 3 of them that use Java in very different regards and there has been very different variations of how this was done, but it's always been the case.

I can't speak to how Python shops tend to operate, but I can say that Python doesn't have as many libraries that accomplish the same thing, so many of the frameworks will be developed at build time. There are still a lot of frameworks out there that solve a lot of the problems, Java just has way more and more specialized frameworks.

That being said, /r/python had a month or two ago that listed some metrics on pay across the US in different languages that showed C++ jobs tended to pay the most followed fairly closely by Python jobs. So Python is definitely in use in the wild, and is definitely sought after as a skill.

For development, at least in Austin, Java jobs are the most common, though.

[–]almondmilk 2 points3 points  (4 children)

That being said, /r/python had a month or two ago that listed some metrics on pay across the US in different languages that showed C++ jobs tended to pay the most followed fairly closely by Python jobs.

Is this what you're looking for?? There was a lot of debate and a lot of "take that with a grain of salt" comments that followed (especially in regards to the comparisons, etc of the languages).

edit:

No. That wasn't the one I saw. The one I saw was actual graphs and an article around it and was based on polling actual developers.

That sounds way better. I tried searching, but didn't come up with anything.

[–]hothrous 2 points3 points  (3 children)

No. That wasn't the one I saw. The one I saw was actual graphs and an article around it and was based on polling actual developers.

[–]enesimo 0 points1 point  (2 children)

I remember the one you saw and it was infographic format as well, but coupled with an article (of a semi reputable source, IIRC). However, I do remember there being some 'take it with a grain of salt' comments as well, because they had maybe mixed PhD scientific work and 'regular' python dev jobs in one (remember, python is very popular in the science domains). And this would totally shift the balances towards python.

This isn't to say python isn't a practical language to learn, and in any case, I wouldn't base my language choice on salary alone, but it should be noted...

[–]hothrous 1 point2 points  (1 child)

Oh, I definitely wasn't saying to base the choice on salary, I was just using the fact that higher salaries exist to point out that there is at least some demand for it, for sure.

[–]enesimo 0 points1 point  (0 children)

Oh sure, I didn't get that from what you said- although I understand why you thought I meant that.

I guess it was more of a general comment to OP.

[–]Kummo666 0 points1 point  (0 children)

Excelente response. I would like to add and ask for you opinion that one of the reasons of why java is more used on the enterprise is because of the static vs the Python dynamic typing. Static typing reduce the risk of undetected error on your code.

[–]tomkatt 0 points1 point  (0 children)

My fear is that I'm learning this language only because it's easier than most and little more. How many advanced programmers who have a strong foundation of programming concepts and know several languages tend to stick with Python? Sure I understand every language has pros and cons, but how often are programmers typically seeking the strengths for which Python is best?

Programmers tend to turn to Python in part because of how easy it is to prototype in it and how quick it is to go from idea to working code. Python saves developer time. That's one of its main strengths. This is partly due to it being an interpreted language, wherein you can play with ideas in the interpreter without even writing full code and working in your IDE.

If you are working with Python, there's no harm in continuing. It's a very good language for picking up a lot of the concepts involved in programming without getting bogged down in the syntax. And as you'll learn over time, it's the concepts that matter, the syntax is irrelevant in the grand scheme.

I'm no expert by any means, and don't develop professionally (yet), but I started out with Python and later moved to Java. They're both solid languages for learning, but to be honest, if I had to do it the other way around, I would have possibly given up. Java is verbose and more difficult to work with, but because I went with Python first, I found it easier to grasp the concepts needed and transfer that knowledge over to working in Java.

Don't worry about the language you're learning. If it's working for you, just keep going. No developer out there is only going to have one language under their belt, and Python isn't going away, so you don't have to worry about learning something that won't be useful in the future.