How do programmers find the correct files and lines of code to edit in an open source project when they want to add or improve functionality.


How do programmers find the correct files and lines of code to edit in an open source project when they want to add or improve functionality.

In: 58

Generally a programmer will be able to read the code and work out where would be best to add in new functionality. Most projects are documented either in the code itself or in separate documentation, so it’s easier to find which bits of the codebase do what.

Well, a good OSS project will have their source structured in a way that makes sense.

So it could be by layer (a folder for everything that does DB access, a folder for business logic, a folder for UI, etc.), by feature/components (a folder for the dropdown, a folder for the toggles, a folder for the cards, a folder for the router, etc.) And so on and so forth, but it is usually quite easy to get a grip on the organization and get a rough idea about where the change needs to be made.

Once you drill it down to a couple of files, the classes, methods and functions should have relevant names that help to find a good starting point to explore the code itself.

You don’t really need to find the entry point of the feature (i.e., the first bit of code executed for that feature), just something that’s probably executed most of the time the feature is used. From there, you can look at what calls and is called by it to pinpoint what you need to change.

Also, nowadays, most of the time, unit tests and documentation will help to find the correct file and function.

It can be difficult sometimes. If you’re taking the time to contribute updates, it probably means you use the code and get to know it.

Worst case, you have the code on your computer, open it in your development environment and run the code in debug mode. You can then walk step by step through the code while its running to see how it works.

A good code base will be organized. If you want to change something regarding the database the folder marked “Database” (or aliases thereof) is probably a good place to start looking.

If you’re lucky the project will have proper documentation which you can simply read and that will point you to the right direction.

If that doesn’t work but you know where the functionality is being used you can find those spots, see what functions are being called, and find where they are defined.

And if the worst comes to worst just do a text search for keywords you think will be relevant is always an option. There are only so many places that “database” or “db” or “select” can appear. Pick the right keyword to narrow things down, and manually check each match manually to see if it is what you need.

“Finding the correct lines” is then just a matter of reading the code and understanding what it does. Code isn’t just random symbols with no rhyme or reason: a programmer simply reads it and figures out what it’s doing, and from there decides on what needs to be altered or added.

Same way that you would find the right recipe in a cookbook. You’d know roughly where to look anyway (i.e. you wouldn’t be looking under roast dinners if you were baking a cake), you would expect it to be sectioned out nicely so you can find stuff, you could search through things if you needed to, and – with code – you can do stuff like load it into a development environment (IDE) and use its features to find the things you’re looking for.