News for hackers. Stuff that matters.
Re:Grokking Big Unfamiliar Codebases by gorgoiler on Thursday January 26, 2023 @10:54PM (#34542254)
It is incredibly important to avoid putting tag-firebreaks in the code base — anything that stops a new developer from being able to navigate from symbol to definition, or from definition to all uses of that function.

A couple of examples:

  ACTIONS = {
    “swim”: Swimmer,
    “skate”: Skater,
  }
  
  # …pages of code…
 
  def f(action, *args):
    …
    mod = ACTIONS[action]
    mod(*args).do()
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:

  def f():
    run(“legacy.sh”)

  def g():
    run(“legacy.sh”)
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:

  def f():
    run_legacy()

  def g():
    run_legacy()

  # …pages of code…

  def run_legacy():
    run(“legacy.sh”)
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.
Re:Grokking Big Unfamiliar Codebases by worik on Friday January 27, 2023 @12:01AM (#34542671)
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

Re:Grokking Big Unfamiliar Codebases by Denzel on Friday January 27, 2023 @12:21AM (#34542795)
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.

Re:Grokking Big Unfamiliar Codebases by afarrell on Friday January 27, 2023 @07:37AM (#34545306)
DRY is the easiest rule to tell if you are following, so it is one that people are inclined to follow.
Re:Grokking Big Unfamiliar Codebases by arkh on Friday January 27, 2023 @07:43AM (#34545367)
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.
Re:Grokking Big Unfamiliar Codebases by wilburm on Friday January 27, 2023 @07:07AM (#34545131)
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.