What is the best way to learn code?

by 61 replies
75
What is the best way to try to learn code? I am learning php using a book and am finding it hard work. I am always astounded by how quickly a coder can read and pick up any errors in it. I was wondering how do programmers look at a line of code to they focus on one element (i.e the variable) at a time or do they try to analyze it all. For me there are usually to many different things going on at the same time and this disorientates my logical thought process leading to panic!
I am thinking of trying a new method whereby I will just read hundreds of lines of code every day to get a feel of it, almost like photoreading it. This will be like how we learn say the English language. Reading is now such second nature that we can immediately spot misspellings or bad grammar because it jars and hits us in the face. Maybe that's how programmers are with code. Would this approach be useful or do you have to be more systematic?
#programming #code #learn
  • Programming is an art. If a programmer tries to debug code, they are VERY good at it because they know exactly what they are looking for. They have probably been writing code for years and years.

    All I can say is, learn the basics. Just keep working at it. I admit that it is hard to learn when doing self study.

    Good luck!
    • [1] reply
    • Yeah little by little you will be becoming a better programmer but it takes time and dedication.
  • Yeah, it does take a lot of experience. People who have done programming for a long time already know roughly how a piece of code needs to work before even looking at it. Then, they skim over it to get the basic layout, followed by a breakdown of the code into sections, functions, procedures, etc.

    You just have to keep at it. It takes time. Good luck. - Russ
  • doylesoft and Russ thanks for your replies guys. Yes it seems to me there is no quick fix, as you say, it is a matter of keeping going. I will never be an expert at it I just want to know enough to recognize the basics.
  • the way to learn php is by writing some code.
    Get yourself a simple open source or plr script and experiment with it.
    When you know what a piece of code should do you will be able to see whats wrong if it doesnt work, also check the php error log as this tells you what the error is and what page / line the error is on, remember that something as simple as a missed comma or semi colon will break it.
    • [1] reply

    • when I started coding this is the method I used...not just PHP, but also HTML, XHTML, and CSS
      I find the only way for me to learn is not from books, but from actually tearing code apart and putting it back together again!
  • Thank you Valdor, I will try your method out. I have a package of small PHP scripts which I will now open.
  • Hi,

    I am a php developer, so I wanted to put in my 2 cents.

    My first suggestion would be to approach the learning process with
    a task in mind that you wish to accomplish.

    It has been my experience that unless you are focused on something
    specific, it's difficult to put the pieces together.

    In addition, it's most beneficial when you create your first script and
    get it to work. ( My examples will be php scripts )

    <?php
    echo "This is my page" ;
    ?>

    Next you would want to understand internal language functions
    and logical structures, ( while () for() if then etc )

    You might take the first example and locate snippets on the net
    that you can add to your script.


    <?php
    echo "This is my page" ;

    $i = 0 ;
    while ( $i < 10 ) {
    echo "Index " . $i ;
    $i++ ;
    }

    ?>

    The idea is to make baby steps in terms of the pieces that you learn,
    in preparation for an overall solution to your task ultimately. Your task
    is broken down into steps that you can implement through the process of
    learning the functions and logical structures.

    Of course, this is a much larger topic, but that's how you can get started.

    I did assume that you
    1 You use a text edit for the script creation
    2 Have a web host that supports php
    3 Know how to ftp the example scripts you make.

    I hope you find this useful

    Regards,
    Phil Alger




    ?>
    • [ 1 ] Thanks
    • [1] reply
    • WoW! you guys are heavy. I just throught they were speaking about HTML code..simple stuff. I'm in the wrong place for now.
  • Phil, thanks you for your input, you suggest:

    "The idea is to make baby steps in terms of the pieces that you learn,
    in preparation for an overall solution to your task ultimately. Your task
    is broken down into steps that you can implement through the process of
    learning the functions and logical structures."

    This is a more structured and and incremental approach than I am trying. This is building from the ground up. Your idea of a strong purpose is interesting and may provide me with a stronger focus by having a practical target. Yes I do have a host runing PHP and can use FTP. I will try out your method (which must have been successful for you), by trying to run mini-scripts and see how it develops from there.

    regards
    fazal
  • The best way is not starting from zero.

    Start with the best opensource code out there.
    There are lots of thing that are not written in the book.
    Just best practice.

    Start with framework. Learn PHP? start with KohanaPHP or code Igniter.
    You want content site. Learn Wordpress.

    Just don't start from basic. That's my method. Hope it works for you.
  • Other reason you need is community.
    Mailing list is the best place to ask something very2 stupid, umm beginner.
    Forum you have to read before asking stuff etc. Etiquette blablah.
  • internet is your friend.

    you can find any pieces of code online

    all you need to do is just know how to read it and piece them together
  • For others who are learning, I have found this neat little program helpful, it makes learning the basic concepts easy. It's free and you can download it from Microsoft.com:

    Small Basic
    • [ 1 ] Thanks
  • I know exactly what you mean. I learned to program by hanging out with gurus as a teenager, and at one point I even thought I was stupid because everything that was effortless to them was far above my head.

    The stuff you're reading is confusing because you don't yet have the feel of the language and the flow of things down. Programming really becomes instinctual at some point. If you tell someone how to pedal a bike, they can awkwardly follow instructions and move forward a few feet, but they won't have to think about their feet or handlebars once they really get going.

    The most important part is trial and error & getting experience in writing code. When you get to a part that makes you want to give up, ask on forums for help. Find a mentor that will give you a visual aide or whatever is necessary when you hit a sticking point. When you make a thread, be sure to post the code that you tried so they see you aren't just asking without first making an effort on your part to figure it out.
  • I think the best way to learn is to just start coding and learn as you go along. That way you can also experiment with what you're learning and things will make a lot more sense. If you read too much you will get confused because a lot of it won't make sense but if you start playing with the code and then slowly try to modify it to do different things you'll start to understand how it all works.

    The first program I ever coded before I knew anything about programming was a simple "Hello World" program where I just have one textbox with a button that makes the textbox say Hello World when pushed. From there I moved onto more advanced things.

    Looking at open source code can be a great way to study and learn as well but make sure once you study it, you modify and update it to do other things. I would often do this with complex pieces of code and would then run into a lot of errors trying to make it do different things. It was in the process of fixing those errors that most of my learning occured - because then I finally understood exactly what each line of code was doing whereas when I was just studying it I only had a basic idea.
  • Sybiz learning by making mistakes is the best way. Best way you are gonna remember things.
  • My 2 cents would be the best way to learn coding is to get a 1 on 1 coach .. Someone that will help you if you get stuck and lead you through it.
    • [1] reply
    • That works too but if you have dedication like I said you can learn by yourself by reading tutorials online or buying books.
  • i think karning the basic of any programming language will really help you.
    because any language can be perfect with you if you have its stong basics.
    • [1] reply
    • Hi Madison.

      I learned to program back before Windows was introduced to the world. I had formal training in it so it gave me an indepth understanding of how coding works.

      With that in mind when it came time for me to learn PHP and HTML, I just got a good editor, I use PSPad. It is free and available at editor PSPad - freeware HTML editor, PHP editor, XHTML, JavaScript, ASP, Perl, C, HEX editor plus it is available in many different languages. I found it easy to use and to learn.

      Anyway what I did was to fire PSPad up and pull up my website on an internet browser.

      And as Palger mentioned, have a specific goal set out. Change something. Maybe starting with the header image. Find the code, take something out using the PSPad and save it. Then see how it affects your website. If it is not what you want simply reverse the step with the undo arrows and no harm has been done.

      I HIGHLY recommend that NOBODY edit their websites with the WP Theme Editor if they can get away with it. Especially when something like PSPad is FREELY available for everyone.

      Just my 2 cents.

      Kelvin
      • [1] reply
  • Something I haven't seen mentioned here.

    Install Linux, Apache, php and mySql on your own computer and do your testing there.

    It's faster than uploading each piece of code and finding out it doesn't work the way you planned and if you get into an endless loop you can just kill the script
    • [2] replies
    • I can't say what the "best way" is to learn code since that really just depends on the individual. Some people like working from a book, others like just ripping into php files, changing things up (making a backup first)and testing the new file.

      In some cases, you can find very well documented scripts, within the scripts themselves. For an example download the SMF forum from Home of SMF: Free PHP and MySQL forum software and take a look at some of the .php files. You will find a good bit of useful information within these files which tries to explain what is about to happen in the script. Not only does this help you figure out the code, it also shows you a good way to comment your own coding projects to help you remember what everthing is doing within each specific chunk of code.

      I know this sounds a bit cryptic right now, but if you download the forum software and browse the files in any text editor or PsPad, you will start to see what I mean.

      For a decent tutorial to get you started writing and understanding a script, take a look at the following tutorial:

      [Tutorial] PHP/MySQL Authentication System

      I hope this helps.

      Thanks for showing us all a pretty sweet looking freeware, Kelvin. I've already downloaded and installed it and will be playing around with it here shortly. I can't believe I hadn't come across this before. LOL

      I'm just guessing, but the WP Theme Editor probably produces sloppy code (could be wrong) and is inferior to freeware like the PsPad Editor that Kelvin mentioned.

      As for the tutorial; see above, under my reply to Madison. It's not assignments with dead lines, but could still be helpful to learn some php code and working with databases.

      Very good suggestion. I've done this myself a few times and need to do it again soon. Here's a list of just a few free webservers:

      Hope this helps.

      Peace & Prosperity,
      Matt Fulger
    • Excellent point!

      You can also download "packages" of apache, php and mysql for windows and set it up VERY easily. Here are two good packages:

      apache friends - xampp

      Install PHP 5 Apache MySQL on Windows : WampServer

      Ron
  • Hi Guys,

    There are a number of good suggestions, as for myself I started learning to code years ago. I actually started writing games in assembler before getting into higher level languages, self taught I might add (I'm showing my age here).

    Anyway I best way I found to pick things up was having a specific task in mind that helps you focus on the key things you need to know to get the job done. That way you can start to build a foundation of knowledge about the language you're working with and expand from there. The other key thing I found that helped me was being able to bounce things off someone more experienced because they will steer you in the right direction.

    There will come a time when it just clicks, after that you can look at code written in any language and be able to make some sense of it, very empowering when you get to that stage.

    Best of luck with your efforts.

    Byron
    • [1] reply
    • I would agree with that 100%. You must have a task (ideally to deliver it for someone else) otherwise there is no deadline and no goals to meet. Here is what I say to people who want to learn development or learn a new language.

      Find a friend/family member who has a business that needs a specific problem solving where a bespoke solution would help
      Then offer to build that solution for free and set a realistic timeframe

      So first off you *have* to get it done as you have a deadline to meet. Second you actually have a piece of work which now forms part of your portfolio/case study to help you get other work.

      It isn't easy and there are no shortcuts, you have to stick at it for quite some time. I have always tried to keep my skillset pretty narrow but very focused on what I do, it always makes me smile when I read someone who claims to be an 'expert' in C++/Java/PHP/Ruby/Perl etc

      What I would say also is pick your language stick with it and you must add SQL to your weaponry. It doesnt matter what dev tool/language you pick you will sooner or later need to access a database, make sure it is at least ansi 92 sql compliant so you are learning standard SQL and not some obscure flavour of it.

      Gary
      • [1] reply
  • I think that the best way to learn coding is to do it!

    Create a simple site using Drupal or Joomla that will allow you to put PHP code into the pages. Then use the support and forums online to help you figure out what code you need.

    Personally, I love Drupal and the support/documentation is fantastic.

    You can also pick up Freelancing gigs on RentACoder or similar. Start with easy jobs and work your way up. You'd be surprised how many people are willing to pay money for a solution that only takes a few minutes on google to figure out... get paid to learn!

    Ron
  • Object oriented programming is essentially building a program around self-contained collections of data and code to modify that data.

    For me the best way to learn code is to experiment the art of programming. It is so hard to learn but you achieved a great reward from this.

    Trust your self and God will give you knowledge and wisdom!
    • [1] reply
  • Ron, on RentACoder they have what's called "work for hire" which essentially means that your customer has full copyright to the product.

    How does that relate to the various functions that are in the code? It seems that I would have to rewrite all the functions for any new project rather than just use them again.
    • [1] reply
    • Hey Gary,

      Welcome to the Warrior Forum. BTW, I couldn't resist taking a look
      at your Singles Cafe site. According to your quiz, I should be teaching
      you how to get laid. LOL
  • GCaine,

    The only time this would be an issue is if the customer was trying to create a software product that they wanted to copyright and resell. Usually in this case, they will have you sign a NDA and will be very specific.

    Web-based systems rarely have/need a specific copyright because they are hosted and the user won't be able to "steal" the code. Of course you can always ask!

    I use open source code as often as possible, and I explain this in my bid. The reason is that by reusing code, we can develop MUCH faster and the time to develop is often a major price factor. This can also help in maintaining a more robust end product.

    Alot of Open Source code does have a GPL (or similar) license, which means you HAVE to provide the source when you sell/transfer it... and sometimes that applies to the custom code you create. So be aware of this issue (again - it doesn't really apply for a hosted web solution as there is no code transfer!)

    I have never had a client (RAC or otherwise) that wanted me to start from scratch. Not that they aren't out there, but there wouldn't be many.

    Consider that even if you program in Visual C++ or something, there are common objects and functions that EVERYONE uses. Its the same thing. If you write a function, and then you rewrite it for another client but its identical, is that copyright infringement? NO way... only so many ways to skin a cat, and we all have our own preference.

    BOTTOM LINE:

    When in doubt - ask. Just make sure they know that if you start from scratch that will really increase the development cost and time.

    Ron
  • Matt, I didn't write the quiz, only the code to make it work. The publisher of the ebook wrote the quiz.

    It did work pretty good as an ad for a while, but it seems to have slowed down.

    Ron,
    If i write some php code that will be hosted on his server there is code, it's just not visable to the users.

    I use a lot of my own functions.

    Anyway I wouldn't worry too much about reusing my code.

    Now I need to find a few bids I can win to get a rating
    • [1] reply
    • Yes - get your rating up on RAC and it helps alot. I did some smaller/faster jobs at a lower price than normal to help boost it up... and not all coding!

      I did some graphics work, video tutorials, voice work and even some sales work. There are tons of jobs on there, and lots are fun.

      If you keep your eyes open, you can also get some work in the IM field. I had some IM related work that was great... I got to read/learn the systems (one I did video tutorials for) and got paid

      RAC can be a really fun game.

      Ron
  • There are some fantastic responses in this thread. What helped me learn PERL a long time ago was creating a game with what I was learning. Some have mentioned the best way to learn is by doing. I agree. You should create small programs or scripts that do something fun or practical. You will quickly learn the ins-and-outs of the programming language.
  • Banned
    [DELETED]
    • [1] reply
    • Thats a critical point... I enjoy coding and figuring things out, but I enjoy making money more!

      I think its important to understand the basics of whats going on so we can manage the project, but leave the "heavy lifting" to others.

      Ron
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Learning a programming language is just one part of the deal. You also need to learn problem solving techniques and other programming related skills and paradigms that are not language specific (though they might be specific to a broad family of languages). Consequently, I would not advise learning two programming languages from scratch simultaneously since you may end up bogged down in details and thus miss the forest for the trees.
  • Best way to learn how to code is NOT learning php first. The best way is to start with pseudocode (search this on wikipedia). After you understand the pseudocode try to make simple programs (write them on your notebook). The next step after pseudocode programming is the C language. And after you know the C language and you understand it, it will be very easy for you to learn ANY programing language. Take Care.
  • You should learn it using your work. You should make some scripts yourself to do practice and you will get more and more knowledge
  • Banned
    [DELETED]
  • I learned all of my programming skills by immersing myself in it. I just said alright, i'm going to learn, then I just started creating a script from scratch and learned as I coded. Bit by bit, I learned all of the language. I don't read code line by line, or all at once. I read it in "Blocks". I look and say, ok this "block" is causing the problem. Then I go through it line by line and I evaluate 1) What is it supposed to do, 2) What is it doing, 3) How do I fix it?.
    • [1] reply
    • I always find when learning a new language I can read all the books and think I have a firm grasp, but when I actually start to code something the knowledge is often not as strong as it could be !

      The languages I have learnt the best are the ones which I HAD to learn to do something for my job - you pick up what you need to know for a specific task and then expand your knowledge around that core to do things quicker / better etc.
  • How i always learn new stuff:

    - Get the thinnest book or shortest tutorial on a subject. That will get you up and running quickly and get somewhat productive with your first ugly piece of code. But early satisfaction means a lot. You don't want to trust these 1000 pages "Learn rocket science in 24 hours" type of manuals. Size matters - and in this case - the smaller - the better.

    - Set relatively interesting but easy task for yourself and do it on your own using any available source of info.

    - Get the fattest and most complete book on the subject and get on with more serious project now.


    Gleb
  • Banned
    [DELETED]
  • Best way to learn is in big chunks of time i.e. 5-6 hours at a time, instead of the typical 1 hour of learning a day. Following tutorials, as well as seeing how other people make their websites also helped me.
  • Wow lots of good responses here, Well I have to say that learning code is really just like learning a new language.

    If english is your native language, when you look at spanish, or another of the romance languages, you may see a few things you recognize, but for the most part, unless you study it you will not know anything about what the language is saying.

    But spend a few weeks studying the language and learning what the language is saying and after a while you will begin to see and also understand the language.

    Learning code is no different, I see no difference between a page written in english and one that is written in PHP, did that happen overnight, Nope, do I understand everything as well as english, No again, but I understand it much better now than I did in the past and in the future I will understand it even more.

    My advice is to learn by doing, install scripts, debug code, trace down errors, the more time you spend working and learning, (hands on) the more you will understand and learn.

    Hope this was helpful,);
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • I think if you are good at Maths...You can be easily good at coding...

    if you are learning some HTML tags,,,then you can go for photocopying whatever you find...

    but when it comes to do some thing on your own...I mean developing a logic..you got to be careful...can't learn by remembering some code...

    Try learning C first...just learn the basics...not even Pointers...Just some tatements and looping and all...

    and try to implement any Math problem that comes to your mind...I mean adding two numbers...then Multiplying...

    and then try Multiplication using addition...

    what i am trying to say...in the world of programming you can code anything if you can implement your logic using the basic elements...no need to go for complex structures...

    but that doesn't mean they are not needed...first grab the basics...and then ....a lot more...

    hope this helps...
  • Banned
    [DELETED]
  • lots and lots of trial and error. also I learn well from videos
  • Learning programming and all of the coding are not really easy. Programmer should know the logic of his program first even before you can make the coding. Well, I guess you need to have lot of exercise codes to practice on. Good luck
  • Look at open source sites like Sourceforge. You can see how other programmers have gotten certain things to work. There are a lot of PHP editors out there but many of them have a price. I use Netrbeans.org for all my coding plus they have a TV site with a lot of PHP coding screencasts
  • Banned
    [DELETED]
  • I use ultraedit. This shows me the errors in my code right away via color differentiation. Give it a try when examining your code.
  • The best way to learn and programming code is to watch the vedio tutorials rather than text book. Also use online text tutorials with full examples. The best online programming tutorial site is W3Schools Online Web Tutorials.

    Start with small progammes and then try others.
    I hope it i will help you to learn as well as get experience.
  • I really strongly suggest learning C first. If you're going to do web design only, I don't see how PHP could hurt but it is also very similar to C/C++. Has elements of both, and some clarity that C/C++ does not have (such as variables always start with $).

    You need to be curious while programming. This helps when you run into problems. You cannot be seriously interested in programming if you will quickly give up on simple errors. You can even Google a common compiler error and more than likely find a solution of some kind, although it may need to be adapted.

    A piece of (bad) code for fun (and yes, this does compile):
    Code:
    #include <stdio.h>
    
    void help() {
      printf("These are the help options:\n");
      printf("  --help, -h -- Show this information\n");
    }
    
    int main(int argc, char *argv[]) {
      if (argv[0] == "--help" || argv[0] == "-h") /* This would work fine in PHP and Javascript */
        help();
    
      printf("My bad program.\n");
    
      return 0;
    }
    Yes, the desired functionality (the user gives -h or --help for arguments, stored in array argv, which is actually an array of pointers to characters) works, but -a, -b, -c will also call help(). Why? Because the program is asking if argv[0] (the VERY first element of the array) is "-", not "--help" or "-h". It's only testing the first character. Instead that line should say if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help")). This does NOT solve the issue if -h or --help were in argv[7] for example.

    Actually, this is one of the big differences in C vs other languages that have come after. String comparisons are done either manually or with the standard C library (string.h). Learning to manipulate strings (arrays) is another very helpful, along with dynamic memory allocation (malloc, yes), and all that other fun stuff.

    You have to want it, you need the curiosity, and you CANNOT give up so easily no matter what. There is a 99% chance that there is a way to get things to work the way you desire.

    If you have any PHP questions, I am happy to help a little here and there.
  • Best way to learn on how to code is to start from the basic, which is flowchart a.k.a logic formulation.

    No matter what programming language you use, if you have a strong foundation, you are good to go
  • There's no magic to writing code. It's no different than learning any other skill or discipline. In fact, it's just like learning to ride a bike.

    In the beginning you struggle. Your brain hasn't formed any neural patterns for coding so everything is new and everything is difficult.

    As you continue working with PHP, you'll get more neurons joining the party. As your neural network grows you begin to more easily recognize patterns in programs.

    As you gain even more experience, the number of patterns you recognize will increase. The complexity of patterns that you recognize will also increase.

    Debugging is simply being able to determine when and where in a program a pattern is has been violated. Your debugging skills will improve in direct correlation with the increase in pattern recognition.

    Unfortunately, growing neural networks and increasing pattern recognition takes time and experience. Unless your a genius - where your pattern recognition skills expand almost immediately - you can't do much to accelerate the process.

    The only thing you can do is to continue regularly working with PHP code and programs. I'd suggest dissecting as many working PHP programs as possible. One easy way to do this is with something like WordPress. If you've got a WP site, download a few plugins and wade thru the code. Figure out how they do what they do. Once you think you've got it figured out, modify the plugin code to add or change features.

    And, above all, have fun.

    Ralph
  • Whenever you want to learn a new language, then best thing is to download snippets of code that do exactly what you are after and change the code.If you are just learning PHP. Do not bother with the web frameworks like EasyPHP/XAMPP as Ikke mentioned above. They are more complicated and you will then have both the language to learn and a heavy featured IDE.
  • You should check out Stack Overflow. It's such a useful and great site for coders.
  • Firstly, if you know any basic programming language and the script has "some" comments you can easily figure out problems and have them solved.

    Now to the question, HOW PROGRAMMERS DO IT, they have experience, once yous tart programming, you can tell the error by just knowing it, without seeing the source code, so its just knowledge, more you know the more you apply and faster results
  • Adopt good practices
    Make your code talk back to you when your developing so you see each step of the way.
    Look at professionally written code.

    It takes time + practice.

Next Topics on Trending Feed

  • 75

    What is the best way to try to learn code? I am learning php using a book and am finding it hard work. I am always astounded by how quickly a coder can read and pick up any errors in it. I was wondering how do programmers look at a line of code to they focus on one element (i.e the variable) at a time or do they try to analyze it all. For me there are usually to many different things going on at the same time and this disorientates my logical thought process leading to panic! I am thinking of trying a new method whereby I will just read hundreds of lines of code every day to get a feel of it, almost like photoreading it. This will be like how we learn say the English language. Reading is now such second nature that we can immediately spot misspellings or bad grammar because it jars and hits us in the face. Maybe that's how programmers are with code. Would this approach be useful or do you have to be more systematic?