Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One spot where I think that dynamic typing shines is dealing with anything from the schema-on-read approach to things, including reading JSON.

In Python, for example, you can just parse your JSON or XML into a dict and start grabbing what you need, typically with fairly minimal hassle involved in dealing with things like missing values or some clown sticking a string into a field you thought could only contain ints.

In Java, by contrast, ugh. You can laboriously litter your code with a whole mess of bean classes and have Jackson take care of the parsing. But if you want to obey Postel's Law, this quickly turns into a foamy quagmire of beans and annotations and whatnot that's at least an order of magnitude larger than the code that actually interacts with the input, and still throws an exception the moment someone populates the timestamp field with ISO 8601 instead of seconds since 1970/01/01. Or leaves it unpopulated. Or alternatively you can ask for a Map<String, Object>. That approach isn't actually any more strongly typed than what a dynamic language offers, but it does have the advantage of justifying the price of that fancy ergo keyboard.

I'm not a big dynamic typing fan overall, but I do think that the .NET folks were on to something when they added the DLR extensions to .NET and gave us ExpandoObjects.



I actually disagree here. I can't speak to Java, but dealing with JSON in Python is actually pretty tedious compared to Go. For example, with Go, if I have a type `Person struct { Name string, Age int}`, I can pass that to `json.Marshal()` (the Go equivalent of `json.dumps()` in Python) and it will render the expected JSON. In Python, we have to marshal everything explicitly (with a `to_dict()` method or equivalent).

And Go isn't even a particularly good example of JSON handling in statically typed languages; OCaml, for instance, does a much better job.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: