r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

140

u/Darcoxy Aug 26 '20

I'm learning Python after learning C and lemme tell you, some stuff that Python does look so illegal yet they work. I love it!

121

u/[deleted] Aug 26 '20

Wondering though, why do people consider this a good thing in Python but a bad thing in JS?

0

u/[deleted] Aug 26 '20

[deleted]

15

u/Yskinator Aug 26 '20

This. In python everything you'd intuitively expect to work will work for the most part, and things that make no sense result in exceptions. JS, on the other hand..

12

u/g0liadkin Aug 26 '20

I mean, that's the biggest pillar of js: it will run most stuff and do its best or yield errors in the console

For some reason people love bringing up examples like adding objects to arrays and saying "omg jabbascreept so random lol"

There are some cases where it's REALLY annoying though — e.g. typeof null being object

→ More replies (8)

0

u/[deleted] Aug 26 '20

[deleted]

→ More replies (12)

66

u/Tarmen Aug 26 '20

I think the problem is more with the cases that make no sense but still don't error

> "b" + {}
"b[object Object]"

42

u/[deleted] Aug 26 '20 edited Aug 26 '20

Why does that not make sense? Adding an object to a string implicitly converts the object to a string and then concatenates the two strings, and the default conversion for object is "[object Object]" if .toString() isn't defined.

Next you're going to tell me that 5 + 1.0 should also error because it implicitly promotes an integer to a double.

Edit: so this comment is dragging out all of the butthurt python fanbois. Here's the deal: your pretty little scripting language was written with auxiliary operating system tasks in mind, and was later adopted by statisticians and mathematicians. Of course it has hard typing and extensive error handling.

But JavaScript was originally integrated into HTML. That's frontend. Frontend needs implicit string conversions, because typing str(some_var) over and over again gets real annoying, real fast. "10" == 10 is a bit more arguable, but I suppose it has its use in validating input. Also, when you have a user on your frontend, the last thing you want is everything to come crashing down because of some formatting error in a string that gets shown to the user maybe once in a blue moon. There's probably some performance reasons for the way things are as well, because V8 compiles hot code into machine code - I imagine it's cheaper to just have a toString() defined to return a constant somewhere instead of checking for nullptr and slinging errors around...

In any case, Lua is, objectively, the best scripting language.

38

u/mrchaotica Aug 26 '20

It's not that JavaScript has syntax that isn't able to be figured out, it's that it makes a bunch of bad design choices that aren't useful.

I mean, Malbolge or Brainfuck "make sense" in the same way too, but that doesn't make them good languages to use!

→ More replies (12)

5

u/marmoshet Aug 26 '20

That's it, I'm learning JS

→ More replies (1)
→ More replies (25)
→ More replies (13)

8

u/marmoshet Aug 26 '20

JS is not as pythonic as python

7

u/Thomasedv Aug 26 '20

I think js is more scary on where it implicitly changes one thing to the something else. Not that python doesn't have similarly grave issues, but some of the stuff it does by itself become issues that aren't immediately seen and breakes something else later on.

Python is a little more strict on what you can have interact, eg. string + number is a no go, but in JS, the string might be converted to an number and added to the number, if it's possible.

6

u/pslessard Aug 26 '20

I don't think anyone would have a problem with multiplying a string by a number in JS. That's a reasonable thing

→ More replies (15)

9

u/letmeseem Aug 26 '20

I'm convinced Python is partially porn. It's super filthy, but you just can't peel your eyes off it.