News for hackers. Stuff that matters.
Re:The advantages of static typing, simply stated by sidlls on Friday September 16, 2016 @10:04AM (#12514054)
Have you considered the possibility instead that JSON is not an appropriate serialization protocol or storage mechanism for the problem to be solved? Or that it isn't being used effectively/correctly (that is, it isn't being parsed correctly, e.g. with a library or some other mechanism that makes checking underlying types less cumbersome)? I noted in a comment downstream from here that plenty of C and C++ JSON libraries offer very easy parsing (e.g. "json_get_int(element, key)") that fails early. I almost don't even think about JSON twice if I have to use it as a data format in a C++ program I'm working on. It's just another library to link against and use almost effortlessly. Doesn't Java, or this Salesforce implementation of it, have something similar?

Furthermore every dynamic language I've used has had tooling spring up, e.g. in the form of linters, that includes at least some basic checking for type mismatch where possible. I'm not so sure static typing leads to problems. It isn't problem free--no programming language or paradigm is--but I do think the lack of it leads to some problems that are easily avoided without too much extra overhead.

Re:The advantages of static typing, simply stated by empath75 on Friday September 16, 2016 @10:15AM (#12514128)
Have you worked with a public api in the last few years that didn't depend on json?
Re:The advantages of static typing, simply stated by zeveb on Friday September 16, 2016 @10:34AM (#12514264)
'Everybody else is doing it' is insufficient justification to keep on doing it.

As it happens, I agree that JSON is probably a long-term mistake, although it is definitely an improvement over XML, the previous player in that space.

Re:The advantages of static typing, simply stated by asimuvPR on Friday September 16, 2016 @10:54AM (#12514391)
Every technology is relatively wrong. Time points out where and we fix it (process is repeated again forever).
Re:The advantages of static typing, simply stated by jack9 on Friday September 16, 2016 @10:10AM (#12514101)
> your only option is to cast to Object

In Java JSON is horrible for serialization because of Java behaviors (your best option is Object). That doesn't mean JSON is horrible for serialization, in general. Fields do have types (int, string, object, array) making it slightly better than arbitrary serialization.

Re:The advantages of static typing, simply stated by sidlls on Friday September 16, 2016 @10:31AM (#12514239)
I haven't used Java in a long time, so I don't what the library ecosystem for JSON is, but with both C and C++ there are plenty of parsers that make type casting and working with JSON data about as easy as in python. The difference is usually that the type of the underlying data one is interested in working with is explicit and, when the JSON data is malformed is caught earlier (at cast, as opposed to later, when trying to, e.g. add a string to an int in sane languages that break when that happens).
Re:The advantages of static typing, simply stated by sdegutis on Friday September 16, 2016 @10:08AM (#12514086)
Meh. A good JSON library for Java can still make it fail fast and fail early, and using Java's reflection it can be pretty concise too.
Re:The advantages of static typing, simply stated by zzalpha on Friday September 16, 2016 @10:07AM (#12514074)
Yup. The correct solution to this is schemas, not throwing away typing information.
Re:The advantages of static typing, simply stated by susan_hall on Friday September 16, 2016 @10:08AM (#12514083)
We have no control over the API that we draw from. We are drawing from the API of a different company. I wish they didn't use JSON. If they have to use JSON, I wish they at least enforced a consistent schema. But they don't. And that is why static type checking fails: because the real world is chaotic, and when you have to interact with that real world, you are often forced to do so dynamically, because of the mistakes that other companies have made. The real world is dynamic.
Re:The advantages of static typing, simply stated by sidlls on Friday September 16, 2016 @10:42AM (#12514309)
The real world being dynamic has almost literally nothing to do with this issue. The concepts are completely unrelated.

Although I'd agree that I find development with dynamically typed languages a bit more chaotic than static or strongly typed ones. And not necessarily in a fun, good way, either.

Re:The advantages of static typing, simply stated by mamon on Friday September 16, 2016 @10:19AM (#12514160)
Ok, so they created a problem by using JSON without schema.

Now, instead of fixing problem by enforcing some schema you propose to use dynamically typed programming language which won't solve the problem but instead will make it spread thorough the whole codebase.

At least static typing limits the damage to the code that directly deals with parsing JSON.

Re:The advantages of static typing, simply stated by oldmanjay on Friday September 16, 2016 @10:36AM (#12514279)
You're insisting on an assertion that the experience of many of us directly contravenes. It's not the best way to make a point.
Re:The advantages of static typing, simply stated by BasDirks on Friday September 16, 2016 @10:14AM (#12514116)
The way you talk about static vs dynamic suggests that you only have a very vague idea of what these mean.