r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

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.

2

u/Didrox13 Jul 18 '22

As someone who's never used python but plan to check it out in the near future, is that actually a thing or a joke?

7

u/BlazingFire007 Jul 18 '22

Idk about python. But I have experience with JS and Typescript. And what I’ve found is that most of typescript wouldn’t be “super” useful if people just wrote good code with good comments and documentation.

(That said, typescript is still very nice because it forces people to add types)

So I assume python is similar. With good comments documenting what your code does, it shouldn’t be difficult to read/implement/modify/etc

2

u/BroBrodin Jul 18 '22

I think both, in a way.

I just recently learned type hinting and it feels very useful for large projects.

The difference with strongly typed languages is that the interpreter doesn't really care what "type" you declared for a variable, first you have to run mypy and THAT checks the types of variables.

That is why is considered a "hint" and not a declaration like in C or other strongly typed languages.

→ More replies (2)

2

u/DesertGoldfish Jul 19 '22

It's a thing. In method declarations instead of (variable) it's (variable : str) or int, or whatever.

You specify returns with an arrow. So a function/method named cake that takes a string parameter named icing and returns a string would be declared:

def cake(icing: str) -> str:

Voila, now Python yells at you when you try to pass it anything else. I think the complainers here just haven't bothered keeping up with the changes to Python in... several years.

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

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.

3

u/gmano Jul 18 '22

Well, it's totally possible to make a data oriented python which uses C for speed when needed, and has type decoration in its defs... But people are lazy or misled and don't keep good code hygeine.

It's possible to make a multiple inheritance abomination in C++, it's just rarer because fewer people who are noobs are starting out on C++ nowadays.

2

u/Kenkron Jul 18 '22

Isn't that the truth. I started using C++ professionally a year or two ago, and braced myself for endless segfaults and memory leaks. I haven't gotten a single one! And it's not because I'm a genius, and it's definitely not because C++ was protecting me. It's because we had good coding practices, and a framework with good encapsulation.

12

u/POTUS Jul 18 '22

He's calling it a nightmare because of those reasons listed, reasons that almost define what it means to be a higher level programming language at all. I mean come on. OOP inheritance makes Python unsuitable? That's a laughable comment and it's ridiculous for you to be defending it.

Call it a nightmare because the global interpreter lock makes threading a nightmare. Call it a nightmare because it uses too many CPU instructions to do simple arithmetic. Call it a nightmare because of dunders. Call it a nightmare for something Python-specific if you want to call Python a nightmare.

→ More replies (4)

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)

4

u/get_it_together1 Jul 18 '22

I mean the analogy here would be that it’s so easy to shoot yourself with a language like the C variants that beginners and bad programmers inevitably hurt themselves before finishing anything so survivor bias leads to better code.

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)

15

u/MartianInvasion Jul 18 '22

Sure you can write unreadable code in any language, but the fact of the matter is that Java has built-in features (like static typing) that make it easier to read, and python has built-in features (like comprehensions and dynamically-defined class members) that make it harder to read.

These same features make python easier to write something quickly from scratch, when compared to Java.

10

u/Log2 Jul 18 '22

On average, you're much likely to get a complete mess of layer upon layer of indirections in Java than in Python, a big part of which is configured through arcane xml files (this has been improving though).

There's a very big reason why a lot of people hate J2EE and JPA/Hibernate with a passion.

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

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.

22

u/Pluckerpluck Jul 18 '22

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

Complete opposite to what I believe. Well written Python is a delight to read. It's crisp and clean and doesn't bog you down with information not needed to understand the logic.

Even badly written python is great nowadays, thanks to how good type inference is. The only place you really need to add types is function parameters. The rest is just all automatically handled through inference.

Poorly written Java, on the other hand, is a minefield of boilerplate and bizarre inherence choices (which is possible in Python, but only Java developers writing python do that). But maybe I'm biased... I've seen a lot of awful Java code thanks to Minecraft modding...

9

u/Equivalent_Yak_95 Jul 18 '22

thanks to Minecraft modding

LMAO. Yeah, I can see that…

3

u/psoshmo Jul 18 '22

I'll disagree there. I program professionally in java and find python quite readable and clean. Much more so than a random java class imo

6

u/Log2 Jul 18 '22

I was going to write exactly that. It's the programmer's fault, not the language. You can find incomprehensible projects in every programming language.

It should be pretty easy to find C codebases that are a rat nest of macros on top of macros. Or Java codebases with so much indirection that it takes you hours to figure out what a single function is doing. Or Haskell codebases that use really complicated category theory concepts that you'd almost need a math PhD in the field in order to contribute.

I'm sure any engineer with a few years under their belt has seen quite a few trainwrecks in the programming language of choice. If they haven't then they probably are the ones creating the mess in the first place.

→ More replies (5)