Tag based programming

programming practices

I don't know if this is a thing but here's a silly idea. Often there are cases when you have to refactor code such that you need to change code pertaining to some particular area. This may involve changing functions or variable calculations spread across multiple files. Let's say I tag these places with a comment saying "tag server_path_calc". When the time comes to refactor or change the server path access logic, I can just search for these tags and make changes quickly rather than thinking "Hm What else I need to change where?". Does anyone follow this kind of strategy in programming?

A somewhat concrete example is:
Let's say I have a binary repository whose path calculation depends on some variables. Now this calculation is used by some python scripts and also some CMake files. I tag wherever I access these paths as "# tag repo_path_calc".

Will this be an efficient process? Are there any productivity tools to do it.

When variables are multiple, it becomes hard to find/search and refactor across files unless you see what broke (via unit or manual testing) and continue to fix it.

Another example if it helps.
The problem I pose is of search/find/refactor cycle, not code organization. Lets say I have an online repository (such as Maven/Nexus) to store binaries.

  • A python module is responsible for upload/download of artifacts segregated into a class
  • There are some tools who do path calculations and use this module above to transfer binaries
  • There is a CMake build system which produces artifacts and meta data used for forming paths for this python module to use.
  • Now there is a C++ application which could also access this online repo and download some application data (meshes, resources, images etc).

Now the online repo path changes (or the organization of the repo changes). Now I want to track down all different pieces of code which have this sort of access to the repo. How would you do it? You would search for these well named classes/variables and hope you reach all of the related code? I was just doing a mental experiment (silly as i noted) to see if comment tags can be used to track all these changes across multiple scripts/languages/modules. We tag content all the time, we also tag lets say commit descriptions to segregate them into "chunks of a particular implementation" for SCM software like Perforce. In code, yes we do have code organization but everyone starts with a "search" button right. In my case not everything is in one IDE/language.

Best Answer

When you are working on a code-base where you seriously consider this a good idea, it's a sign that you might be working with a horrible mess of spaghetti code.

In a well-organized codebase such tags should not be necessary, because each of these functionalities you mention should be contained in a single place. Components should be encapsulated and loosely coupled, so that you can change the way the path to some binary file is generated without having to change any other code.

Related Topic