Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Best strategy to study computer science?

  1. Sep 3, 2011 #1
    What is the strategy to master computer science. My class is Fortran 90 based :D.

    I never really took a computer science class before and I'm sure its a bit different than preparing for mathematics.
  2. jcsd
  3. Sep 3, 2011 #2


    User Avatar

    Staff: Mentor

    Never try to write a non-trivial program all at once and toss it to the compiler. When something goes wrong, you'll never figure out where the problem is.

    Write and debug one section (perhaps no more than a dozen or so lines of code) at a time. Don't move on to the next section until you've got the previous sections working properly.
  4. Sep 4, 2011 #3
    Words of wisdom.
    Every programming task can be subdivided into a series of smaller tasks, and you want to focus your attention on each one of them individual and ensure that one is working before you go onto the next. I recommend keeping a library of code that you've written for this reason; it will happen very often that you've coded a particular "sub-task" before, and you can easily modify it to fit the new code.

    On a side note (and I can't stress this enough), focus on clean (legible) and efficient (computationally speaking) programming right from the start. Bad habits are hard to break.
  5. Sep 4, 2011 #4
    Pick a naming convention, and stick to it. The last thing you want when you're shuffling dozens of variables is to have to go back and look up what each one is.

    Try to have an idea of your program's general structure at all times. If something comes up that puts a kink in your original plan, see if there's anything in that structure that you can alter that will fix the problem. The alternative of adding a bunch of case structures and exceptions is just asking for a migraine.

    Code legibility is key. You should be able to quickly glance at any block of code, and immediately have an idea of what it does and how it works. Comment as you go, even if you think you don't need to. At the beginning, it always seems easy to keep everything straight in your head. This will probably change within the first hour of coding, and if it sneaks up on you, you may be in for an arduous line-by-line journey through your code to recomment it.
  6. Sep 4, 2011 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    But do not sacrifice the former for the latter -- a lot of harm gets done in the name of efficiency. (so much that "premature optimization" is sometimes cited as the #1 cause of programming sins)

    99 times out of 100, it's better to write a piece of code quickly, clearly, and correctly, with little regard to efficiency. The remaining 1 time out of 100 can be discovered after the fact by profiling your code, then going back and improving the parts that need improved. (of course, you have to be diligent about actually doing that....)
  7. Sep 4, 2011 #6
    To "master" an area takes years or even decades. Just focus on learning.
  8. Sep 4, 2011 #7
    Thanks everyone! I will take them all into consideration. :)

    But my biggest concern: how can I go about actually studying and getting good at programming?

    For example, in math I carefully take notes of the sections, go over the proofs, make sure I understand everything at a non-superficial level, and then tackle the problems.

    What do I do for my computer science class exactly?

    Well, by mastering I mean it towards my class. Getting an A would be an indicator for me.

    This is random but just to throw it out there, my psychology book cited about 10 years to master any area.
    Last edited: Sep 4, 2011
  9. Sep 4, 2011 #8
    You don't study, you just program. Keep writing programs and you'll get used to it. Get a book on FORTRAN and don't just replicate the code in the book, but write your own that incorporates the techniques you're learning. There's no substitute for actually doing coding yourself.
  10. Sep 4, 2011 #9
    This is basically my first CS class so bare with me a bit hehe. The problem is I have no idea what to write a code about or where to write one and or to get started or anything.. :confused: The actual class material didn't really start yet either so I'm a bit lost on what to do.
  11. Sep 4, 2011 #10
    I wouldn't worry about it. The whole programming "thing" seems incredibly daunting at first, but you'll find it comes pretty easily. Your professor will walk you through some simple code and give you a sense of what the language actually does, and there'll be plenty to experiment with from there.
  12. Sep 4, 2011 #11
    It doesn't daunt me at the least, its just that I believe highly in learning strategically. Its made a huge difference in my ability to absorb mathematical concepts.
  13. Sep 5, 2011 #12
    In my experience, learning to program is fundamentally different from learning math or science. As others here have noted, a big part is playing around by yourself, and learning things by trial and error. In some intro science classes, you can get away with plugging and chugging without actually understanding the underlying principles; this tends not to work in computer science, since a given block of code needs to accomplish a very specific task, and it won't unless you know exactly how you want to do it. Classes are great for learning the basics and getting exposed to the major libraries, but at some point, you're going to want to start little projects of your own. Start thinking of cool little things that would be useful, perhaps to satisfy your own curiosity or even to help with your other classes. Take some problem that would be difficult or impossible to do by hand, and try to make your computer do it. Then see if you can generalize it to a broader range of problems, make your solution more exact/realistic, or just make it cooler. Here's one that I was able to get a lot of mileage from:


    Try solving the third "problem" there computationally. Then use your imagination and see how realistic you can make it. Do the raptors slow down when they turn? Can the person change directions in mid-simulation? Do the raptors engage in pack behavior, and work together to corral the person? (That last one is probably the hardest, but may be the most fun, especially if you're mathematically-inclined.) The bottom line is to have fun and keep learning new ways of doing things, rather than hitting the books as one might do for other classes.
  14. Sep 5, 2011 #13


    User Avatar

    Staff: Mentor

    You have a textbook with exercises in it, right? That should give you some ideas.

    That depends on the tools that you have available to you. Some schools use a packaged "integrated development environment" (IDE) under Windows. Some schools have you write code with a plain text editor, and run the compiler and the finished program at the command line under Unix or Linux. Most textbooks don't cover details like that because they're so different from one school to another. You'll probably cover it in class before too long, or else there will be instructions available in your computer lab or on the school's web site.
  15. Sep 5, 2011 #14
    Last edited by a moderator: May 5, 2017
  16. Sep 6, 2011 #15


    User Avatar
    Science Advisor

    On top of the great advice I would suggest you always keep Murphy's Law in the back of your mind the whole time you are writing code.

    Murphy's law is basically the saying that if something can go wrong it eventually will.

    In application to programming, always think about your state (variables, and allocated memory) and picture in your mind what values they can take and what can go wrong with regard to specific realizations of those values.

    For example if you are say learning C for the first time and need to work with dynamic memory (i.e. allocation from the heap), then chances are you will probably write code that crashes (it happens to us all) and most likely the error is with what the contents of the pointer are (null pointer, pointer outside range of heap).

    So when you declare a variable, or use some form of allocated memory, think about what could go wrong and keep that in the back of your head.

    For really simple programs you may think "what's the point", but when you start to get bigger programs and then create a lot of modules that contribute to the complexity of the program, you'll find that being paranoid (but not too paranoid!) will actually serve you well.

    Good luck with your course.
  17. Sep 6, 2011 #16

    But study a little bit too. Read the text 10%, Practice programming 90%. It's the key to success in programming.
  18. Sep 15, 2011 #17
    Thanks everyone for your input. ^.^ I'm doing great in the class. Fortran is an awesome language. =D
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook