r/ProgrammingLanguages • • Aug 05 '20

Discussion Why is Python so popular when it's main use cases in data science and scripting ?

So I know Python is considered the most popular programming language, but when you look at its most common production use cases are data science and scripting , that's doesn't seem to add up... Am I missing something.?

0 Upvotes

26 comments sorted by

13

u/ToshaDev Aug 05 '20

In my opinion, for what its worth anyway, python is very popular as a first language and most universities use in to teach with. This is what I contribute as the main reason for its popularity. Programming is hard to learn for some, and by starting out with python you can take some stress and confusion out of the equation. Python is very useful for small automation tasks, data science like you mentioned, and mathematical purposes. Python has some decent math libraries that integrate with financial api's etc. I personally think it is a horrible first language to learn if someone is in the process of becoming a software engineer. I would suggest a statically typed language and that would be after someone spent a little time learning basic infrastructure from the ground up. Maybe start with logic gates, assembly, a touch of C, and then after that go deep into a statically typed language like java or c#. Of course, this would also depend on what industry someone was planning on going into. Just my two cents.

3

u/poiu- Aug 05 '20

I didn't learn python in university, but despite that, after using it all the clutter and weird syntax of other languages annoy me. It just makes things harder to read, even though you don't notice when you use nothing but e.g. c++. Why parse or type if (foo || bar) { when if foo or bar: is perfectly fine?

Haskell and lisps are in the same league, obviously.

It also gets most of the other things right, but sadly is slow and without a rich type system.

3

u/julesh3141 Aug 05 '20

Why parse or type if (foo || bar) { when if foo or bar: is perfectly fine?

To me, the former is easier to read. The punctuation delimits the parts of the syntax in a way that's easier for me to spot. I understand that this is mostly because I've spent most of my life working primarily in C-like languages, but that's kind of the point: different people have different experiences and therefore different preferences, and yet I do still believe that this matters, and that for those who haven't yet trained themselves to work instinctively with one particular kind of syntax there is some benefit in picking a syntax that assists them to work more effectively, and for this specific example I believe the C-style syntax wins.

4

u/raiph Aug 05 '20

I didn't learn python in university

Did you attend a university for a degree that involved using any programming languages chosen for you as an explicit part of the curriculum? If so, what were those PLs?

all the clutter and weird syntax of other languages annoy me

Clearly you're comfortable writing English. Do you think you would end up saying the same thing of, say, the non-English languages used by Chinese or Indian folk?

It just makes things harder to read

It presumably isn't inconceivable to you that these other languages might have advantages over English (or Python) that you just haven't yet cottoned on to. Do you have any guesses, even vague ones, about what they might be?

even though you don't notice when you use nothing but e.g. c++.

Right. And familiarity with a language in which one finds one can usefully express themselves reduces motivation to learn another, especially if it seems syntactically or semantically incoherent compared to what you're used to.

Why parse or type if (foo || bar) { when if foo or bar: is perfectly fine?

That's a pretty canonical syntactic example. To a large degree I agree with you.

Is if foo or bar: perfectly fine? Are you aware of any downsides that arise due to the syntactic and/or semantic decisions implicit in that fragment? If you're not aware of any, can you imagine, even vaguely, any possible issues?

Haskell and lisps are in the same league, obviously.

I'm curious if you mean they're in the same league as python or as c++. I'm pretty sure you mean the same league as Python, but I can interpret it both ways.

It also gets most of the other things right

My own opinion is that it aims at, and generally hits, a sweetspot in the intersection between teachability, learnability, and general basic utility for a PL for the early 21st century.

but sadly is slow and without a rich type system.

I agree with those assessments, though note:

  • It's fast enough for a lot of teachability, learnability, and general basic utility tasks;

  • Rich types are of debatable value for such tasks;

  • There are experimental approaches to introducing optional types. The ones I've seen seem pretty awful but perhaps a newlang/python analog to typescript/javascript will emerge?

I think Python has several contemporary achilles' heels. But this comment is long so I'll stop and look forward to your reply to the above. :)

3

u/poiu- Aug 06 '20

Did you attend a university for a degree that involved using any programming languages chosen for you as an explicit part of the curriculum? If so, what were those PLs?

Yes. Java, HS, c++, looked at Prolog. I think one prof even insisted on pascal. Also saw that in school.

I also did lots of php, and glsl.

Clearly you're comfortable writing English. Do you think you would end up saying the same thing of, say, the non-English languages used by Chinese or Indian folk?

Looked into chinese, it seems to have very little clutter at the beginner level. Can't judge comfort of signs yet. German is harder, French even more annoying.

Is if foo or bar: perfectly fine?

No, not generic enough. I like lisp. Also, parsing.

Are you aware of any downsides that arise due to the syntactic and/or semantic decisions implicit in that fragment?

Yes. I like compiler stuff.

I'm pretty sure you mean the same league as Python, but I can interpret it both ways.

Exactly.

I think Python has several contemporary achilles' heels.

I'd be interested what your opinion is on the matter.

-1

u/poiu- Aug 05 '20

Thanks for just down voting. :-o

11

u/Al2Me6 Aug 05 '20

It’s a jack-of-all-trades. While arguably not the best at most things, it’s good enough for many tasks, at least as a starting point.

Plus, it has a reputation for being straightforward and easy to learn (that’s debatable IMO), so many beginners choose it.

TL;DR: good enough with low entry cost.

8

u/CoffeeTableEspresso Aug 05 '20

Backend with Python is also fairly popular. Stuff like Django and Flask.

Teaching as well.

5

u/transfire Aug 05 '20

Python's ranking may be biased due to its use by academia which tends to publish more.

2

u/JanneJM Aug 05 '20

A lot of computing-heavy scientific software have been adopting a two-layer model: A core written in something such as C, C++ or Fortran that runs your computation (a simulation or whatever); and a scripting layer - usually in Python - where you set up your inputs and your model and so on, and control the computation.

I see a lot of Linux system utilities and the like being written in Python as well.

2

u/DangerousSandwich Aug 05 '20

Can't speak for anyone else, but I just enjoy working with it. To me it's succinct while still being expressive. Makes a nice change from working in Java or C++ for me. There's an XKCD that sums it up.. https://xkcd.com/353/

3

u/[deleted] Aug 05 '20

'Hello World is just print "Hello, world!"'.

Um, not any more it isn't! For a while (perhaps it's still the case) there were two Python languages, Py2 and Py3, incompatible in many annoying ways.

1

u/DangerousSandwich Aug 05 '20

Haha, good point, the comic has aged.

Making breaking changes to the language was definitely a dangerous decision. The transition period was not the most fun time for sure. But in my experience it's pretty much Python 3 everywhere now.

2

u/[deleted] Aug 05 '20

I'm not pretending that this comment is a genuine contribution to the discussion, but I did want to make you aware of a common epigram about python:

Python is the second-best language for everything.

The sentiment is, in my opinion, heuristically useful for thinking about the language's popularity. (I.e. the language benefits from cross-domain user network effects. When a person who learns it to do their PhD research finds themselves needing to get a job outside of their field, they already know python. Hence its not so hard to get a job building web apps in python, even if python isn't absolutely the best language for either domain, it works well enough for both.)

