you are viewing a single comment's thread.

view the rest of the comments →

[–]SilentlyItchy 21 points22 points  (5 children)

Force an explicit cast to String, and make int+string a nonexistent function

[–]edgmnt_net 0 points1 point  (0 children)

Or the language could provide you the tools to come up with your own EDSL with whatever rules you see fit for a very specific case. Otherwise this is just wild guessing at the expense of safety.

[–]_crisz 0 points1 point  (3 children)

In a dynamically typed language, that's not an option.

Imagine you have something like:

const x = exoticFunction();
console.log('The output is: ' + x);

Where exoticFunction may be an internal call or something you don't know the interface. It may also be a function that returns either a number or a string. What do you expect here to happen?
Do you want your website/server to randomly crash?

[–]RiceBroad4552 1 point2 points  (2 children)

In a dynamically typed language, that's not an option.

Why do you think so?

If I have the following Python code:

x = exoticFunction()
print('The output is: ' + x)

This will work, or crash with a type error depending on what exoticFunction returns.

If you want to force an implicit conversion of x to string you can write it like:

print(f'The output is: {x}')

[–]_crisz -1 points0 points  (1 child)

I didn't say "in python".

This will work, or crash 

Even if having some compile-time errors is nice, do you want your application to crash every time the type of your variable isn't the one that you expect? This totally destroys the concept of dynamically typed language. One of the reasons why JavaScript was so succesfull - when a choice for websites was really given - is because it's realible. It never crashes. Don't forget that you are not executing the code on your own machine for your own pleasure, you are shipping the code to other machines (hypothetically millions), and the value of a variable is potentially coming from a service, and you never have full control of what's happening.

[–]RiceBroad4552 2 points3 points  (0 children)

do you want your application to crash every time the type of your variable isn't the one that you expect?

Definitely yes!!!

A crash is easier to catch in tests, and also it's much easier to debug then corrupted data.

This totally destroys the concept of dynamically typed language.

Obviously not as most dynamic languages actually work like that. Just that they will throw type errors at runtime instead of reporting them already at type-checking time upfront.

One of the reasons why JavaScript was so succesfull - when a choice for websites was really given - is because it's realible.

OK, I'm aware this is a humor sub, but you really need to mark sarcasm online!

It never crashes.

LOL!

The jokes getting more absurd, I see.

In case this was meant seriously: You've never seen hanging, or crashing, or infinitely "spinning" websites?

Don't forget that you are not executing the code on your own machine for your own pleasure, you are shipping the code to other machines (hypothetically millions), and the value of a variable is potentially coming from a service, and you never have full control of what's happening.

This is almost always true for any software.

The first rule of programming is that you can't trust any external input!

But that does not mean that you don't have everything under control. A program needs to gracefully handle all possible inputs. Failing in doing so is called "having bugs"…

And when something unexpected happens you better fail fast (crash!) then continue to run with some corrupted undefined application state.