Ah Python, you have spoiled me for all other languages

Steven D'Aprano steve at pearwood.info
Fri May 22 21:36:35 EDT 2015


On Sat, 23 May 2015 05:14 am, Laura Creighton wrote:

> The first time you discover that in javascript typeof(null) is 'object'
> and
> not 'null' you will scream.  I wonder how many home versions of typeof
> to replace the system one exist out in the wild?

What weirds me out is that that Javascript provides syntax for creating
arrays and associative arrays (in Python terms, lists and dicts) but
there's no standard way to check them for equality.

What weirds me out is that setting properties on non-objects silently fails:

js> var a = 1;
js> a.foo = "something";
something
js> print(a.foo);
undefined

except when it doesn't:

js> b = null;
null
js> b.foo = "something";
js: "<stdin>", line 16: uncaught JavaScript runtime exception: TypeError:
Cannot set property "foo" of null to "something"
        at <stdin>:16


What weirds me out is how useless the tracebacks printed are, at least using
Rhino. There's no stack trace, so if there's an error in a function call,
you cannot see what called the function.


What weirds me out is that all numbers are floats, even if they pretend to
be ints. So:

js> Math.pow(2, 53)
9007199254740992
js> Math.pow(2, 53) + 1
9007199254740992

What weirds me out is that iterating over an array gives the indexes, not
the values:

js> arr = [10,20,30];
10,20,30
js> for (a in arr) {print(a)}
0
1
2


What weirds me out is that while false is falsey, and Boolean(false) is
falsey, new Boolean(false) is truthy:

js> arr = [false, Boolean(false), new Boolean(false)];
false,false,false
js> for (i = 0; i < arr.length; ++i) {
  > print(arr[i]);
  > if (arr[i]) {print("Surprise!")} }
false
false
false
Surprise!


It's going to take a lot to get past the first impression that Javascript is
nearly as horrible as PHP.


-- 
Steven




More information about the Python-list mailing list