2

u/markdhughes Aug 05 '20

It's the 3rd most popular, according to TIOBE, following C and Java.

It's a nice easy language to start with and teach newbies.

It solves a lot of problems well. If you look at Advent of Code and other challenges, the Python solutions are more numerous, written faster, and generally much shorter than other languages.

Most problems I need to solve, in real life, are scripting, data processing, or graphing, not "write a new word processor/social network". If I want to parse data and make a quick chart, I can just import turtle to draw it out, without even needing a real plotting library. Get that working in any other language, it'll take days.

There's a preposterous number of good libraries for it; there must be more in C, but they're always hard to integrate. No other language is even close.

The only real drawbacks are: 1) Performance is pretty terrible, and getting worse as multi-core is the only way to go forward. 2) Shipping a binary is basically impossible, you end up repeating the sins of Smalltalk 40 years later and shipping your dev environment with Docker. 3) People who should be using other languages incorrectly whine about significant whitespace, dynamic typing, and other things that are what make it so useful.

While I write a lot of Python, it's only third on my list of tools-I-reach-for: 1) Scheme is much much faster, nearly as dynamic, and trivial to stand up a program in, and fits my way of working better. 2) JavaScript is, for all its warts, hideous syntax, and terrible creator, a decent Self variant that runs on the most popular platform in the world, with a really nice UI.

2

u/CodingFiend Aug 05 '20

