4 ms·
This is approximately the same reason as why I start out writing most of my programs by creating a bunch of types, and why I find dynamic programming languages
by barrkel 14y ago
This is approximately the same reason as why I start out writing most of my programs by creating a bunch of types, and why I find dynamic programming languages uncomfortable to use.
I'm less and less a fan of the ceremony of object orientation, but I think there's a lot to be said for having a succinct formalized statement of your data structures up front. Once you understand the data structures, the code is usually easy to follow. The hardest times I've had comprehending code in my career, apart from disassembly, have been from undocumented C unions.
- antidoh 14y ago"This is approximately the same reason as why I start out writing most of my programs by creating a bunch of types, and why I find dynamic programming languages uncomfortable to use." Classes. There are your types. Python has them. Ruby has them. Javascript has them. . . .
- barrkel 14y agoIf you can't see see the qualitative difference between algebraic data types and Javascript classes, there's no point discussing things.
- dasil003 14y agoJavascript only has Objects not Classes.
- antidoh 14y agoThanks, I stand adjusted. And of course you can use prototypes (objects) for the same intent as classes, which was the source of my error.
- hcarvalhoalves 14y agoData structures != Types Dynamic languages are not an argument to make bad use of data structures in any way, it changes nothing.
- barrkel 14y agoI think you missed my point. I wasn't arguing against bad use of data structures; just for a formalized, checked description of the data structures used in the program. I have in the past written preprocessors for this purpose. A simple language just to describe the types used in the program, with the output being the implementation language's definition of the type, as necessary. I've even done it in Javascript, in a very roundabout way - was JScript.net, producing XML, which was consumed at runtime to create classes dynamically, which in turn were used by a dynamic programming language. I'll go a long way to get a simple up-front map of the program's data in a checked format.
- auggierose 14y agoI totally get what you are saying. I also have the difficulty that when programming in Clojure and starting on a new problem, there is no really good way of writing down the data structure. I still love the flexibility of Clojure, though, so now I am trying to work around this by writing down proper documentation of the data structure instead of representing them exclusively with types.
- tikhonj 14y agoIt sounds like you'd really like Haskell. It gives you a far more succinct way to represent your data. Since the overhead of creating a new type is very low, you also become far more likely to express more of your logic in the types. I always start my Haskell projects by laying out the data types. The type declarations are very readable--you can just skim over them to see what's going on. This means that you can get a very good overview of what the project wants to do just by quickly looking over what types it declared, and then looking through functions' type signatures. Then, after you have the data types defined, the resulting code is not only easier to read but reflects the data operations it is doing. I've found the type signatures above each function--which are optional but highly recommended--really help tie the code back to the data it operates on. Additionally, pattern-matching against the data makes the structure of most functions clearly reflect the exact data it is working on. The low overhead of creating Haskell types also makes it very easy to add aliases to existing types. So perhaps you use a `Map Int String` in your code; you then give it a domain specific name: type IdMap = Map Int String so your functions refer just to that. Then, when somebody comes along and tells you about `IntMap`, refactoring all your code to use `IntMap String` is far easier! So if you really like a more type/data directed style of programming but are getting tired of OOP, you should definitely check out Haskell (or something similar like OCaml).
- olliesaunders 14y agoThis is a very apropos recommendation. I love the way Haskell makes you think like this. Even better I love how you can continue to apply that kind of thinking to programming in any other language.