Really good. Think about the programmer reading this at write time.
How to write large code bases that can be understood, every bit as important as knowing how to read them
Software Engineering at Google has lots of valuable advice and best practices to accomplish this - https://abseil.io/resources/swe-book/html/toc.html
Re:Grokking Big Unfamiliar Codebases
by guntherhermann on Friday January 27, 2023 @05:09AM
(#34544443)
I agree, when learning new codebases, the ones that take me the longest time to learn are the ones with many layers of indirection.
I view over-indirection as an anti-pattern and I often see it come from engineers who take the DRY philosophy as dogma.
I have seen countless cases of your second example throughout my time programming, and I'm convinced it comes from the DRY mantra that first-year CS students get drilled into their brains.
DRY is the easiest rule to tell if you are following, so it is one that people are inclined to follow.
Best example of "good practice" becoming a hassle: the "interface for everything" habit. Even when the majority of those interfaces have only one implementation.
Re:Grokking Big Unfamiliar Codebases
by JamesonNetworks on Friday January 27, 2023 @07:55AM
(#34545448)
I can't stand this. I once worked on a project where there were seven layers of interfaces that all led down to a wrapper around a library and each step was just adding another parameter onto the call in the library. The entire PROJECT didn't need to exist, the owning project could have easily just called the library directly as it already had all the context, maybe with one method to abstract in case we needed to swap the underlying library. I remember thinking I was a bad developer for not "getting it," but armed with 10 more years of experience I've realized it wasn't me.
Re:Grokking Big Unfamiliar Codebases
by patrickthebold on Friday January 27, 2023 @12:56PM
(#34549361)
I've come around on this one. I (now) like having a separate interface, having just method signatures separated out makes it easy to get an overview of the class. It also makes it a bit easier to agree on the interface.
Re:Grokking Big Unfamiliar Codebases
by yCombLinks on Saturday January 28, 2023 @12:28AM
(#34555433)
You have an interface already, without separating it from the implementation: the public methods of the class. In java any IDE will quickly give you the class outline showing you the public methods.
omg yes. This is my single biggest complaint about large Python projects, or anything with complex implicit type conversions. Fun to write, a nightmare to read.
Re:Grokking Big Unfamiliar Codebases
by tengbretson on Friday January 27, 2023 @04:10PM
(#34551912)
Especially in languages with string literal types! There's no excuse not to just have the thing be the thing when the type system can do the heavy lifting of preventing typos.
A couple of examples:
This pattern doesn’t do anything particularly wrong other than anyone on a code safari shoe arrives at f will find it doesn’t contain the symbols for either Swimmer or Skater. Sure, ACTIONS is only a hop away, but what if the class name was derived from a string?The fact that the action implementations are chosen at runtime also makes life a bit awkward but the primary issue is not being able to immediately see what actions there are, nor be able to jump to their implementations.
Another one is calling shell scripts. We all have projects, I’m sure, where we have to shell out to some common legacy tool:
The simple act of wrapping the script in a native function does wonders for making it easier to find, especially for the poor, sacred soul who deprecates it from the codebase one day: Any unfriendly pattern that breaks tag-hopping / IDE-integration is yet another small chafing of your colleagues‘ productivity. Think twice before you introduce that YAML file which defines behavior, instead of implementing it natively — your friends (and their jump-to-definition muscle memories) will thank you.