Revanche1367
8 hours ago
A lot of Python design decisions have felt weird and off to me but they’ve long justified it by saying that it’s those little ugly design choices that make the language so usable and effective in practice compared to more well-designed languages that hardly anybody uses. I’m not enough of an expert to clearly say if that’s really true, but imo, there’s a repeated pattern of slightly weirdly designed languages becoming super popular: Python, Javascript, perhaps C as well. Or, maybe we only notice the weirdness because these languages are used so much and get nitpicked to no end.
stephenlf
7 hours ago
Yes. These are funny little quirks, but nobody will ever get tripped up by them.
frollogaston
8 hours ago
JS is a lot less weird than Python. And Python is what I started with and continue to use half the time. The article missed the most common one, __name__ == "__main__" like wtf
Revanche1367
8 hours ago
I’m not a regular JS user and haven’t touched the language in a long time, but I remember a (popular?) website for teaching modern JavaScript mentioned that some aspect of the function/macro that returns the type of an object was just plain wrong in a specific and important case. This was years ago however, so maybe the problem isn’t there anymore. Anyhow, I added JS to the list mainly because it is known as a badly designed language and Brendan Eich seems to agree.
frollogaston
8 hours ago
There are certainly weird things about it, but they're all things you can ignore especially in modern times, whereas in Python you're constantly dealing with it head-on.
Revanche1367
8 hours ago
Totally agreed there, Python is my main language nowadays because of work but the inconsistencies and lack of some very easy to add syntactic sugar to cover up some of the ugliness (like your example above) in a backward compatible way is constantly irksome and keeps me from really loving my most used tool.
lukan
7 hours ago
Ah yes, nowdays it is even easier, but "Javascript, the good parts" came out 18 years ago already.
https://www.oreilly.com/library/view/javascript-the-good/978...
Helped me get a more pragmatic approach to use that chaotic mess of a language and environment. Just use what works, ignore the rest (but I also ignored some specific advice from the book and used what worked for me).
Daishiman
6 hours ago
I'm not sure what world you live in but I remember quite well when prototypical inheritance was The Way in JS to do object-oriented programming. Then they copied the C#/Java syntax for classes. Then they aded a bunch of reactivity with Observable with a ton of quirks.
Every single new, large feature in JS has been full of quirks. The same cannot be said for Python; the exceptions are few and far between and more often than not they're not actually exceptions but rather something bound to core language fundamentals which once understood don't present a challenge because there is an actual underlying consistency.
frollogaston
2 hours ago
11 years ago sure. Then the classes they added were syntactical sugar. Observable was never part of JS, it's from the rxjs lib that I avoided cause yeah it's spaghetti.
In about the same timeline, Py went from threading to async-await, which created classic blocking vs nonblocking mismatches. The whole 2 to 3 breaking migration was also still a big deal in 2015.
Izkata
5 hours ago
You've probably just gotten used to it so you don't notice it anymore: https://github.com/satwikkansal/wtfpython
(Note some of these are outdated, but some of those only mention that towards the end of the section rather than the beginning)
impulsivepuppet
44 minutes ago
this isn't uniquely pythonic and JS isn't a great counterexample.
https://nodejs.org/api/esm.html#importmetamain
node also has __dirname and __filename from the good old days.
hackyhacky
8 hours ago
> JS is a lot less weird than Python.
I challenge you to find Python behaviors as weird and off-putting as anything here: https://wtfjs.com/
frollogaston
8 hours ago
A lot of those are stuff I'd never do like `Test.prototype = null;`. Some are legit footguns, but they rarely get in your way.
Python has weird file imports (no relative ones either), broken package management, historical differences between asyncio and blocking that still cause issues, threading/GIL caveats that trip up even experienced users, indentation for scope (esp weird given it was designed for REPL), weirdly no anonymous functions, 2 vs 3 (mostly gone by now), the __init__ and __init__.py stuff, namedtuple vs dict vs object, `global`, and a whole mess with type-linting if you're going there. You have to deal with all those things every time.
Here's one little Python footgun that everyone hits and is also annoying after:
def func(array=[]): # default value is empty array, right?
array.append("asdf")
print(array)
>>> func()
['asdf']
>>> func()
['asdf', 'asdf']Daishiman
6 hours ago
What you put as an example isn't a footgun if you know how the language evaluation rules work. Once you understand that the "footgun" explains a dozen behaviors, which may be a weird behavior but it is consistent.
Izkata
5 hours ago
Which isn't really much of a refutation because you can say the exact same thing about what's on wtfjs.
DangitBobby
5 hours ago
There's really no comparison. I use both languages extensively and JavaScript is by far the quirkier language.
jrrv
7 hours ago
I clicked on half a dozen of these at random and none of them are weird.
For example, why would you expect `Boolean("false")` to equal `false`? It's a string, and bears no relation to the Boolean type. [0]
selcuka
7 hours ago
I agree that the examples on that site are not very good. What about
[1, 2, 3] + [4, 5, 6] == "1, 2, 34, 5, 6"
or parseInt(0.000001) == 0
parseInt(0.0000001) == 1
or "" + 5 == "5"
"" - 5 = -5frollogaston
7 hours ago
A lot of them are also about nulls and == vs ===, which are weird, but they're weird in many langs. Like Python has the whole == vs `is`. You just learn the convention and use it. Same with typecasts.
joaohaas
6 hours ago
What about the fact that there isn't a single 'parseInt' function in JS that can reliably only convert number strings to numbers?
They each have different quirks (some will parse 'a123' as 123, others will handle scientific notation etc). The only reliable way of doing this is doing a regex followed by parseInt... which is definitely a footgun IMO.
Izkata
5 hours ago
Unary "+" returns NaN for strings that don't contain exactly a number (except for empty string which standard type conversion turns into 0). It even works for scientific notation like +'1e3' === 1000.
hahn-kev
7 hours ago
Fair, but I'd expect consistency. Number("1") equals `1` IIRC.
zmgsabst
7 hours ago
> __name__ == "__main__"
What makes this weirder than other languages detecting if they’re an import or an invoked file?
scoofy
2 hours ago
It’s only weird syntactically. Python tends to lean towards intuitive, natural language by default. I would have assumed they’d have created a syntactically straightforward alternative, like:
__this_file__ == “__launch_file__”
or similar. I understand python values “only one way” of doing things, but it would be helpful for readability.