Good Code as a Data Structure

Hayden Rear - Sep 8 - - Dev Community

What do the frameworks have in common? How do you rectify the divide between object oriented and functional? How can we write code that can be provably correct, logically? One thing that has come up is modeling the "data", and even modeling a data structure.

So when we write code that performs some actions, we want to prove that it performs the way we want it to in all cases. But then the number of cases grows to be out of control, resulting in wild edge cases. How to simplify? We make it a data structure that satisfies the needs. So then we only have one of iterate, add, remove, etc, and then we can add hooks into this data structure, such as afterAdd, afterRemove, postConstruct, and then we can build out our program as nodes that get added and perform behaviors after being added, removed, etc.

One thing that's become viral is this idea of "hooks". We hook into the behavior in a way that we can prove. I argue that this is just that - a data structure that we hook into.

So putting this together, we have a data structure that we can prove, and then we add hooks into that data structures behavior that we can prove things about. The nice thing about this is that it allows for the logic to be refined at various levels of the hierarchy, allowing reuse of the code and the logic to be refined correctly.

. . . . . . .
Terabox Video Player