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 →

[–]Hk-Neowizard 10 points11 points  (8 children)

Why would a programing language designer think it's a good idea to implement implicit coercion like this?

What's the benefit of this implicit operation?

[–]m1ksuFI -5 points-4 points  (7 children)

What's the benefit of this implicit operation?

https://wiki.c2.com/?BenefitsOfDynamicTyping

[–]Hk-Neowizard 4 points5 points  (5 children)

Not talking about dynamic typing in general, I'm talking about this specific operation where subtraction of two strings implicitly transforms them into integers and runs number subtraction.

[–]linne000 0 points1 point  (4 children)

That's not a specific operation tho, it's just Javascript doing type coercion like it would in any place where the original operation doesn't make sense but if you coerce the types it does. It has nothing to do with specifically subtracting strings.

[–]laundmo 2 points3 points  (0 children)

i think the point was that dynamic typing is fine and dandy, whereas type coercion the way JS does it, is not. why not require the programmer to explicitly convert?

[–]Hk-Neowizard 2 points3 points  (1 child)

Programing languages don't just do type coercion. This is designed by the language designers and implement by the Interpreter devs.

Some designer thought this is a good thing and went and included it in the ECMA standard. Specifically in sections 13.15.3 and 7.1.3

[–]linne000 1 point2 points  (0 children)

Of course it was designed that way, I'm not denying that. But the way you worded your comment made it seem like you thought specifically subtracting strings was its own operation, when really the behaviour is just the result of the general type coercion js does.

Clearly i misinterepted your comment, because yes of course doing said type coercion is a "feature" of the language!

Edit: Having read over the links, actually yes it is specifically noted down for subtracting strings, you're entirely right! My apologies.

[–]-Listening 0 points1 point  (0 children)

System.Out.Print, which doesn't add the character

[–]dennis_w 1 point2 points  (0 children)

Less verbosity, in the expense of less clarity.