SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you learn from other peoples' code?

    Hi guys!

    I am new to Sitepoint, so let me first introduce myself.. My name is Martin Green, as you will have guessed by my username I'm an 18-year old, self-taught PHP-developper looking to make a useful contribution to the world of PHP.

    As you all know, the PHP world is littered with dozens of frameworks, CMS'es and other free applications. Some are good, some not so good. They all do things a bit different then the rest. So, as this is my first time around, I taught; what better way is there to learn a bit about other peoples' views then a good old discussion thread. As I have learned myself, there are different ways of learning from the code created by others.

    For example, you could read the API-reference and just start hacking away. You could also get in-depth by examining all the classes and functions inside these classes. This way, you really gain some insight into the ways somebody else is working.

    Take, for example, the popular Symfony Framework. You could just read the Symfony Book for your version, and assume that everything is said when you've finished the book. You could also take an in-depth look into all the code, which is hard work. This is especially true when the capabilities of OOP have been worked out correctly throughout the code, because there will be a lot of function calls to other objects in the code.

    In summary, I'd really like to get a discussion started based around the question: How do you learn from other peoples' code?

    I hope to recieve a lot of replies so a good discussion can taken place

    yours,
    Martin

  2. #2
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am always learning, and can't contribute to this thread other than: Welcome to SitePoint!

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the forums Martin.

    I'm not really sure as to the direction of your question.

    Do you mean how do you learn how to use specific code (i.e. a framework) or how do you learn about using a certain new technique?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Martin,

    From my personal experience, books teach you basics, but my favorite ways to learn are:

    1) Read every problem on these (or other) forums and learn from the replies. Even if the thread title hints that you already know the subject in question, some people could always post new (possibly better) ideas in that thread to do something a different way, or even to add another interesting aspect to it. You learn a lot from reading a bunch of professionals' opinions, so even if you are pretty sure you know all you need to about the subject, it's always good to take a look at the topics here when you get the time, because there's a lot of good input in them from (in most cases) people whose words come with a guarantee.

    2) It's a great way to learn how to work out complex systems by yourself by, like you said, downloading established (or exciting) frameworks or any type of open-source code and going through it, from the first step of the script to the last (of course, try paying attention to the real stuff, the process, rather than each single function and variable name).
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  5. #5
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I remember somebody giving me that suggestion back in the day. I tried messing around with the idea for a while, but simply reading the code never got me anywhere.

    What i did instead was, rather than simply read the code, re-invent the wheel. Take what was wrote, retype (or copy/paste) it somewhere, and go through the usual development cycle of a program. Debug everything, see why some things work and others don't. For me, that helps to figure out exactly how things work a little better.

    Obviously this approach wouldn't work for a full-scale CMS, which is why i only do it on the bits i'm interested in (i.e. a templating class).
    Mind the gap.

  6. #6
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pick a frame work. The lighter, the better. Start a project and learn while working on the project. You don't have to read some body's codes and how boring that will be.

  7. #7
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I learned a lot from customising Vbulletin for a few years, which isn't to say that I follow Vbulletin's example, but that it gave me a good idea of the way some other people code PHP.

    I also learned from building my own jokes website, following the examples in Kevin Yank's book, and I also learned a good amount from working with some code at SitePoint written by Jules.

    I tend to learn by doing rather than reading or looking at other people's work, so in all these circumstances the real benefit I got out of it was when I myself was working with this code and making it do things.

    I have also learned an immense amount about coding from other sources than PHP or MySQL - for instance I am interested in video and audio codecs, compression and archive formats, HTML and XHTML parsing, etc.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  8. #8
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd suggesting picking an old, successful established project, like media wiki or drupal, and becoming very very familiar with it. These projects have gone through many iterations and have collected the solutions to many problems that you didn't even know you had (yet). Are they perfect examples? There is no such thing as perfect code.

    Lightweight generally means unused. I'd study Zend Framework.

    I'd also suggest picking a few interesting people and then checking out anything they do. I have a short list of people and projects that I follow and check in with repeatedly, just because they are always coming up with some interesting bits of code.

    Learning software based on a doc comment generated API reference is like fast forwarding past the movie and then watching the credits. I rarely find API Reference docs to be the best way to learn about a body of code. What is?

    Throw this at the bottom of your index.php
    PHP Code:
    echo implode(get_included_files(), "\n"); 
    And point your browser to the working app.
    (Use a register shutdown function if the app does funky exits or output buffering)

    Now, use the list and open the files one by one and read the code in context.

    So how would I learn about Symfony if I were approaching it for the first time? First, I'd read over their user manual. Then I'd get an example app going. Then I'd do the trick with included files. Then I'd try to write a more complicated application. I'd join their forums and mailing lists. I'd look at other apps that were available. I'd probably never look at the API Reference except in the code.

  9. #9
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I, on the other hand, have gained immensely by examining the code, structure, and architecture of established frameworks/libraries.

    Ok, PHP Manual does an amazing job of explaining syntax and language structure. But how do you put together disparate pieces to make up an working app? The existing libraries come to rescue. Tear them apart and see how they work, how they are structured etc.. . Don't just do passive reading. Modify the code, run with different parameters/settings etc.. It is also an fantastic opportunity to get to know obscure functions/uses that you never knew existed. If the library has accompanying documentation (most of the good ones do), it’s icing on the cake. Besides, being able to read someone else’s code is an important skill that will come very handy in your career as a programmer. Admittedly, there are moment of frustrations but you’ll be glad that you held on.

    To be on the safe side, study the code from libraries that are known to be of high quality lest you don’t pick bad habits. But then, ability to tell good code from bad one is a separate skill in itself.

    Zend Framework, Creole, SWIFT could be a good start.

  10. #10
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Welcome to the forums Martin.

    I'm not really sure as to the direction of your question.

    Do you mean how do you learn how to use specific code (i.e. a framework) or how do you learn about using a certain new technique?
    I mean how do you learn about using new techniques, for instance: What do you learn from any given codebase in what ways.

    Take, as in my first post, the Symfony project. Do you only implement the stuff they provide you with, or do you also check out the code they've written?

    Quote Originally Posted by CoderMaya View Post
    Hey Martin,

    From my personal experience, books teach you basics, but my favorite ways to learn are:

    1) Read every problem on these (or other) forums and learn from the replies. Even if the thread title hints that you already know the subject in question, some people could always post new (possibly better) ideas in that thread to do something a different way, or even to add another interesting aspect to it. You learn a lot from reading a bunch of professionals' opinions, so even if you are pretty sure you know all you need to about the subject, it's always good to take a look at the topics here when you get the time, because there's a lot of good input in them from (in most cases) people whose words come with a guarantee.

    2) It's a great way to learn how to work out complex systems by yourself by, like you said, downloading established (or exciting) frameworks or any type of open-source code and going through it, from the first step of the script to the last (of course, try paying attention to the real stuff, the process, rather than each single function and variable name).
    This has helped me a lot indeed. I followed a lot of topics here on Sitepoint, which has given me some great insights into what to do in certain contexts.

    I also like how some frameworks do the stuff they do. For example, with Symfony, I really like the routing and configuration, based on contexts and yaml files. And it is obvious that you shouldn't just look at the function names and variables; the API reference exists for the purpose of doing exactly that..

    Quote Originally Posted by Selkirk View Post
    I'd suggesting picking an old, successful established project, like media wiki or drupal, and becoming very very familiar with it. These projects have gone through many iterations and have collected the solutions to many problems that you didn't even know you had (yet). Are they perfect examples? There is no such thing as perfect code.

    Lightweight generally means unused. I'd study Zend Framework.

    I'd also suggest picking a few interesting people and then checking out anything they do. I have a short list of people and projects that I follow and check in with repeatedly, just because they are always coming up with some interesting bits of code.

    Learning software based on a doc comment generated API reference is like fast forwarding past the movie and then watching the credits. I rarely find API Reference docs to be the best way to learn about a body of code. What is?

    Throw this at the bottom of your index.php
    PHP Code:
    echo implode(get_included_files(), "\n"); 
    And point your browser to the working app.
    (Use a register shutdown function if the app does funky exits or output buffering)

    Now, use the list and open the files one by one and read the code in context.

    So how would I learn about Symfony if I were approaching it for the first time? First, I'd read over their user manual. Then I'd get an example app going. Then I'd do the trick with included files. Then I'd try to write a more complicated application. I'd join their forums and mailing lists. I'd look at other apps that were available. I'd probably never look at the API Reference except in the code.
    Thanks for a great tip on the included files, haven't thought of that. I'll try it out first thing when I get the change this afternoon.

    In my opinion it is indeed a good practice to dive into code that has been around long-time, like the Drupal and Mediawiki systems you mentioned. Then again, you don't want to start doing that before you have got a good sense of how to read other peoples' code and how to actually learn from it, in an active way.

    I normall start hacking away when I've learned how to use the code. I then extend controllers, model, routers etc. to get a feel for how the output changes when I make modifications to the code.

    Quote Originally Posted by Kailash Badu View Post
    I, on the other hand, have gained immensely by examining the code, structure, and architecture of established frameworks/libraries.

    Ok, PHP Manual does an amazing job of explaining syntax and language structure. But how do you put together disparate pieces to make up an working app? The existing libraries come to rescue. Tear them apart and see how they work, how they are structured etc.. . Don't just do passive reading. Modify the code, run with different parameters/settings etc.. It is also an fantastic opportunity to get to know obscure functions/uses that you never knew existed. If the library has accompanying documentation (most of the good ones do), it’s icing on the cake. Besides, being able to read someone else’s code is an important skill that will come very handy in your career as a programmer. Admittedly, there are moment of frustrations but you’ll be glad that you held on.

    To be on the safe side, study the code from libraries that are known to be of high quality lest you don’t pick bad habits. But then, ability to tell good code from bad one is a separate skill in itself.

    Zend Framework, Creole, SWIFT could be a good start.
    I like to tear things apart.. it really makes you feel like you understand what's going on under the hood. I'd build an application with any given framework, and then alter the library code, so things in my application change. This way, I can learn how certain changes effect my code, and what the best practices are.


    For those of you that I haven't quoted; thanks for the replies to this already interesting talk about this !

  11. #11
    Django Jedi neron-fx's Avatar
    Join Date
    Sep 2007
    Location
    Bristol/Bath, UK
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I definately learn better from playing around with code and experimenting than I do reading through book after book. Don't get me wrong books have a very important role in my professional development but they are not my sole means of learning. I use books more as a guide and a reference and will learn from books if Im trying to pick up a new language or framework. For me half the fun and excitement of web development is figuring out new things for yourself and learning under your own steam and at your own pace.

    One of the best learning experiences I had was about 7 years ago when Friends Of Ed released a book called 'Foundation PHP for Flash' By Steve Webster. In Chapter 12 they developed a Flash, PHP and MySQL threaded message board. A few of us readers met up on the book's online support forums and continued the project working together adding our own functionality to it, sharing code and fixing any bugs that arose. By the time the support forums had disbanded and the next book had come out the Flash message board had many of the features of its PHP counterparts. This was a brilliant way to learn. It was that period in my life that really got me into PHP and MySQL, now I work with it full time as a developer

    By learning in this manner, we got to know the code inside out and if we had any problems the more experienced members of our team could step in and help

    So I find the tips below work for me!

    • Have your own projects, its a great way of learning.
    • Start a project with some developers right here on Sitepoint! Communities Rule!
    • Play with code, pick it apart, experiment and try to re-create on your own.
    • Read books and refer back to them if you are unsure.
    • Get a job in what you love doing, you learn so much more when you work with a language everyday.
    Neron-Fx
    Everytime a user opens Internet Explorer, a web developer dies...
    http://www.savethedevelopers.org/

  12. #12
    SitePoint Enthusiast webslicers.com's Avatar
    Join Date
    Aug 2008
    Location
    Netherlands/Manila
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ripcurlksm View Post
    I am always learning, and can't contribute to this thread other than: Welcome to SitePoint!
    no offense meant but, your comment made me laugh. i don't know, but it really did. maybe it's because i also cannot contribute to this thread as well. anyhoo, welcome to SitePoint, martin!
    www.webslicers.com [Follow me!]
    We slice your designs in perfect handcoded XHTML and CSS.
    Guaranteed W3C standards compliant and checked against all major browsers.

  13. #13
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i find that trudging through the code is the best way to get an understanding of how a piece of software operates. of course, well documented code (i.e. with javadocs) makes this process much easier than if you had to try to figure out for yourself what everything means.

    that's not to say an API is useless though, it provides a great reference (again...if well documented), but I think it's better to get an understanding of the implementation first.

  14. #14
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by neron-fx View Post
    I definately learn better from playing around with code and experimenting than I do reading through book after book. Don't get me wrong books have a very important role in my professional development but they are not my sole means of learning. I use books more as a guide and a reference and will learn from books if Im trying to pick up a new language or framework. For me half the fun and excitement of web development is figuring out new things for yourself and learning under your own steam and at your own pace.

    One of the best learning experiences I had was about 7 years ago when Friends Of Ed released a book called 'Foundation PHP for Flash' By Steve Webster. In Chapter 12 they developed a Flash, PHP and MySQL threaded message board. A few of us readers met up on the book's online support forums and continued the project working together adding our own functionality to it, sharing code and fixing any bugs that arose. By the time the support forums had disbanded and the next book had come out the Flash message board had many of the features of its PHP counterparts. This was a brilliant way to learn. It was that period in my life that really got me into PHP and MySQL, now I work with it full time as a developer

    By learning in this manner, we got to know the code inside out and if we had any problems the more experienced members of our team could step in and help

    So I find the tips below work for me!

    • Have your own projects, its a great way of learning.
    • Start a project with some developers right here on Sitepoint! Communities Rule!
    • Play with code, pick it apart, experiment and try to re-create on your own.
    • Read books and refer back to them if you are unsure.
    • Get a job in what you love doing, you learn so much more when you work with a language everyday.
    I think books provide you with the foundation, which you in turn have to build a house upon. So you learn from a book what the language is capable of, how it is structured, what the disadvantages are etcetera, and you then adopt projects, as you mention, to build that foundation into a house of understanding.

    Personally, I'd love to get into a community project sometimes, but I haven't found one which appeals to me enough, so as for now, I'll just stick to my own non-for-profit projects, with the only reason they exist are to allow me to develop my skills.

    Thanks for the replies ! It's getting quite interesting to see other views on the subjects.

  15. #15
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    The code will come up in notepad or something similar. This type of program is very basic so you won't be able to do very much with it. You will be able to find what you are looking for though. Notepad does have a "search feature. Just click on "Edit" at the top of the page and then click on "Find" or "Find in This Page". A box will pop up where you can type in a word or group of words that you are looking for. Then click "Find" and you will be brought right too it.

  16. #16
    SitePoint Zealot Dorsey's Avatar
    Join Date
    Feb 2004
    Location
    NJ
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Back in the prehistoric days of computer centers, I often dug listings (!) out of recycling bins to see what sense I could make out of them. It was like doing a Vulcan Mind Meld - seeing how someone else solved a problem was like being inside their heads, and really opened my mind to alternative ways of solving problems, and the importance of good documentation.

    I was fortunate enough to be working among those who pioneered Unix at Bell Labs at the time, so much of what I saw was Fortran (!), but also a lot of early C versions of what are now standard Linux utilities. I think that with the advent of Open Source software, we can all do this now.

  17. #17
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice.

    I just got done writing a small search engine spider emulator type deal in perl

  18. #18
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never bought a PHP book, though I did look at a few in the bookstores. I'm a much more "hands on" type person, so I just started by visiting script listing websites like www.hotscripts.com, finding scripts that would help solve my particular problem, and then hacking them up to include the features I needed. I'm sure if I looked at the resulting code now, I'd probably want to gouge my own eyes out - but producing horrible code is part of the learning experience. That was back in the days when PHP3 was new.

    Now that PHP is more mature, we have much better scripts and projects to learn from than I did back then. I would probably start with a good framework like Zend or Symfony or even a platform like Wordpress or Drupal. Find something you want to add to it and do it. You will probably produce crappy code at first, but at least try to get it to do what you want it to do. Once you've done that, you can focus on making it better and improving it. Just keep at it and you'll get there.

  19. #19
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the possibilities with php is unlimited,you can check out other peoples codes then think of some projects where you wanna use those scripts and costumize it your own way this way i think works best to get the hand on it, going to different php source sites where many have contributed free scripts and them looking at their structures works best.

  20. #20
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can definitely see some patterns rising here. A lot of people learn the syntax of the language by heart, using a book or online articles. They then tweak existing code until they get familiar with working in the language. A great tool for learning is creating your own project, in which you really test out your strenghts and weaknesses.

    Thank you all for the replies !

  21. #21
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only thing I really learned from my CS professor in the last year and a half was not to be afraid to get my hands dirty mucking through source code and documentation. Books are great and sometimes they have great insights, but I've found more often than not, that books are mostly fluff and not enough insights. I'd encourage you, once you are comfortable with the basic syntax and structure of php, to start playing around with Zend Framework or Symphony. Use there tutorials to get yourself up and running then open up the source code and start following the rabbit trails backwards trying not to make something work, but understand why and how it works. If you get stuck search for the answers. Google it, search forums, scour the internet until you come to a dead end. If you still can't find an answer, ask for help. The glory is in the journey and not the destination

  22. #22
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I honestly think you learn a lot by making changes to / breaking code and fixing it. You learn more that way because you have to figure out what you're doing wrong. Plus you get exposed to more advanced techniques that way. Trial and error is the best way to learn.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •