4 ms·
I think the problem in your example is mostly related to the fact that Java syntax is just horrible for dealing with JSON - not really an issue of typing. If J
by jomamaxx 10y ago
I think the problem in your example is mostly related to the fact that Java syntax is just horrible for dealing with JSON - not really an issue of typing.
If Java were conceived of today - I think it might look a little different with respect to this.
I'd like to point out that there are many areas wherein fluid typing might help a little bit, especially on the UI.
Have to make a class for 'every little thing' gets cumbersome.
I wish there was a 'lighter typing' opportunity in some cases (schema-ish JSON).
But I agree that in the long run, static typing is really the way to go for the most part.
- empath75 10y agoElm is similarly awful at decoding json, and was what stopped me from trying to use it. I mean, it'll get the job done, eventually, but it's just so much additional work, compared to just json.loads() in python.
- danneu 10y agoI'd say working with JSON in Elm is pleasant and simple, but it does require familiarity with parser combinators. It's a common challenge for Elm beginners.
- tdb7893 10y agoJava is fine at decoding Json if you know what the fields are going to be. It's not like creating an object with the fields you want is very difficult and then libraries will deserialize it easily. It's also not hard to create a tool that will generate a POJO class from a string of Json. It doesn't really take time so the only problem is that it is yet another class on the classpath
- jomamaxx 10y ago"Java is fine at decoding Json " It does the job but it's not nearly as nice as javascript or python. It's about double the code in Java and it doesn't read nicely. I think it depends on what you're doing.
- tdb7893 10y agoJava definitely makes it harder to work with json but the only problem I run in to is that I need classes (which I just autogenerate) for every json object. Serializing and deserializing json is a one liner once you have classes set up for them to deserialize into. Again, it is definitely harder than in Python and Javascript but I work with Java and json every day and it's generally only a huge difficulty if you need a strange edge case. EDIT: also, java is bad at dealing with json if the api could return data in multiple different schemas and you don't know which one it is until you parse it but I've only run into this once and it's just bad API design.
- jomamaxx 10y agoAh, yeah, if you have known-entities ahead of time it's no problem via serialization. Developing/experimenting/scripting is where it's painful.