How to read the codes written by other programmers?

 

Hello everyone 

Some times people ask me to edit their EAs.

I have built lots of EAs before but when I see a code which is written by somebody else it's difficult for me to read it. 

It takes much, and I always afraid of missing some small but important thing.


So please share your experience about:

+how you read  the codes? 

+how much it takes for you to read a program in average ? (let's say 3000 lines, of course I'm not expecting a certain answer )

and any useful information or tips/tricks related to this question.

Thanks

 

Certainly, sometimes it's difficult to read programs written by others.

I usually convert the format to my favorite type and sometimes I remove the extra parts which do not need to run it.

I use "UniversalIndentGUI" as a tool for that.

The time it takes depends on the level of difficulty of the program, so it's hard to say.
 

er... intuition? LOL

But really, there are many variations here, depending on how that piece of code was written - how it was formatted, how modularized, how well commented, how buggy, am I going to do minor fixes or adding major capability, etc. etc. And the steps to take to understand/prepare the code will be different for different scenarios, ranging from zooming in straight (by something as simple as a string search) to reading line by line carefully.

Any attempt to re-apply the same strategy used for certain scenarios to other scenarios may be inefficient and/or overkill.

 
+how you read  the codes? 

I add relevant comments. Comments are free. A comment will tell me at a glance what a section is doing such that I don't have to dig into that code again (unless it doesn't work). Most of the code I get from the codebase is sparse on comments.

Often I rename variables & functions to meaningful (or more meaningful) names.

 
Naguisa Unada:

Certainly, sometimes it's difficult to read programs written by others.......

Seng Joo Thio:

er... intuition? LOL

But really, there are many variations here, depending on.....

Anthony Garot:

I add relevant comments. Comments are free....

 Naguisa Unada ,

 Seng Joo Thio,

 Anthony Garot

Thanks for all your suggestions .

Can you give me an example of your experience, so I can compare my speed to the others, cause when I'm going to accept a project I need to know , if it was another programmer how much was his/her estimate reading time. Examples like " once I had a project with 3000 lines of code and I read it in .... hours/days.  I agree with you that it is 100% depends on the codes , but examples can help a lot for now.

thanks

 
Examples like " once I had a project with 3000 lines of code and I read it in .... hours/days.

An example: An EA from the code base, about 500 lines.

It took me about 5 to 10 minutes to find and understand the strategy.

It took maybe a 1 to 1.5 hours to fully digest and "clean it up" to a point that I understood every detail of what the EA was trying to do.

A different example: An EA of around 1700 lines.

Although 3X the lines of code, this was much better written, so it took about the same time to fully understand it.

 
Anthony Garot:

An example: An EA from the code base, about 500 lines.

It took me about 5 to 10 minutes to find and understand the strategy.

It took maybe a 1 to 1.5 hours to fully digest and "clean it up" to a point that I understood every detail of what the EA was trying to do.

A different example: An EA of around 1700 lines.

Although 3X the lines of code, this was much better written, so it took about the same time to fully understand it.

 

Thanks a lot Anthony Garot

Now I know that I'm too slow at it and should practice for improve my code reading skill. 

thanks, it was very good help

 
Reza nasimi:

I agree with you that it is 100% depends on the codes , but examples can help a lot for now.

Sounds contradictory to me.

Anyway, if I say that I need 1 full week to fully understand a 3000 lines of codes, what would you make of that? I could be a rookie and claim that code to be extremely complex... but I could also be very experienced and meticulous about doing my job right that I preferred to spend more time on it. My point is that such information is completely meaningless when you don't know any details about the code, and you don't know anything about my experience and programming proficiency.

If some numbers is all that you're look at now, then my suggestion is you compare with yourself - if you needed 1 hours before, target for 30 minutes in future if you encounter similar codes, that's how you'll improve, without being affected by subjective figures given by people you don't know.

 
Seng Joo Thio:

er... intuition? LOL

But really, there are many variations here, depending on how that piece of code was written - how it was formatted, how modularized, how well commented, how buggy, am I going to do minor fixes or adding major capability, etc. etc. And the steps to take to understand/prepare the code will be different for different scenarios, ranging from zooming in straight (by something as simple as a string search) to reading line by line carefully.

Any attempt to re-apply the same strategy used for certain scenarios to other scenarios may be inefficient and/or overkill.

OK , I should say I agree with you, however who answers here has also a profile here and I can read some of his/her posts to see who is this person.

Most of us are working alone then in some subjects (like speed of code reading - sorry for poor English) we can't see how the others are working, and in some cases this information seems to be necessary. 

and it is not something countable or measurable, then of course question and answers can not be precise. 

No, the Numbers are not "All" I'm looking for. I'm trying to get more close to the answer.

BTW Thanks for your response and suggestions. 

Reason: