Jump to content

Need example code with step by step explanations


OM2

Recommended Posts

I know how to code

I don't need to learn about arrays and sorting and other things

 

But... when I look at code, I just get lost!!

I don't know what the heck is happening

It all seems daunting

 

Where does this function relate to? Why isn't this variable declared somewhere? What does this line do??

 

Is there anywhere I can find code samples that give a line by line explanation on everything

+ More and more complex examples - leading onto using Object Oriented code and frameworks

 

Thanks

 

 

OM

Edited by OM2
Link to comment
Share on other sites

I think that you should find the PHP manual a very good resource for your questions, especially the function reference section.

 

As far as not needing to learn about "arrays and sorting and other things": That is exactly what you need to learn about, especially basic variable types such as arrays. Saying that you don't need to learn about them is like saying that you don't need to learn about grammar or syntax, but that you still want to learn a foreign language.

If you're daunted by the code, and cannot see the relationships between it, it is (most likely) because you're too unfamiliar with the syntax and vocabulary. The only solution to that, is to read more up on it, get to know it even better. Once you've learned it well enough, reading code will be like reading a second natural language. More or less, anyway. ;)

Link to comment
Share on other sites

Learning to read code is a skill in itself that needs to be learnt. In a lot of cases, just because you can write code does not mean you can read it well.

 

What most people do is skim over the code too fast because they just want to figure out how a particular part works. They might skim the code beforehand. This can ofte trip you up.

 

The first thing I always do is try and locate an (execution) entry point. Where does the execution of the piece of code I am looking at start? From there, you simply follow the logic (slowly) all the way into (and through) the part you need to understand. I'll usually do this a few times making sure I understand each block as I go. If I hit a point where I am lost, go back up a bit until you find your (execution) path.

 

With practice, this process becomes quicker. Make sure though to always stop yourself from skimming past parts you think you understand until you truly do understand them.

 

This process works for small blocks of code all the way up to larger more complex systems. Find an entry point and follow it.

 

I thought I was reasonably good at this skill until I started working where I am currently. Our code base is currently over 2 million lines of code in several different languages spanned across two svn and several git repositories. Nothing is documented at all. I would read more code in an average day than I would write and it is VERY common for me to need to wonder into some part of our applications or libraries that I have never been before. There are guys at work that you can ask for help / advice, but there is no one there that knows the entire system well enough to get you through all situations. Hell, if we spent all day asking each other how different shit worked we would never get anything done anyway.

 

Reading code is a very important skill to have. I actually think a lot of developers under estimate its importance.

 

ANyway, to answer your question. No, your not likely to find some walk through that instructs you how some code base works. To read even the best documented code you still need the skills to be able to follow the execution path. You need practice, there are no short cuts.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.