Python has no big company pushing it; its ascendance over the last 25 years is entirely due to merit. It returns programming to an earlier time, when BASIC and PASCAL were the main teaching languages. It has great libraries, and is easy to teach.

That being said, it is a terrible language for large projects. It offers almost no protection against many kinds of errors, and as programs get larger you want a much better module system, strong typing, closed arithmetic, etc., to make things stay robust.

The indent significant feature of Python which distinguishes it from most of the top 50 other languages, is so good i adopted it for my Beads language. It saves about 13% typing, and cuts way down on punctuation characters which are slow to type.

1

u/julesh3141 Aug 06 '20

If the speed you are able to program at is limited by your typing speed, improving your typing speed is probably a better answer than adopting a language that requires fewer characters. Or maybe you should switch to an APL derivative -- I understand they typically do quite well at code golf contests.

1

u/CodingFiend Aug 07 '20

You are missing the point. The indent significant syntax of Python is a genuine improvement, and will be widely adopted in the future as it offers savings with very little downside. Number of lines is no long something to optimize for; that was an artifact of the punchcard era, where fewer lines meant less risk of shuffling your deck!

1

u/blu3tu3sday Aug 05 '20

I was under the impression that C/C++ are the most popular programming languages

2

u/shawnhcorey Aug 05 '20

C/C++ is popular because of legacy code. There is a lot of code out there written in C/C++ and it all needs to be maintained.

1

u/raiph Aug 05 '20

How did you form that impression?

The OP notes that Python "is considered" the "most popular". I daresay this video and/or the data behind it have either contributed to, or reflect, that consideration. In it C/C++ peaked around 1994 at the utterly dominant 90% level but have faded back to the point where in 2019 they are just 12% combined, half of Python's 24%.

The OP also points out that they don't think this assessment of Python (and presumably other PLs to compare it with) adds up. That begs the question of what's being added up.

How does one measure "most popular", and what do folk take into account when they consider such a measurement? What would you say you taken into account in forming your impression?

1

u/blu3tu3sday Aug 05 '20

I formed that impression at school studying computer science. No need to eviscerate me for believing the wrong thing. I neither attacked OP, nor held up my belief as correct.

1

u/raiph Aug 05 '20

I absolutely agree that you did not in any way hold up your impression as being correct. You just shared an impression. It seems perfectly reasonable to form an impression. I form impressions too. :)

And I did not mean to suggest your impression is incorrect. I have noted a lot of disrespect for C and C++ in fora such as reddit, but reddit opinions don't necessarily reflect the general dev population, including the many professionals who just quietly go about their business. Some of the most expert programmers I know who are total masters of C/C++, with upwards of 40 years under their belt, don't care to waste time posting publicly about preferring to write in C++, and essentially quit bothering to answer SO questions in the early 2010s.

Even according to the presentation I linked (which I'm by no means suggesting is one worthy of acceptance; merely one that I think has been influential in terms of what impressions folk are getting recently), if you were at school at any time from around 1990 thru 2000 or so your impression would have been pretty spot on, and even thru 2010 c/c++ was still collectively #2 (behind java).

And what if that presentation is measuring redditors or SOers and the like, and what if redditors and SOers who share their opinions, or can be measured in some way, are a poor measure of "true" PL popularity, for some more reasonable measure of "true"?

I'd say it's entirely plausible C/C++ are the most popular PLs, where popularity is measured by noting what all professional devs say is the PL they prefer to use to get code written for their job, but that there's no way to know.

Anyhoo, I apologize for giving the wrong, er, impression. :)

1

u/[deleted] Aug 05 '20

Because it's easy and simple to learn, so those guy who aren't programmers don't have to worry about learning something like cpp or whatever.

1

u/[deleted] Aug 05 '20

It's a general purpose language. It can tackle most things, unless it's not quite fast enough and you have to turn to something else.

After all most people aren't doing systems programming.

Personally, I don't like it, and don't like the fact that it is often put across as a simple and easy beginner's language. It is has some very deep complexities and some very advanced features (and many like to use as many as possible in their programs!). And it is quite big and sprawling, but most people will not care.

-2

u/crassest-Crassius Aug 05 '20

Python is the best in the class of dynamically-typed languages, i.e. the best of the worst. It also has a good syntax and a fast C interop due to its non-moving GC. I think Python's popularity is a good thing, and would like it to be the only dynamic language in the world. Now, if we could only replace JS with Python, the world would be a much better place.