How Do You Understand How A Program Works? How Long Does It Take?

Hey guys. I’d like to start a discussion of sorts (or at least ask your guys’ advice on the subject):grinning:.

What do you think is the best way to understand the ins and outs of a program that you didn’t write? Especially if the code is long and convoluted and the variable names make absolutely no sense…

I ask because I’m currently trying to reverse engineer some YouTube JavaScript code to figure out how certain functionality works. My strategy so far has been to search for keywords indicating significant purpose for what I’m trying to analyse (which, again, are few because the variable and function names make no sense) and then go backwards from there, trying to figure out how all the interconnected parts work.

I take notes on what I find and why I thought it was significant, but as the notes get larger and I discover new information about the things I already wrote about, I find it more and more difficult to keep everything organized.

Perhaps it doesn’t help that I have numerous sets of notes for different parts of the program. This is because the file I’m analyzing is hundreds of thousands of lines of code and there are a few interesting keywords I found very far apart from eachother, so I was analyzing each of them and the code surrounding them separately.

How would (or do) you, reader, go about solving this problem? Are there any useful tools that could make this process easier?

This is a tricky question because it really depends on how the project is structured and how well the code is written.

In my first job I worked on a huge and poorly written AngularJS project which took months to get to grips with. Even then, I didn’t feel confident about doing major refactoring.

In my current job, we use the standard Angular CLI project code. The architecture is predictable and the code broken up into modules and small manageable components. With this project, I could start working on the first day.

If a project is well designed, you should not need to understand the whole code base. It should be possible to find the module or component or class that you need to work with and pretty much ignore everything else. But in order to do this, you do need to understand the overall structure of the project.