4 ms·
This is an extreme example of something I’ve found to be quite common: programming “types first”. For another example, I recently read a tutorial on parsing tha
by pansa2 7y ago
This is an extreme example of something I’ve found to be quite common: programming “types first”. For another example, I recently read a tutorial on parsing that started by defining `abstract class AstNode`, followed by multiple concrete derived classes. Only after ~100 lines was there any actual parsing logic.
My approach would be the opposite - start with the logic, using built-in types, and maybe refactor to use custom classes later. Perhaps there are downsides to this approach, but it’s how I think about solving the problem. I’ve found this style of programming is easiest in languages that have powerful, flexible built-in types, which seem to be best provided by dynamically-typed languages.
- marcosdumay 7y ago> My approach would be the opposite - start with the logic, using built-in types, and maybe refactor to use custom classes later. That's how you discover what abstract logic you need. And then you implement that logic types first, because it's abstract, so the types are both enough to describe the functionality and much easier to reason about. And you go and refactor your old code by following the types (or the type errors, if you are more in the let the computer do the work mood). But I have no idea how to do that in dynamically typed languages. AFAIK, they hinder refactoring as much as they can.