How do you learn programming?

Discussion in 'Programming & Software Development' started by lawrencep93, Apr 28, 2013.

  1. lawrencep93

    lawrencep93 Member

    Joined:
    Apr 12, 2009
    Messages:
    1,975
    Location:
    Melborne, VIC
    I was wondering how one learns programming?

    I have done one subject at uni in it (C++ for electrical and electronic engineering), only just passed by memorizing code.

    How do I actually learn how to program in C++ other than memorizing code someone else wrote?

    Any good resources or any personal experiences that helped them, sometimes I feel as though I just don't really get it.
     
  2. Carcin0Genic

    Carcin0Genic Member

    Joined:
    May 3, 2012
    Messages:
    1,586
    Location:
    Sunshine Coast
    Write code. Then write some more. Then some more, then some more.

    When you think you have learnt it. WRONG.
    Write more code.

    Same principle as when learning math. Do it to learn it, not learn it to do it.
     
  3. Taceo Corpus

    Taceo Corpus Member

    Joined:
    Sep 19, 2005
    Messages:
    3,253
    Location:
    Tokyo
    1. Write code.
    2. Run code.
    3. Did it work? Yes: Go to 1. No: Continue.
    4. Check the documentation if there is any. Try fixing it with what you have found.
    5. Did it work? Yes: Go to 1. No: Continue.
    6. Google the problem. Try fixing it with what you have found.
    7. Did it work? Yes: Go to 1. No: Continue.
    8. Post the problem online at somewhere like StackExchange. Try fixing it with the information others provide.
    9. Did it work? Yes: Go to 1. No: Scrap problem code and try a different approach. Go to 1.

    Iterate that often enough and you'll not only learn programming, but have a few working programs at the end. :) Keep iterating for the rest of your life.
     
  4. PsydFX

    PsydFX Member

    Joined:
    Jan 1, 2011
    Messages:
    3,739
    I learnt by helping others. I ended up on Experts Exchange helping others with their code - ranging from beginners to more intermediate programmers.

    Gave me a good opportunity to learn the fundamentals without having to come up with my own ideas of things to program.
     
  5. OP
    OP
    lawrencep93

    lawrencep93 Member

    Joined:
    Apr 12, 2009
    Messages:
    1,975
    Location:
    Melborne, VIC
    So how do you get the idea's and so on to extend your knowledge. I can write some basic programs, but my course means we go from writing a calculator to programming an IOUSB board and little to no help from people other than, go work it out.

    Maybe I need to keep writing a calculator program from scratch on my own and keep working my way up, just wish I could do it faster, I might be one of them people who has to do a little more to get it I guess.
     
  6. echo foo

    echo foo Member

    Joined:
    Jun 26, 2012
    Messages:
    14
    Location:
    Armadale
    try... catch... finally...

    Try - your code
    Catch - the errors
    Finally - drink that coffee

    There is no real other way to learn than by Trial and Error.

    But, please please please don't re-invent the wheel all the time.
    That was a mistake I first made when I started, tried to do things that someone had already made a free library for. Learn how and when to use someone else's work ;)

    To get new ideas - search some sites like StackExchange, or GitHub, or Freelancer to get the idea of what people MIGHT want you to program...

    Or, find a problem that you have - might be something small like an alert program which sets off an alert for a given time etc... (I've seen some pretty complex alert programs).
    And just keep adding to it.
    Make it do more, and more, and more. While keeping the integrity of your code.
     
  7. SLATYE

    SLATYE SLATYE, not SLAYTE

    Joined:
    Nov 11, 2002
    Messages:
    26,853
    Location:
    Canberra
    Not all the time, but reinventing the wheel can be a good way to start. That way you can always go and see how other people did it if you get stuck.
     
  8. blankpaper

    blankpaper Member

    Joined:
    Feb 1, 2013
    Messages:
    1,272
    A calculator is a good starting program. At school I wrote a dictionary program (based on a wordlist and definitions, I imported it, indexed and searched it, etc).

    Simple every day things you use, try and replicate them with your coding. Do you use robocopy to backup files? Try recreate it, it'll teach you a lot about filesystems and file manipulation and coding to use them.

    As far as resources, google. In your mind, aim for efficiency, not just code that works. Efficient code is good code.
     
  9. xsive

    xsive Member

    Joined:
    Jun 29, 2001
    Messages:
    4,343
    Do not agree with some of the stuff posted above. Two things in particular:

    1. DO reinvent the wheel. It's important to understand how wheels work.
    2. DON'T aim for efficiency. At least not at first. Premature optimisation is the root of all evil.
     
  10. blankpaper

    blankpaper Member

    Joined:
    Feb 1, 2013
    Messages:
    1,272
    Premature optimisation, sure. But ignoring it just because your code compiles and 'works' is a sloppy way to write software.
     
  11. xsive

    xsive Member

    Joined:
    Jun 29, 2001
    Messages:
    4,343
    I refer you, Sir, to the title of this thread. Enough said :p
     
  12. OP
    OP
    lawrencep93

    lawrencep93 Member

    Joined:
    Apr 12, 2009
    Messages:
    1,975
    Location:
    Melborne, VIC
    So write my code, understand it, then try and do the same thing again but in less lines?
     
  13. xsive

    xsive Member

    Joined:
    Jun 29, 2001
    Messages:
    4,343
    Essentially. Performance optimisation is important when you need to scale your applications. At that point you need to understand where your bottlenecks are and how to remove them. Don't worry about this stuff now. Just code. Forget everything else. Code.
     
  14. ShaggyMoose

    ShaggyMoose Member

    Joined:
    Jul 1, 2002
    Messages:
    483
    Location:
    Sydney
    And once you have spent some time on a particular problem and have a working solution, its good to compare your solution against others. For this reason, its good to work on a "standard" problem for which there are a lot of elegant solutions out there. This can help to avoid picking up bad habits.
     
  15. elvis

    elvis Old school old fool

    Joined:
    Jun 27, 2001
    Messages:
    43,141
    Location:
    Brisbane
    Speaking as someone who regularly saves business from bad code at high financial cost:

    Code that is clean, understandable, logical and well documented is better, safer and more profitable than code that is highly optimised, condensed obfuscated.

    Save your crazy optimisations for when you're writing high performance clustering code on super computers. Until then, make it easy for others to read and understand as your first priority.

    That doesn't mean be sloppy and lazy. That means be purposeful and obvious in what you want to achieve and why, and write code that complains loudly and obviously when things break (because like it or not, you're not perfect, and your precious code will break at some point).

    But anyways, that's all very high level. How do you learn to code in the first place? I always suggest people start with the basics - a few simple programs in whatever language (and no, the language really doesn't matter). Then go look up some open source software in whatever field/industry/hobby you enjoy (because if it's fun, you'll want to do it), and try to understand what the author is doing. From there, try to modify some things to make them better/different/fixed. If you're confident, commit them back upstream and see if/how they're accepted. And if they're not accepted, take the criticism on board and improve your code next time.
     
  16. OP
    OP
    lawrencep93

    lawrencep93 Member

    Joined:
    Apr 12, 2009
    Messages:
    1,975
    Location:
    Melborne, VIC
    Alright I will start coding a calculator program and put in my error checking, still have the criteria from last year.

    Anything you guys do for motivation?
     
  17. islade

    islade Member

    Joined:
    Aug 17, 2004
    Messages:
    555
    Location:
    Gold Coast, QLD
    Just come up with your own little projects.

    Eg: a 2 player pong game, or a small contact address book, or a little something that might make your job a little easier? If you have a "goal" for the app you are working on ,it's easier than just mucking around aimlessly. You can always stop it and work on a better project if you get bored half way through.

    I'm currently making an ipad image viewer, but it loads pics from your desktop machine in real time, so you don't have to sync first. So I can now browse my 6tb photo gallery on my ipad (while on home wifi) and... No server software required :)
     
  18. sam_allen

    sam_allen Member

    Joined:
    Sep 7, 2003
    Messages:
    359
    Location:
    BorĂ¥s, Sweden
    Dogfooding :)

    Don't bust your ass trying to memorize exactly how things are done. The commonly used logical processes will come to you with time. Anything more complex you use/see is really only about being able to remember that it 'can' be done that way and then you reference it later. As others have said, programming 99.9% of the time is about NOT re-inventing the wheel. If other's code works, and works properly then there's no point in not stealing it.
     
  19. elvis

    elvis Old school old fool

    Joined:
    Jun 27, 2001
    Messages:
    43,141
    Location:
    Brisbane
    The preferred term is "sharing". :)
     
  20. GumbyNoTalent

    GumbyNoTalent Member

    Joined:
    Jan 8, 2003
    Messages:
    9,371
    Location:
    Briz Vegas

Share This Page

Advertisement: