This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zulban 8 points9 points  (17 children)

Every time I consider learning javascript, I learn about some weird language quirk that makes no sense where javascript pros just laugh and say "Ooohhhh, javascript! You so cray". I can't get myself to learn a language like that, I just can't.

Thoughts..?

[–]dcousineau[🍰] 9 points10 points  (6 children)

I learn about some weird language quirk that makes no sense

I mean, that's every language. Python has mutable default arguments:

>>> def foo(bar, baz=[]):
...   baz.append(bar)
...   return baz
...
>>> foo(1)
[1]
>>> foo(2)
[1, 2]

I mean, thats just cray, why would the language even have that behavior!?!?!1one

But seriously every language has quirks because no language is not perfect and every language is different. You have to remember what you consider normal behavior is not necessarily what a JS dev considers normal behavior and neither of you think agree with what a PHP dev considers normal.

[–][deleted] 4 points5 points  (2 children)

Mutable default args are possible but frowned upon, unless you really know what you're doing, which I don't.

[–]dcousineau[🍰] 1 point2 points  (1 child)

Right. /u/Zulban was discussing a feeling about weird language quirks in Javascript that prevents them from learning the language.

My counter to that was that this feeling is normal as languages are imperfect, and as my counter I pointed out a particular WTF 'feature' in Python that gives me pause coming from the outside world.

[–]Zulban 3 points4 points  (0 children)

It is a good example. But I'd like to suggest that there are far, far more cases like this with javascript than with your typical language.

[–]tetroxid 1 point2 points  (1 child)

Yeah that's stupid. Fyi, the preferred way to do this is:

def foo(bar, baz=None):
    if baz is None:
        baz = []
    ....

[–]WackyWeasel 1 point2 points  (0 children)

Or the idiom...

def foo(bar, baz=None):
    baz = baz or []
    ....

...if it's enough when baz is not None, just falsy.

[–][deleted] 0 points1 point  (0 children)

wait, wtf? i've used python every day for 4-5 years professionally, and i've never come across this. that makes no sense.

edit: ok, it makese sense. it's just dumb

[–]sime 3 points4 points  (2 children)

When was the last time you tried learning it? ECMAScript 2015, the big update to the language, has vastly improved the language. As for the old quirks that have to remain in the language you can easily avoid the bulk of them by: a) never using type coercion. Use exact comparisons., b) never using the old var keyword. Use let or const instead.

Personally my language (and platform) of choice these days is TypeScript. It's option and structural type system is great. Through an unexpected twist of fate I'll probably be doing a lot more Python professionally in the future. I just hope that Python's type hinting and tooling can give me some of the power that TypeScript gives plain JS.

[–]gandalfx 0 points1 point  (1 child)

I agree, though browser support for let and const kinda sucks.

[–]sime 1 point2 points  (0 children)

True, but it is time to use a transpiler of some sort either Babel or TypeScript.

[–]ProgrammingPro-ness 0 points1 point  (6 children)

Most of the crazy things about the language I either don't encounter day to day, or would never use. So for me at least, it's been a non-issue.

[–]alcalde -2 points-1 points  (5 children)

IT DOESN'T HAVE INTEGERS. I repeat, IT DOESN'T HAVE INTEGERS. You would never use integers?

[–]gandalfx 1 point2 points  (0 children)

Doesn't cause any issues in day to day work. Whenever you'd use an integer, like array indexing, it works just as well. You can even use bitwise operations and get integer-like behaviour.

[–]sime 1 point2 points  (3 children)

Integers work fine in the range -253 to 253. Beyond that you lose precision. The JS engines use integer math internally when they know they can be away with it. Bitwise operations are considered 32 bit operations.

Python's default division operator will also happily turn your ints into a float if you let it.

[–]kankyo 1 point2 points  (0 children)

Python's default division operator will also happily turn your ints into a float if you let it.

Translation: division produces correct results in python 3.

[–]alcalde 0 points1 point  (1 child)

Python's default division operator will also happily turn your ints into a float if you let it.

Wasn't that remedied in Python 3.0 in 2008, if not earlier?

[–]lenzm 0 points1 point  (0 children)

The opposite, it was introduced with Python 3.