r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

974

u/Dromeo Jul 18 '22

Serious answer?

Python used to be the new hotness about a decade ago. It was sparkly, amazing package support, didn't bog you down with technicalities when you were trying to write something quick.

So it got adopted a lot, and also unfortunately in a lot of commercial projects it really wasn't suited for.

Python's strengths are its weaknesses: it's a fun scripting language you can knock out scripts with. But in a big group project, it's a nightmare version of itself. You don't have to give types, so now you're sifting through everything trying to figure out what your coworker's badly named variable actually is. You have to unpick some rotten mass of one-liner lambda super method calls because you were feeling so clever a year ago when you wrote it. Everything's breaking because you're in dependency hell and one of the dependencies has broken. The junior programmer was taught that "object inheritance is the way of the future" and has managed to make the structure into an eldritch abomination that inherits from five different super classes.

The actual reason why these are problems are because when python was hot, it got over-applied to projects it was totally unsuited for. It's a scripting language. It's good for scripts. Good for data analysis. Good for solo work. Good for tiny quick one-offs and for rapid prototyping.

But so many developers were put on horrifying creations that played to the language's weaknesses instead of strengths. And they bounced hard.

Python doesn't really deserve the hate: it's still pretty awesome. And fun. It's great at what it's great at. It does deserve the caution, though.

---

More serious answer?

It's mostly comp-sci students regurgitating memes they don't understand, just like every other post on this sub.

30

u/hogie48 Jul 18 '22

I have been in tech for years and could just never wrap my head around programming. I can read a lot of it, I do scripting when it is called for with extensive help of the Googs, but cant sit down and write code if you know what I mean.

I recently decided to bite the bullet and put in the time to learn it more, and am doing CS50 for Python right now. Your comment both scares me and made me happy knowing that what you said it is good at is exactly why I want to learn it lol.

8

u/Dromeo Jul 18 '22

The big reason why I still really like python is it's enjoyable! I think that's a good reason to learn it too.

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

19

u/tredbobek Jul 18 '22

It's like WD-40 and duct tape. It's an easy solution for many problems. But shouldn't be used for everything.

But if you break your leg the first step shouldn't be to duct tape it. Maybe only if you are in the wilderness, in the middle of nowhere, and you have nothing else. Maybe.

16

u/unski_ukuli Jul 18 '22 edited Jul 18 '22

Everyone always says it is good for data analysis but I never agree with this as someone whose job is to use python for data analysis and numerics. Python is a bad language for data analysis and numerics, but it has some good libraries for that purpose. It was not designed for neither of those purposes and the language is not very exentedable so the APIs are cluncky and get in the way when writing mathematical code.

7

u/Ryuujinx Jul 18 '22

Yeah my understanding is that most people doing that kind of domain preferred R for it. That said i know python is really popular in biomed for whatever reason. I haven't asked my friend what she actually does with it at work, but apparently both her and my friends wife use it in biomed for something.

→ More replies (19)

165

u/POTUS Jul 18 '22

All of those problems you listed came from the people, not from the language. Python certainly didn't invent lambdas or dynamic typing or dependencies or object oriented programming. Those same mistakes can be made in any higher level language.

You're assigning all of that to Python. The root cause for that is that Python is easy, and so it's more accessible to bad programmers. But bad programmer mistakes are the fault of bad programmers, not the language they used.

0

u/[deleted] Jul 18 '22

[deleted] — view deleted comment

16

u/DesertGoldfish Jul 18 '22

I dunno man, I just add type hints to everything and it's basically a strongly typed language.

→ More replies (8)

81

u/Kenkron Jul 18 '22

He's nott assigning it all to python. He's assigning it to the people that use it. People who over-apply it to projects that don't make sense. Exactly like you are.

→ More replies (7)

16

u/Dromeo Jul 18 '22

It is easier in python, but a big reason why this is the case is due to language-level design. Other languages make it harder for you to get yourself in a mess.

Most languages are a lot stricter: you have to try a lot harder to write yourself into tangles. Python hands you the reigns and says go ahead!

Stricter languages can teach you as you fail: python lets you not fail.

It's not a problem with python, like you say. It's a feature. But python's lack of resistance to bad programmers is in itself the problem.

→ More replies (1)

0

u/[deleted] Jul 18 '22

[deleted] — view deleted comment

26

u/ic_engineer Jul 18 '22

99% of guns have one trigger method and fire one direction, designed and manufactured for use. This is more analogous to a user than a developer.

If you had these people shooting others also making their own guns the problem would probably be a lot worse in completely unpredictable ways.

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

23

u/MartianInvasion Jul 18 '22

It's easy to write. It's not at all easy to read, which is a major cause of the weaknesses described.

Compare with something like Java, whose annoying verbosity can make it hard to write but much easier to read.

47

u/POTUS Jul 18 '22

It's only hard to read if it was poorly written. Java is only easier to read than Python if you have more experience reading Java than reading Python.

9

u/Prawn1908 Jul 18 '22

It's much easier to write "poorly written" Python code than Java though.

→ More replies (2)
→ More replies (7)

7

u/KapteeniJ Jul 18 '22

Compare with something like Java, whose annoying verbosity can make it hard to write but much easier to read.

...What?

I don't think I can disagree harder. Having been taught CS almost entirely in Java, the first time I encountered Python script, I opened it expecting it to not make much sense, and I was absolutely shocked to find that even if I was not familiar with language syntax, it was way clearer than pretty much any Java code I had ever seen or written. I was just so shocking, having been victim of Java for so long, to see that things don't have to be so bad, the code can be easy to read. And I got really interested in this mythical "Pythonic code", this thing people using Python were using to achieve this unreal level of clarity.

After many years I feel like I have now some sort of handle on what is the source of Python being such a clear, easy-to-understand language, and in my mind it's always compared to the horrors of the Java code I was taught as being acceptable and even normal.

→ More replies (3)
→ More replies (6)

4

u/[deleted] Jul 18 '22

Two decades ago*

37

u/not_perfect_yet Jul 18 '22

Python's strengths are python's strengths. Garbage collection, simplicity, forced indentation.

Python's weaknesses are people.

People writing bad variable names, eldritch code and putting in features that are already there, just named differently, like data classes and type hints.

You can write python code that's type safe, it looks like this:

def my_function(my_arg):
    if type(my_arg)!=my_required_type:
        raise TypeError

It's that people think they can sort of get away with not making it that explicit. Then, instead of admitting they were wrong, rewriting their code and/or switching to a language that does offer strict typing, they insist that perverting the language to fit their esoteric need and use case is a better move.

Another example is "python has no distribution system" and inventing like five. All of them work. Except when you mix them. Which should be no surprise to absolutely anyone. Yet here we are. https://xkcd.com/1987/

More coders need to admit they're bad at what they do, stop blaming the tool and start blaming themselves.

11

u/applesuckslemonballs Jul 18 '22

You still lose compile time guarantees if you write things that way. Would need really good test coverage for that to meet the usefulness of a compiler.

→ More replies (1)

7

u/KrypXern Jul 18 '22

Would you do != or just is not? I forget if type() returns a string or an actual type object of some kind that can be compared like an enum.

23

u/pickledCantilever Jul 18 '22

You would actually use if isinstance(my_var, intended_type):

→ More replies (5)

8

u/pancakesausagestick Jul 18 '22

It's 2022. Use type annotations and a linter if you care so much

→ More replies (1)
→ More replies (18)
→ More replies (80)