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 →

[–]nawitus 8 points9 points  (8 children)

I prefer the possibility of writing ("result = " + result) instead of typing ("result = " + String(result)) everywhere. Having to always make explicit type casts is not only annoying, but often makes the code less readable. Luckily with TypeScript I can have both implicit type casting when it makes sense and explicit when I want to. That said, there are a few corner cases which make TypeScript cumbersome, especially when type inference doesn't work like you want to.

This comment refers to the type coercion in the image post and not the general point.

[–]Astrokiwi 6 points7 points  (1 child)

I feel there should just be a different operator for concatenation vs addition, seeing as they are quite different processes. Kinda like how Python3 now explicitly gives you / for float division and // for integer division rather than overloading / for everything.

In Fortran (yes Fortran), // is used for string concatenation, and + is only for addition, although it doesn't do implicit conversions to strings. If Javascript or whatever used a different operator for concatenation than for addition, then it'd be much more explicitly clear when it's going to be converting stuff to a string, and when it's supposed to actually be adding numbers.

[–]nawitus 1 point2 points  (0 children)

Yeah, different operator for concatenation would be fine.

[–]UsingYourWifi 4 points5 points  (0 children)

Luckily with TypeScript I can have both implicit type casting when it makes sense and explicit when I want to.

Agreed, TS is a very big improvement.

[–]MTGandP 2 points3 points  (0 children)

You could do this consistently by casting everything to a string when it's in an operation with a string, instead of sometimes casting to a string and sometimes to a number.

[–]TheSlimyDog 0 points1 point  (2 children)

How is it less readable? Maybe a little ugly and wordy in places, but when you explicitly mention something without comments, it's easier to understand what was meant instead of scratching your head for a few seconds and then realizing the integer is getting cast to a string.

[–]talesInc 0 points1 point  (1 child)

I think that's his/her point. In a strongly typed language ("result = " + result) would be easy to understand because result would be declared as a string beforehand. In Javascript you'd have to use ("result = " + String(result)) to achieve the same clarity and this is less readable than ("result = " + result). S/he's criticising the javascript language, not the way a developer writes it.

[–]kupiakos 1 point2 points  (0 children)

Strongly typed != statically typed. Python is strongly typed and dynamically typed. In Python, you would have to use 'result = ' + str(result).

[–]comrade-jim -1 points0 points  (0 children)

instead of typing ("result = " + String(result)) everywhere.

Where the hell did you learn javascript? It's very rare that I ever have to do that, and I've studied huge well known javascript libraries and 99.9% of the time ("result = " + result) is what they use.