4 ms·
> Can you give a specific example where you think you need dynamic types? The diff operation you described sounds like it could be made generic pretty easily.
by duaneb 10y ago
> Can you give a specific example where you think you need dynamic types? The diff operation you described sounds like it could be made generic pretty easily.
How do you figure? This would require macros or runtime type introspection.
A specific example might be "serialize this json type without having to annotate the fields with how to serialize them".
- wyager 10y ago> This would require macros or runtime type introspection. Not if you structure your data using an appropriate data structure, like a map. After all, this is all structs in dynamic languages are. > A specific example might be "serialize this json type without having to annotate the fields with how to serialize them". Aeson does this safely and statically using Haskell's powerful static Generics. data Foo = Bar Int String deriving (Generic) instance FromJSON Foo instance ToJSON Foo You can get named fields like data Foo = Bar {baz :: Int, qux :: String}
- duaneb 10y agoMost static typing systems have no parallel to 'deriving', which is to my understanding compile-time computation (aka a macro).
- dllthomas 10y ago"deriving" is compile time; "Generic" is runtime inspection of the shape of a value (in terms of constructor applications). Something (at least vaguely) similar to Generic exists in many statically typed languages - including (IIRC, IIUC) Java and Go.
- duaneb 10y ago> Something (at least vaguely) similar to Generic exists in many statically typed languages - including (IIRC, IIUC) Java and Go. Sure—but it's in spite of static typing, not because of it. You certainly give up any guarantees of avoiding runtime errors by detecting typing issues at compile time.
- dllthomas 10y agoSure, it's orthogonal to static typing (I wouldn't quite say "in spite of"). I wasn't trying to weigh in on the general topic, just to clarify what was happening where.
- Roboprog 10y agoTrue, but "batshit conservatives" won't do that, or will mess themselves if you do that, rather than making some kind of "Object-Whatever-Mapping" model and annotations. But that's what I would do (at least in Java) for this kind of transient transfer object, if left to my own devices. https://plus.google.com/110981030061712822816/posts/KaSKeg4vQtz https://plus.google.com/110981030061712822816/posts/KaSKeg4v... (I would put myself in the "moderate liberal" camp, even if the languages Steve Yegge lists for that group are not my choice languages)
- imtringued 10y ago>A specific example might be "serialize this json type without having to annotate the fields with how to serialize them". https://manosnikolaidis.wordpress.com/2015/08/25/jackson-without-annotations/ https://manosnikolaidis.wordpress.com/2015/08/25/jackson-wit... That is a property of the library not of the language.
- Roboprog 10y agoThere are some wrapper utilities for Java around reflection for property access, but yeah, it's still pretty clumsy.