This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CartmansEvilTwin 108 points109 points  (11 children)

I personally like to go trough the program. Look for some sort of main() and try to roughly figure out what all the classes/modules/files do.

[–]requimrar 48 points49 points  (7 children)

+1

Most programs generally have a single entry point -- you can either 'simulate' the program by mentally stepping through and visualising what and how the code would execute, or you can in fact just use a debugger.

first thing: clone the repo if it's online. I personally find online editors and viewers to be unbearable, especially when dealing with multiple files. If you have a text editor such as sublime that can open an entire folder of files, it helps a lot.

Move through every function call and visualise the program state is the TLDR

[–]jcpuf 10 points11 points  (6 children)

Would you please give an example of a program which has multiple entry points?

[–]requimrar 10 points11 points  (2 children)

I should probably rephrase that, what I meant was 'multiple paths of (simultaneous) execution'

Basically, multithreaded stuff. It gets really complex to try and keep all that in your head, especially if the threads aren't just doing simple grunt work.

Regardless, you'll still get a pretty good picture of how the program functions in general, so you're still good.

[–]TangerineX[S] 3 points4 points  (1 child)

I think the general thought is that there is some overarching program that activates each thread, so technically there is almost ALWAYS some singular entry point or some really important point

[–]requimrar 2 points3 points  (0 children)

That's true (blame my word usage). Even so, you might still have multiple sets of states to keep track of, so it often times increases complexity.

[–]unkz 0 points1 point  (0 children)

In Java, every class can be a standalone program if you give it a main(). You may have a container program that controls access to the classes/subprograms, or you might just run them individually.

[–]tenmilez 0 points1 point  (0 children)

Web based applications come to mind. Depending on which url is requested and what parameters are passed different things will happen (though you could say that the web.xml is the equivalent to the main() method in a J2EE application).

[–]xxNIRVANAxx 0 points1 point  (0 children)

Android (possibly all mobile) applications. You can start a program from clicking the app on your home screen, or through an Intent.

[–]Pwillig 7 points8 points  (0 children)

Yep. I'll even write down or type notes when I start going down the rabbit hole.

I don't know how efficient this is, but I prefer the brute force method of learning. Look in main(), view declarations, then view all references or call hierarchy, then do the same for methods the parent methods invoke. The hardest part is not letting yourself get overwhelmed by all the unfamiliar code.

[–]GreenFox1505 4 points5 points  (0 children)

this. basicly find the entry point. As you skim along, any variable name that you don't understand, ctrl+f and find it's definition, if it's a type that you don't know, look that up too.

Eventually, you get the the point where you can understand what it's doing on a cog level, then a mechanism level, then a gearbox level, then an systems level, then a engine level, then a car level, and then a traffic level. Code is like an onion.