logoalt Hacker News

hackyhackytoday at 12:53 AM2 repliesview on HN

> 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/


Replies

frollogastontoday at 12:54 AM

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']
show 1 reply
jrrvtoday at 1:11 AM

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]

[0] https://wtfjs.com/wtfs/2014-10-07-true-equals-false

show 4 replies