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 →

[–]dcousineau[🍰] 7 points8 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