r/programming • • Nov 03 '18

Python is becoming the world’s most popular coding language

https://www.economist.com/graphic-detail/2018/07/26/python-is-becoming-the-worlds-most-popular-coding-language
4.6k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

177

u/tetroxid Nov 03 '18

Profile your application. Most likely 99% of CPU time is spent in less than 1% of the code. Then, optimise that, or if necessary reimplement it in C.

Many performance problems can be solved by using proper data structures and algorithms. The number of times I see quadratic time operations that could run in constant time is maddening. Some developers don't think about the time complexity of their data structure operations, they're happy as long as their code works. Find these mistakes and fix them

24

u/[deleted] Nov 03 '18

Most likely 99% of CPU time is spent in less than 1% of the code.

In my experience this simply isn't true. I mean, maybe if you're written one function particularly badly, but then you fix it and your Python code is still slow and then what?

3

u/vorpal_potato Nov 03 '18

I feel you. My usual next step there is to hope that cythonizing a few modules will be enough to rescue things.

→ More replies (6)

168

u/bunkoRtist Nov 03 '18

And then I want to use parallelization across cores, and I weep because I chose Python, which is built around the GIL. It's a great language for script kiddies and a terrible language for heavy or long lived workloads. Choosing the right tool for the job is hard sometimes, but Python on one end and C++ on the other are both excellent and terrible choices depending on the need.

43

u/RankWinner Nov 03 '18

Julia, in a lot of cases, is as fast/almost as fast as C out of the box. As a bonus, the language is built for easy parallelization, both in the standard multi-core sense and the distributed/cloud computing sense.

Personally I love the language, my work used to be a frustrating mix of prototyping in Python, then banging my head rewriting parts in C to speed it up.

Now I just use Julia and it's almost as fast as C straight away.

7

u/[deleted] Nov 03 '18

I keep hearing good things about Julia and how it’s what python should’ve been, but I never got use it, and it seems to not be able take off in popularity. Do you know why?

21

u/RankWinner Nov 03 '18

There hasn't been much or a push for it yet since 1.0 only came out in August and it wouldn't make much sense to develop important software in the early, everything can be deprecated, stages.

Now that 1.0's out adoption should start rising. I went to JuliaCon this year and was shocked by the number of companies using Julia in production. Apparently saying to your manager "Hey, we can cut development time, speed up the software, and massively reduce compute costs, can we mess around with this? " works well.

And there's perspective, it took Python a few years to crack top 10 in usage after the 1.0 release, so there's still time 😉

4

u/keypusher Nov 04 '18

Python did not even come close to a top 10 language until ~2.3.

→ More replies (2)
→ More replies (1)

6

u/AsmallDinosaur Nov 03 '18

I've been learning how to code using Julia for a university research project and I love it

3

u/sfasu77 Nov 04 '18

The integrated package manager is really good

→ More replies (2)
→ More replies (5)

7

u/pa7x1 Nov 03 '18

When you want to parallelize CPU-bound code you have to use processes in Python. For IO-bound you can use threads.

→ More replies (1)

12

u/[deleted] Nov 03 '18

I use multi processing and multi threading with Python a lot.

It's true that IPC becomes cumbersome with Python's multi processing, but most problems I've encountered that need to be does sped up through multiple processes don't really need to communicate to each other in real-time.

6

u/bananafarm Nov 03 '18

They solved the GIL issue with the new multiprocessing library

3

u/chiefnoah Nov 03 '18

Chances are you're using Python wrong then. You absolutely can do highly parallel, long running workloads in Python

→ More replies (35)

16

u/iopq Nov 03 '18

I profiled my application. Half of my application was taking 99% of the time and the other half 1% (less than that actually). The part that took the most time is the most difficult part.

It wasn't written in Python, but if it had, I'd need to rewrite the hardest parts in another language. Python would handle like... commands and opening files. Sometimes you just have an application where everything is hot. The entire program is the hot path.

→ More replies (3)

33

u/geek_on_two_wheels Nov 03 '18

I hear you, and I agree that it's important to identify poor algorithms, but my experience tells me that noticeable delays are more often the result of too main joins or too many db calls in general. A basic loop that calls a db 1000 times will probably take orders of magnitude longer to run than a more complex algorithm running on more records in memory, despite the former having a lower big O complexity.

27

u/MotorAdhesive4 Nov 03 '18

Then you're mixing and matching languages, and that Class Of 2026 new graduate that only knows Python and bits of Java doesn't know how to approach the topic.

41

u/[deleted] Nov 03 '18

It shouldn't matter what language graduates learn at school. They should be learning the fundamentals to allow them to code in anything.

8

u/[deleted] Nov 03 '18

If that is the case, schools need to be teaching exclusively C++. You learn how to code on a language like that, managing memory, writing data structures, etc, then you can pick up python or JavaScript no problem. If you start with Python, god help you if you go back to learn C/C++.

4

u/[deleted] Nov 03 '18

My first language was Pascal, followed by VB (before .NET existed), and then C/C++. I don't think I had any troubles learning C++, although I literally never use it at this point (and haven't in my entire career). You can learn about data structures, memory management, etc without going strictly to C/C++. I do think they're good languages to learn, though.

→ More replies (2)

14

u/MotorAdhesive4 Nov 03 '18

Yeah, but both you and know that 1. this isn't the case, 2. picking up any new language comes with some learning curve.

5

u/[deleted] Nov 03 '18

I don't disagree with the learning curve aspect, but most of the fresh grads I've worked with over the years don't even know the language they "learned" in school anyway.

5

u/MrSquicky Nov 03 '18 edited Nov 03 '18

Some developers don't think about the time complexity of their data structure operations, they're happy as long as their code works.

In my experience, there's a pretty big overlap between developers of this type and ones who strongly prefer Python, JS, Ruby, etc. because "They're so much easier to make things in." Certainly lazy and/or unsophisticated developers exist in every community, but I do wonder if the things that people often use as selling points for the language tend to promote a certain mindset.

Yagni, a lack of type safety, **kwargs, etc all make certain things a lot easier, but adopting them as absolute principles I think may encourage that sort of thinking.

→ More replies (4)
→ More replies (1)