1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to self-learn programming

  1. Jan 27, 2012 #1
    Hi,

    I have some basic background in Python and was planning to self-learn more programming.

    I was wondering if people here that have self-learnt programming in C/C++ and now using it for "real world" purposes (such as image analysis for BEC or data processing in particle physics) can share some experience on how they did so.

    I'm of course aware that the first thing you would need to do is to pick up a programming book, read through it and work on the exercises in it.
    However it seems to me that even doing so doesn't seem to give you skills quite at the "practical" level.
    After all, nobody in the real world would write a program to simulate a few particles, sort a list or just solve some simple differential equations as they would in the textbooks.


    Any comments appreciated!
    Thanks
     
  2. jcsd
  3. Jan 27, 2012 #2
    You have to start somewhere. After you you complete a general introductory book, move on to more advanced books covering specific topics you are interested in.
     
  4. Jan 27, 2012 #3
    Programming books or, my own preference, online tutorials are great for getting the syntax down. Once you know the basics, though, I'd start applying them immediately. You can find a good number of practice exercises and fun project ideas online, and not necessarily only hugely simplified ones. Keep reading through the books while you're at it, since that's a good way to pick up new language features, but I'd make that a secondary concern. There's no substitute for actually coding a complex project.
     
  5. Jan 27, 2012 #4

    jhae2.718

    User Avatar
    Gold Member

    It's pretty simple: first you program, then you program some more, and then you program even more.

    There are a lot of good books out there, and Google Is Your Friend. (If you want to continue with Python, the Python Essential Reference is wonderful.) StackOverflow is good for asking questions.

    Project Euler has a lot of exercises.
     
  6. Jan 27, 2012 #5
    In the real world we don't ever have to sort lists? News to me! Admittedly a lot of the basic stuff is done these days through libraries but we still need to know how all the basic data structures work in order to build bigger and more complex ones.

    Plenty of books out there on architecture of large software systems however you can read all of them and still won't be able to code a simple Hello World program unless you learn the basics of a language.
     
  7. Jan 27, 2012 #6

    Pythagorean

    User Avatar
    Gold Member

    Program.

    You'll have to write pointless programs to challenge yourself in all the ways. Find exercises online or in books and do them.
     
  8. Jan 27, 2012 #7

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    That's the wrong way to look at it. If you can't write small programs that work, I guarantee you can't write big programs that work.

    Learning to program is like any practical skill. You learn a lot more and a lot faster by completing 100 different small projects successfully, rather than attempting to do one huge project and giving up before you finish it.
     
  9. Jan 27, 2012 #8

    phinds

    User Avatar
    Gold Member
    2016 Award

    Programming is exactly like riding a bike ... you can read about it all you want but until you do it you don't know how to do it.
     
  10. Jan 27, 2012 #9

    chiro

    User Avatar
    Science Advisor

    Hey Ans426 and welcome to the forums.

    Adding on the advice given by the posters above, you need to pick a domain.

    Picking a domain means that you can focus on something specific and it will be the step that needs to be carried before deciding on (a) project(s).

    With big projects, divide them into mini-projects or tasks. Create libraries of code that will be used for future projects.

    If you don't pick a domain, then what will happen is that your scope and focus will be way to wide meaning that you either a) will be trying to do may more than you can handle and not actually get anything done or b) you won't even know where to start because you are considered way too much to start out with.
     
  11. Jan 27, 2012 #10
    I don't know if reading a book would be the best thing. I learned programming through 8 years of pure doing, reading little pieces of books here and there and TONS of online example code. Just this year, I picked up Kernighan & Ritchie's C programming book (this is a must read for anyone who's serious about programming in any scope, Kernighan helped write the UNIX kernel and Ritchie basically wrote the C language). I can't say whether it's easier to learn [in general] these things from a book or from doing, but what I do know for certain is that I always found reading books to be really boring. Studying physics has helped me get over that, but I still never read books for trivial things where I can read documentation or examples online as I go.

    It will be useful for you to also know how to use Linux. Learning C and learning systems kind of go hand in hand with each other (though knowing Linux isn't exactly *required*, but compiling, running, doing basic things in Linux is something you should know since Linux is heavily used in science and other fields in industry). If you're really ambitious, you can get the book I mentioned above and just work through it. It's very short, but dense and it comes with exercises. I can't say for sure whether this method will work for you. It may scare you away because it's too hard, but you might end up saving a lot of time doing the baby stuff. If you can learn C, you can learn practically anything.

    Also, with this book I mentioned, it's not really written for anyone in particular. C is simple and general that way, but what I mean is that you won't find any applications really towards science or math. That's ok. Once you know how to do the stuff in there, you begin to understand how to program the physics and the math. After that, you'd want to learn about optimization techniques and maybe parallel programming.... but starting with something general is the best idea I think.

    Anyway, I wrote this post assuming that you wanted to do something related to scientific computing. Also, my background isn't exactly professional. I did lots of programming in high school (mostly on web engines) and I started doing astrophysics research a year ago when I started on the physics BS, but no real work experience in professional software writing/engineering. Just an FYI.
     
  12. Jan 28, 2012 #11
    One thing that you can do is to download an open source package, try to get it working. Most of them have bug lists and open projects and you can work on some of them.

    http://en.wikipedia.org/wiki/ROOT
    http://www.tina-vision.net/
    http://en.wikipedia.org/wiki/List_of_free_and_open_source_software_packages

    Right. They'd download a program and modify it so that they can do it. Which is what you can do with those packages..... :-) :-) :-) :-) Also be prepared for days to weeks of frustration as you try to get the package installed. Be also prepared for poor/non-existent/misleading documentation, which will teach you how important documentation is.

    Also, one thing good about working on an open source project is that you learn some of the social skills that you'll need in the real world. Once you have finished the coding, having people review it, and then convincing people to put it into the tree is quite useful.
     
  13. Jan 28, 2012 #12
    Also writing code is easy. It's reading and modifying other people's code that gets painful, and one reason to work on a big project is that you will "feel the pain" of having to figure out and fix other people's bad code.
     
  14. Jan 28, 2012 #13
    On the other hand, writing your own program may not be the best way of learning this sort of thing. One thing that would work is to write a sort program once. Spend a day or two, writing together a program to sort a list. Then download an implementation of STL. Compare. You'll see the difference between a paper airplane and a Boeing 747.

    You can do the same for differential equation code. Write your own. Look at professional code. Compare. Learn what they are doing that's different.

    Part of programming is to know when *not* to write your own stuff. For list sorting, you do *NOT* want to write your own routine as another other than a "let me fold a paper airplane" exercise.

    You want to use STL. For ODE stuff, you really don't want to write your own code either. Use Scipy, and then download and take apart Scipy to see how to works.

    Also do you want small projects, but open source makes it possible to do that in a way that is useful. For example, it would be better if instead of writing a "throw away" ODE calculator, you look at scipy, and then implement some thing is missing.

    One big advantage of CS, is that if you want to learn aerospace engineering, you can't just download a copy of a Boeing 747, change the wing slightly and have Boeing redo the 747, whereas with software engineering, you can.

    Something else that would be useful (i.e. I'd like to do it if I had the time, but I don't) is to write some simple scientific apps for the Android apps store.
     
  15. Jan 28, 2012 #14
    Thanks a lot for all the feedback.

    I'm guess I made myself a bit unclear.
    What I meant was it seemed to me that nobody in the real world would write programs that ONLY sorts a list or do so simple tasks in a couple hundred of lines.
    I'm aware that the basics are very important and I certainly know how to write my only algorithm to sort a list or do some basic numerical stuff or directly using stuff from SciPy/Matlibplot.

    Based on the above comments, would it be a good idea if I first read and worked on all the exercises in a book in C++ (say Accelerated C++ or C++ Primer Plus, or if anyone could recommend some good online tutorials) , and then trying to working on larger codes from TINA or ROOT?

    Thanks again.
     
    Last edited: Jan 28, 2012
  16. Jan 28, 2012 #15

    Pythagorean

    User Avatar
    Gold Member

    If writing code is so easy, why bother fixing somebody else's? :)
     
  17. Jan 28, 2012 #16

    chiro

    User Avatar
    Science Advisor

    If only it were that easy!
     
  18. Jan 28, 2012 #17
    If there is a huge app(s) or large libraries you have to maintain you are not going to write it all from scratch, you will be wading through thousands of lines of code written by possibly dozens of different coders. Some will be neat and elegant, some will be average, some will be just plain unreadable and you will be left scratching your head how it even manages to compile let alone work as required. Many of those coders will no longer work for the organisation so you are on your own to figure out what's going wrong or how to add the new requirement. Once you feel the pain of having to fix someone else's code then you generally try to do better with your own. It surprising how fast you learn why you should code things a certain way and get an appreciation for good design when you see the abominations that happen when others have done things differently.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook