3 ms·
I was disappointed to see this line: design patterns – at least most of the patterns in the "Gang of Four" book – make code bases get bigger. This hasn't been
by helmut_hed 15y ago
I was disappointed to see this line:
design patterns – at least most of the patterns in the "Gang of Four" book – make code bases get bigger.
This hasn't been my experience. In fact, learning about and applying design patterns has been a crucial part of reducing code size in previous projects by eliminating copy-paste code. For example, a previous company had a lot of code devoted to traversing a particular data structure and taking various actions at each node. There were multiple variants of this traversal code, each with different actions but also slightly different (for no reason) in the traversal code. Applying the Visitor pattern allowed me to write the traversal only once, reducing code duplication and potential future bugs. I also believe it was more readable.
This was in C++ though - I'm not sure how much of his comments are directed solely at Java.
- gmartres 15y agoIf you had experience in a functional programming language, you'd have recognized this as a fold and written the foldMyStructure function. If your Visitor pattern solution is similar to the example code in https://secure.wikimedia.org/wikipedia/en/wiki/Visitor_pattern https://secure.wikimedia.org/wikipedia/en/wiki/Visitor_patte... then it is certainly longer than the natural solution in functional programming.