3 ms·
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
by sidlls 10y ago
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.
- zzalpha 10y agoYup. The correct solution to this is schemas, not throwing away typing information.
- susan_hall 10y agoWe 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.
- BasDirks 10y agoThe way you talk about static vs dynamic suggests that you only have a very vague idea of what these mean.
- mamon 10y agoOk, 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.
- oldmanjay 10y agoYou're insisting on an assertion that the experience of many of us directly contravenes. It's not the best way to make a point.
- sidlls 10y agoThe 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.
- sdegutis 10y agoMeh. 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.
- jack9 10y ago> 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.
- sidlls 10y agoI 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).
- empath75 10y agoHave you worked with a public api in the last few years that didn't depend on json?
- zeveb 10y ago'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.
- asimuvPR 10y agoEvery technology is relatively wrong. Time points out where and we fix it (process is repeated again forever).