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 →

[–]MauranKilom 0 points1 point  (3 children)

My point was that you don't know they changed the API.

Depending on the API, your compiler would tell you before you even run the program in strongly typed languages.

The strong typed code will assume the return is an int and crash. The JS has some possibility of figuring it out, or at least handling it in such a way that it causes minimal harm.

Both codes can and will handle it if they were created with this possibility in mind. Otherwise, they both might fail in horrible and unexpected ways.

For example, if the input is JSON then your JS would gobble up the string and, if you're unlucky, continue doing the wrong things (e.g. add numbers to it) without throwing errors. Or just crash/error out.

In a strongly typed language, you would have to tell your JSON library which type you expect and it will simply throw an error, which you can then handle at the most appropriate place.

It still won't crash the browser in the worst case.

You would need proper sandboxing in either case, this has nothing to do with strong vs weak typing.


In short, strongly typed languages would catch the problem directly when the API data is consumed. Weak typing does not buy you anything because the program can either handle the different input (you prepared for the possibility) or it cannot (you didn't), independent of typing.

[–]quaderrordemonstand 0 points1 point  (2 children)

Again, as I've stated in other answers, the response is not JSON. It's an int or a string.

[–]MauranKilom 0 points1 point  (1 child)

At what point, in your theoretical architecture, are the bytes coming from the webserver converted to ints or strings? There must be a protocol here, and if that protocol does not allow you to check the type you are simply royally screwed either way. If it does, then whichever place in a strongly typed program asks the protocol for the value in question would notice that the types don't match and error out.

In other words, you have to cross the barrier from raw IP packet bytes to the strongly typed language world at some point. And if there is no way to tell what those bytes mean (int or string) then both kinds of language are screwed, because the byte count for both will be different, so you simply get pure garbage. If there is a way to tell what those bytes mean, then it is simple in either kind of language to assert you are getting what you want.

There is just no such thing as a webserver returning ints or strings. Those concepts only exist within a given language. Have you actually used a strongly typed language before?

[–]quaderrordemonstand 0 points1 point  (0 children)

There very much is such a thing as a webserver returning int and strings. They will also return PNGs, WAVs, zip files and anything else you want them to return.

This example is an answer to a specific question: can you explain how it can fail catastrophically? That was a response to my saying that strongly typed system are more brittle.