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.

2.17K views

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

34 Answers

Anonymous 0 Comments

Computer programs are, in many ways, complicated machines.

So imagine you’re an engineer and someone asks you to fix their airplane. It handles funny when banking left.

First, before the plane even rolls into the hangar, you need an overall understanding how airplanes work in general. In this analogy, knowing the programming language is just basic engineering: which way to turn a screw, what does a washer do, how to weld two pieces of metal together.

To be of any use, you need to gather _domain knowledge_. You need to know that an engine is called “engine” and in which places you can usually find it, what are “flaps” and what they do, what happens when a “rudder” breaks.

An experienced aerospace engineer will already know the path from the cockpit to “airplane turns left”, and can imagine a list of places to look for a problem.

But you’re a novice. You realize that looking into the in-flight entertainment system would probably be a waste of time, and that the landing gear controls are unlikely to be involved. But beyond that, you can’t be sure.

Start with what you know: if you push the control stick to the left, the plane should go left. Control surfaces will move, something something airflow. Do they actually move as they’re supposed to? Is anything else moving? Is it different from what happens when you push to the right? Maybe the movement is restricted somewhat?

Then you can look deeper. Follow the wires and pulleys. Sooner or later, you’re bound to hit a spot where maybe two parts grind against one another. Hooray, that’s it!

Now, how to fix it? You could replace one of the parts, or maybe both. But maybe that’s not the right solution. Keep the whole system in mind. Perhaps something two steps earlier is wound too tight. Or maybe someone tried to compensate for another problem and this was the result. Think it through: what is the best way to make the whole work better?

Sometimes making a tiny tweak in the cockpit will solve the problem in a satisfactory way. Other times, it might be best to throw away the whole sequence and replace it with something different. It is more work in the short term, but it will make everything easier in the long term.

In conclusion, again, programs are a lot like machines. You need to understand a big enough part of the machine to know where the problem lies and how to fix it. Knowing “what file and which line” flows from that. To start, you can tell from the filename whether that’s “definitely it”, “definitely not it”, “maybe” or “unknown”. If everything looks “unknown” , just pick a file, understand what it does and follow the code to other files, until you have an understanding how the thing fits together.

Anonymous 0 Comments

I work in huge projects and it’s really simple how we do it. (Wish I knew a better way though).

I just open up the project, start search all files and start guessing the names of methods or classes that are connected to what I want to change.

If I can’t find anything I usually go looking in the data access layer for anything that looks related to what I want to change and I go up from there where the methods are referenced.

Anonymous 0 Comments

The real trick, which only comes from experience, is being able to read code for the intent. This allows you to build a low resolution idea for how a large system works, and only improve the resolution in the parts that matter to you.

To find a starting point for what to read I look for keywords that I can search for, then try to understand the system around that point enough to make a change.

For web ui, I inspect the element, at or near, where I need to make a change. Then look for unique looking ids, class names or attributes. That will usually help me zero in on the code that needs to be modified.

For http back end projects, I usually start by looking for url path parts. Then I should be able to trace that specific endpoint’s logic to understand the change.

For more ETL work, I’ll look for a unique looking table or column name from a database schema. That should show me where that data is being used in the code.

Anonymous 0 Comments

You read the code, building a mental map of whats calling what. And eventually you feel like you understand it well enough that you add a line.

If you want to find where to start you should find an ‘anchor’. Find something you do know that is as related as possible and work your way through it. Could be a text line or an api call.

Also if you can, debugging helps a lot.

Anonymous 0 Comments

There is a lot of talk here about proper structure, descriptive naming conventions and such. Personally, I get drunk and poke things.

Anonymous 0 Comments

We learn how to filter / drill down to places we’re interested in.

For example, take a deck of cards, and then I told you to find the Queen of Hearts.

Your eyes would probably chuck out any black cards, any numbers you first come across. Then check suit, and then finally if it’s a Queen.

Similarly in code, we’re usually looking for something specific. And we can trace it down from package/folder structure/class name / function name / line of code.

Anonymous 0 Comments

Varies on what the code base is, and probably on the person.

I’m almost always end up doing a find in files search from a code editor at some point. The keyboard shortcut is ctrl+shift+f / cmd+shift+f. Before doing any major code changes I’ll add something like “hello world” to prove the code in changing will have an effect at what I’m looking at.

So basically I do a keyword search on all the code. Then change something little to see if I can see that change.

Anonymous 0 Comments

Having learned c# on a project with poor code and variable naming… It’s takes time and patience. In our case the code was not the original source but as we reverted the exe back to source. It was a mess. After years of work it was greatly cleaned up.
This is not the kind of project you want to learn on unless you have someone who knows what the code should look like. A mentor familiar with the project. Which I had. I can not stress enough how important a mentor is when learning code.

There is a lot more to coding than just code.
Code readability is very important especially in large or multi person projects.

If the code is running under visual studio or something similar, there are mapping tools that will show all the ways the code interacts. I didn’t find this useful but it can be useful.
https://docs.microsoft.com/en-us/visualstudio/modeling/map-dependencies-across-your-solutions?view=vs-2022

Else setting break points and watching the code run was how I did it. Even then I found later there were better ways to do it and rewrote what I did.

Well structured easy to read code makes a huge difference. The entry points become not only fairly easy to find but the structure can show how new ideas can be implemented. I believe the process is similar though. Time and patience and watching the code run in source.
A really stellar intuitive coder can just look at briefly and see what to do especially if it’s structured in a way that makes sense with good readability.

I highly recommend checking out game programming patterns.
https://gameprogrammingpatterns.com/

The concept is that code structure has been thought about a great deal. If the code was written with good patterns then once you become familiar with the patterns then you just know how it works and where things should be.

I think the eli5. Code can be written with known patterns. Once you know the patterns then you can look at code using those patterns and it just makes sense. Like maybe using a ladder. Once you know how the ladder works you don’t need to know what you are carrying up the ladder to know how to go up the ladder. More or less.

Anonymous 0 Comments

It’s all about the tips and tricks each individual knows.

Imagine when someone is having a hard time explaining something and when you finally get it you reply with a short summary that simplifies the whole explanation.

Programming is a language at its core so it works much the same, but first you have to follow three lines to get an understanding of what they mean.

Anonymous 0 Comments

Here’s an alternate approach. You’re presented with an error message that occurs in a situation you might be able to fix. Sometimes you can search the whole code base for (part of) that error message. That often lands you in the neighborhood of what you’re looking for.