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

Did I make the right choice?

  1. Apr 29, 2012 #1
    Hey everyone.

    I recently decided which language I wanted to start programming with, C, and I also bought a book for guidance/referece. https://www.amazon.com/gp/product/0672326663/ref=oh_details_o00_s00_i00

    I have never programmed before and after doing an extrenious amount of research I have concluded that C would be the best language to start with. Also that the book would be the best to have bought for a guidance/reference.

    I was wondering if I had made the right choice on starting out with C and buying that book.

    Thanks in advance!
     
  2. jcsd
  3. Apr 30, 2012 #2
    The book looks okay from what amazon allows to skim through and C is definitely a good language to know. Note though, that when you're learning C, you will need to know more about the internal details than you would in, say Java. It can be a pain, unless you enjoy it.
     
  4. Apr 30, 2012 #3
    I'm not too worried wether or not its a pain. I've done a little with Python and I've found that I really enjoy programming.

    Once I become really good with C what would I be capable of doing? As in how will it benefit me and what exactly is the point of doing it?
     
  5. Apr 30, 2012 #4
    You can do ANYTHING with C, and from my limited experience (I'm still at uni), learning C makes learning everything else easier. It's close to the metal, if you are processing a string you will know about every character in that sucker, you'll terminate it yourself and you'll manually allocate and free the memory it uses. I like to think you learn some good practises coding in C. Good luck!

    If you get stuck for something interesting to code, look up Project Euler, or do some text processing (encryption, HTML parsing, compression). Graphics is fun too, but you'll need to learn some extra libraries for that (OpenGL or something).
     
  6. Apr 30, 2012 #5

    chiro

    User Avatar
    Science Advisor

    Not quite everything unless you include inline assembler or link to libraries that have assembler routines like communicating with I/O directly.

    It's close enough though for bare metal since only with the exception of device drivers, super-optimized routines for particular chipset types or extensions, it's good enough for the kind of micromanagement required for fast software and with a good compiler, nowadays the results are good enough performance-wise.
     
  7. Apr 30, 2012 #6
    The only problem with C is that it teaches "bad habits" in the world of Object-oriented programming.
     
  8. Apr 30, 2012 #7
    Object-oriented programming? Could you please explain what you mean.
     
  9. Apr 30, 2012 #8
    Wait. Didn't you just say you had done a lot of research and concluded that C would be the best language to start with? I think, my friend, that your research might have been somewhat incomplete.

    Also, Google is your friend.
     
  10. Apr 30, 2012 #9
    Depends on what you want to do.

    C is closer to the metal, yadda yadda, but you lose some functionality and don't gain much over the equally fast but object oriented c++. Before anyone corrects me by saying c is more basic and therefore faster than c++, remember that c++ is so popular, and a lot of money and effort has gone into optimizing it, while c optimization has been pretty stagnant.

    To answer your question about object oriented programming, or OOP, first of all c is procedural i guess, and c++ is OOP. In C++ you can create a class, say a triangle class, and create different instances of triangle. These are all part of the triangle class, but operations on triangle_1 don't effect triangle_2 don't effect..... The class also defines methods or operations you can do on the triangles, like if you wanted to stretch triangle_4, or access what the base of triangle_6 is or whatever. You're modifiyng and accessing "instance variables" of the different "instances" of the "class". Each triangle is an instance of the triangle class.

    Basically OOP creates a more pretty way to keep track of many "objects", and their seperate instance variables. Otherwise you might have to do some ugly multidimmensional arrays or something, but those have there purpose, don't get me wrong.

    Most video games are written in c++ btw.

    If I'm trying to throw together a quick program, python is still great for simple scripts, to even modeling, and it's really easy.

    If I was writing an intense physics engine with 3d visualization, I'd pick c++.

    If I was writing code for a microcontroller, I'd probably use C.
     
  11. Apr 30, 2012 #10
    All that said, you can do anything with C :) It's just a matter (how long it takes to program) vs (how important is performance) for a task by task basis. You can't go wrong with learning C
     
  12. May 1, 2012 #11

    rcgldr

    User Avatar
    Homework Helper

    C++ is an extension of C. Object oriented programs have been written in C, and procedural programs in C++. Even in the case of OOP, member functions of an object end up being procedural, so the innermost code of most well designed programs doesn't end up that much different.

    Unless you plan to be a programmer, or your studies or a future job involves programming, I'm not sure what the point is, but the same applies to a lot of subjects you learn in school, some of which are more for academic purposes as opposed to having a practical purpose.

    You didn't mention what your plans are that might involve programming.

    There's no reason that C can't be the first programming language you learn. If your studies or a future job involves programming you should find out what language is being used and perhaps start with that language, or switching to that language after spending enough time with C to get an idea of how to write programs.
     
  13. May 1, 2012 #12

    This may sound a little far-fetched, but I've heard from a couple of peolpe that you can do something with physics equations that involves programming? I'm not completely sure, but I found myself to be interested in what they were telling me so I decided I would give it a shot. I'm really interested in physics and by the time I start my physics course next year I was hoping I would be pretty good at programming. I am studying physics this summer, so no rush. I just think that it would be really cool, and why not persue my interest?
     
    Last edited by a moderator: May 1, 2012
  14. May 1, 2012 #13

    rcgldr

    User Avatar
    Homework Helper

    For physics or engineering, you might find a very high level language like Matlab, which is more of a mathematical tool than a programming language, to be useful. There's no reason you couldn't learn both C and Matlab.
     
  15. May 1, 2012 #14
    Oh ok, thanks.

    I've been so lost on deciding which language to learn first. Everyone tells me something different... I will probably learn C then Matlab.

    Thanks for the help!
     
  16. May 3, 2012 #15
    Python has some nifty Matlab modules.
     
  17. May 3, 2012 #16
    Since you mentioned you were in it mostly because it'd be useful in physics, I recommend staying away from C. Matlab is a good choice, but I would still recommend (as I do to practically all beginners) to learn Python. It's a real programming language (somewhat unlike Matlab), and it's powerful yet easy (unlike C, which requires you to do all the nasty memory allocations by hand).

    This is not to say that you should never learn C or Matlab (you will most likely learn the latter in college anyway), but *starting* with Python is highly recommended.
     
  18. May 3, 2012 #17
    Too late, the book just arived. And I'm really interested in C, and I've done a little of Python. Would you reccomend learning C, then Python, then Matlab?
     
  19. May 3, 2012 #18
    No. I'd go for Python (which can easily be learned by using tutorials on the internet), then C (since you already bought the book), then Matlab (since Matlab is awesome).
     
  20. May 5, 2012 #19
    Alright, how long do you think it would take me to learn Python and C pretty thoroughly if I spent about an hour aday 7 days a week?
     
  21. May 5, 2012 #20

    chiro

    User Avatar
    Science Advisor

    It depends on what you call thorough.

    One thing that you should keep in mind is that a lot of what is learned in programming has to do with debugging code and this takes a long time to do when you start off. As you get better though, the time needed will decrease though, but you will be working with larger repositories which means the problems get more complicated.

    I think you will need at least a few years minimum for this amount, probably a lot more. Again it depends on how thorough you want to be.

    You could probably learn the actual language components a lot quicker, but if you want a thorough understanding you will have to apply your programming to a number of different situations and applications to reinforce it all.

    Don't be discouraged though because you'll find that even if you have been doing stuff for a while (like say ten years), there is always stuff you don't know and that's a good thing IMO.
     
  22. May 5, 2012 #21
    Well I actually wouldn't learn it that thoroughly, I'm mainly starting programming so I can do certain things invloving mathematical/physics equations for my classes next year. They wouldn't be that complex, it's just highschool physics and pre-calc. I'm a freshman so I was hoping I could start to learn alot over this summer and get more advanced my next 3 years of highschool.

    As to which I understand one must use Matlab for that sort of thing, not for sure though. I really never planned on spending that much time with C, same with Python if I choose to learn it as my first language or even learn it at all. Then again I dont even really know what I could "do" with Python or C. If you could, could you please explain some of these things to me?

    Thanks.
     
  23. May 6, 2012 #22

    chiro

    User Avatar
    Science Advisor

    If its mainly computation for science/engineering/computational kinds of things like that then MATLAB would definitely be the platform that you should learn since you don't really have to worry about the stuff that takes away from what you need done.

    This is what software developers have to do anyway since projects are so complex. Usually they get some kind of library and then they just call one or two routines to do something complex that they don't have to worry about.

    I don't know about Python, but if you can include libraries and call outside DLL's then you can pretty much do anything in Python that you can do in C. The big difference is that it won't be as fast as it could potentially be in C and that you probably won't know how everything works in detail in Python.

    It isn't a bad thing though especially if you starting out. Getting stuff running quickly is important and if that means using Python over C (especially when starting out), then OK that's what you need to do.

    So with regard to what you can "do", it depends on a) the language features and the environment features, b) the libararies that come with python (and that other people make) and c) whether you can include custom DLL's (to do say Operating System things or functionality which is not included in the Python dev environment).

    I think Python allows all three which means that you can pretty much do everything in Python that you can in C and with the speed of computers nowadays, unless you need really really optimized code for something then just use something like Python.
     
  24. May 6, 2012 #23
    Alright, thanks for the help!

    One last thing, how long will it take me to learn the componets of C? I need to make a schedule of how to study C so I can move onto Matlab in optimized timing.
     
  25. May 6, 2012 #24

    chiro

    User Avatar
    Science Advisor

    I have a couple of points for your question.

    The first one is that C is a procedural language and has procedural constructs. The constructs for procedural languages include a standard flow-control which itself includes loops, branching, and function calls and it's own flow-control. Within function-calls you get concepts including recursion which is an important thing to use (and is used quite extensively).

    The next common thing is state-control. The state-control concerns things like data operators and how data is both read in, transformed and written back somewhere. You have arithmetic (including addition, subtraction, multiplication, division and modulus) for integers as well as for floating point numbers of different precision (but you don't have modulus functions for floating point unless you want to define it yourself).

    Apart from arithmetic operations, you have bitwise operations (AND,OR,XOR,NOT), shift and rotate operators (again bitwise) as well operators that deal with reading and writing memory. In C you won't have to tell the CPU this: you just declare variables in the right way and the compiler will sort out this kind of thing.

    Branching also includes comparison operators that include bitwise, normal numeric comparison (like less than, greater than, equal to etc). Comparison bitwise operators are not the same as normal bitwise operators.

    You also have to learn things to do with memory which includes allocating and deallocating memory, pointers, structs, and how things look in memory in terms of pointers. Things like MATLAB allow you to get away without having to know this kind of thing in a deep way.

    Then along with all the above, you have specializations of these concepts as well as issues related to the syntax and its use in the C language. Syntax is something you will learn a lot more when you have to write code, and ultimately compile. There's no real shortcut for this: you write code, compile and see what happens.

    This is a really short answer to your question, but I hope it will still be useful.
     
  26. May 6, 2012 #25
    It does, thanks for the help!
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook