New to programming

Discussion in 'Mac Programming' started by Little Rich, Oct 29, 2006.

  1. Little Rich macrumors newbie

    Joined:
    Feb 10, 2005
    #1
    Hi all, sorry if this has been asked a thousand times before but basically I want to start programming C or C++ on the mac. I've been making web sites since the dawn of the web and know xhtml, css, asp like the back of my hand and am beginning to learn c# / asp.net, but recently I've been trawling the net and what I've come across makes me think that I'm going down the wrong route! I understand the fundamentals of oop and have a basic knowledge when it comes to database design / programming but don't really understand it all in great depth. I read threads and see people banging on about memory management / garbage collection / this and that but haven't a clue what it all really means... Would you recomend C / C++ a good place to start? Any books? Online tutorials? What tools do I need on the Mac?

    PS this is to start application programming, not website scripting.

    Cheers guys & gals
    Rich :)
     
  2. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #2
    I've said things like this in this forum before and I'll say it again. You can start with any language, the most important thing is to learn a lot about how programming languages work. This is something you can pick up as you switch between languages or read about formally.

    I personally started with C, and I think it's a great way to learn a lot about how programming works and how computers work. It makes transitioning to a lot of languages easy because in C you have to do the most low-level work. Those details get taken care of under the hood in higher level languages, but to be a really good programmer you need to understand what is going on and C will give you that insight.

    The inventors of C still right what I consider to be the best book on C for beginners ever, called The C Programming Language by Kernighan and Ritchie. It has exercises and lessons so it is well structured to teach you from beginning to end.

    As for tools, gcc and a text editor is all you need to start C, and it's the only way to start, imo. Don't use Xcode or an integrated development environment for a while, you don't need it and setting it up for what you need will only be more frustrating. I still don't use IDEs for even complex app development, and a lot of people seem to get hooked on them and can't think without them after a while.
     
  3. mufflon macrumors 6502

    Joined:
    Sep 15, 2006
    #3
    another good road to venture on for your first language would be java - nice, powerful and versatile - mobile as well as it's platform independant to a very high degree...

    ... oh and you don't have to manage memory much - which is nice imo - no need to consider that kind of stuff when you've just started...
     
  4. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #4
    I disagree, I think that knowing what's going on in memory is important to the beginning programmer. It allows programming in Java, etc. to seem taht much easier, and if you start off with a garbage collected language going to C seems that much more difficult. Not to mention you need to learn the concept of references vs. values and it is quite explicity in C.
     
  5. Little Rich thread starter macrumors newbie

    Joined:
    Feb 10, 2005
    #5
    Yea I have to agree with you on this one. So gcc and textedit - sorted. Like I said in my previous post I understand the logic of programming no problem but I want to learn the low level stuff like the memory management and what is actually happening to the computer when I right int = 5 etc.

    Cheers for your advise.
     
  6. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #6
    I think the most overlooked aspect of getting into programming is what is your end goal. That is, what kind of software do you wish to create that you cannot find/build from an existing project?

    It really does not make sense to spend the effort and time to reinvent a content management system (CMS) when there are tons of free ones already in existence with more features and bug fixes than you could ever hope for.

    If you want to make web apps I would suggest learning Ruby on Rails, as it is object orientated and has excellent Mac support already (including a dedicated IDE).

    If you want to learn to make desktop software, learn ObjectiveC and the Cocoa framework with the Xcode tools (IDE, Interface Builder for making the UI).

    Buy some books on the subject and language (usually anything from O'Reilley is recommended) and read and read and practice. Download sample code, read and read and practice with that. There is no magic one-day solution to learning (and becoming proficient in) programming for any platform/language.
     
  7. dummy1 macrumors newbie

    Joined:
    Oct 30, 2006
    #7
    Programming

    Yes i am idiotic i know. I am new to this fourm and programming. Me and my friends have been planing a online game for years now and i am ready to start learning but know nothing except that Macs r cool. The internet has very little information that is not confusing. I need help!!!!!!!!!!!!!!!
     
  8. dummy1 macrumors newbie

    Joined:
    Oct 30, 2006
  9. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #9
    Depending on how nitty-gritty you want to get about memory management and understand variable declaration, there are two things you want to learn.

    1) Assembly. It doesn't really matter which flavour, IA-32, IA-64, MIPS, etc. all cover the same fundamental ideas, where you learn how a compiler implements loops, deals with the stack, etc.

    2) Also, there are several books on programming languages that go over what you're interested in. Essentials of Programming Languages takes you through writing an interpreter in Scheme for a basic language. Many books on LISP also teach you about language interpreting.
     
  10. Little Rich thread starter macrumors newbie

    Joined:
    Feb 10, 2005
    #10
    Yes this is exactly what I'm after, I tried assembly years ago but I got kinda lost with it - where do you recommend starting with this? I'll get that book when I have a spare £20 or so.
     
  11. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #11
    I disagree with this. I've been a professional programmer for 10 years, and programming has moved *so* far beyond this. As a professional programmer, you're almost *always* building on top of high-level APIs, no matter what language you're programming in. You're not reinventing the wheel every time.

    I think the important things to learn as a beginning programmer are:

    1) variable scope
    2) looping/conditionals
    3) functional decomposition/abstraction

    Beyond those concepts, basic functional programming is not that much different from algebra/math concepts that the student should already be familiar with (including functional decomposition/abstraction). After mastering that, the next thing to learn would be object-oriented programming concepts.

    Also, I think beyond syntax or technical concepts, the most important things that a programmer should learn are good *habits*, that will help them both as students and also later in their professional life. Things like:

    1) writing clear code with obvious variable names, program flow, etc. Any programmer can write code that a computer understands - but a skilled programmer will write code that a *human* can understand.
    2) writing good comments/documentation (this is important not just to explain your code to other people, but also to remind yourself what your thinking was when you coded something).
    3) writing code iteratively (get little bits of the project working at a time, rather than trying to do it all at once),
    4) write test cases/scripts for your software
    5) use any tools like debuggers, etc. when they are available for your language

    Granted, I am a bit biased here. My first language (learned it in an intro to computer science course in college) was an interpreted, garbage-collected version of LISP called "Scheme". I feel like hiding the details under the hood was *precisely* what was needed in order to let me focus on the more important concepts in software engineering. C was my 2nd programming, and I just found it to be uglier and more bug-prone. My 3rd language, in a more advanced computer science course, was a garbage-collected version of C++. It was a joy to work in and like I said, I am a bit biased here since the professor was a huge proponent of garbage collection (5% performance overhead as a tradeoff for vastly fewer bugs). My 4th language was Java, which actually turned out to contain almost all of the features (garbage collector, Collection classes, assertions, etc.) that my Professor advocated in that C++ class.

    So anyway, sorry for the rant, but for Application programming I would definitely advocate Java. I once did a freelance project for a professor at New York University and was able to program it on my iBook even though the target deployment machine was a PC. That's a huge advantage: you can program something specifically for the Mac, and it yet it will probably run on the PC (depending on what you were doing with it).
     
  12. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #12
    There are some good textbooks. I started with IA-32 on a windows platform and have since switched to living in Unix/Mac. I can't recommend the book I used; it sucked. I would look at textbooks on Computer Architecture that include Assembly as part of their book. Because, really, Assembly is all about understanding what is going on. It's not hard, per se, but you have to be willing to start basic and deal with just being able to add and subtract and move numbers until you're comfortable.
     
  13. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #13
    I applaud your desire for knowledge, but at the same time I don't think there's much value in it beyond intellectual curiosity. I mean, for computer science class I've programmed computers down to the 1's and 0's. I mean, I literally had hundreds, maybe thousands of 32-bit instructions in a software program, and had to know the purpose of every single bit in the instruction. Was it interesting? Yes, definitely. Was it useful? I'd have to say no, not really. I'm glad I know how computers work, but it actually has made absolutely no difference to my career as a programmer. As a programmer, I don't *have* to know how a computer is magically executing my code. I mean, yes, I should be aware at a high level of things that might affect performance: excessive disk reads/write, network performance, memory usage, etc. But I certainly don't need to know these things at a detailed level.
     
  14. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #14
    I have to disagree with you strongly here. I think you have not done very much with functional programming if this is your opinion. Lambda calculus and reduction are very powerful concepts that let you do a LOT more than their algebraic counterparts. The concepts of functional programming are very important if you want to understand the theory of creating and implementing programming languages, which I gather is what this poster was curious about at least in part.

    Also, it is true that API's and libraries are how rapid development occurs, but I guarantee you the writers of all of that knew a lot of technical detail about what they were doing. I'm sure they were well grounded in algorithmics, code profiling, and memory management.

    Any programmer should know these. Learning these things shouldn't be instead of the things I described, but along with them. If you can't do any of the above, chances are you wouldn't go beyond being a coding monkey in the professional world and probably accomplish little in academia.

    You may hate C, but it is the foundation upon which a lot of computing exists. Most scientific computing is done in C or C++. Almost all real-time programming is done in C. The majority of operating systems that you use today (*NIXes, Windows) are all programmed in C. Garbage collection may be useful, but it is also inefficient, non-deterministic, and a poor candidate for many systems, especially large distributed and multi-threaded systems. Garbage collectors have to halt the execution of every single thread in a system to do what they want, that can't happen in a lot of different systems. If you can't manage your own memory, you shouldn't be programming anything on a decent scale. Even in garbage collected languages you have to understand memory management, unless you want to trigger garbage collection constantly.
     
  15. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #15
    Unless you want to write compilers or device drivers, in which case all of that is quite important.
     
  16. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #16
    The original poster said he wanted to program applications (desktop applications not web applications, to be specific). What percentage of programmers write compilers and device drivers? For application programming, it's not than important, IMO.
     
  17. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #17
    I think it is if you want to learn how to write code that is both elegant and efficient, but that's just a difference of opinion. There are many skilled programmers that can do just fine without this knowledge, though I find it quite good and useful to have.
     
  18. jnwhiteh macrumors newbie

    Joined:
    Nov 2, 2006
    #18
    This is a valid perspective, for a software engineer. There are a number of facets to computers that aren't software engineering. Based on the OP's post and first response, he is more interested in the science of computing, literally computer science.

    You can learn design fundamentals, and how to write pretty code, and how to work in groups, but the grasp a fundamental understanding of what is happening, not just the result, there are steps you can take. The OP was quite clear in stating that he wants to know how and why things work. To that end, rtharper's post is accurate. Any language will give you some understanding of what is happening internally, but C or a language that forces you to consider things is a very useful tool.

    Scheme, Lisp, Lua, Python, Java, etc. are great for teaching PROCESS and algorithms, because you are able to ignore the higher details of what needs to happen.. how memory is managed.. how arrays are build.. what happens behind the scenes.

    You can't just take a square peg and shove it into a round hole because it worked for you. As a professional programmed I'd expect that you would be able to recommend an appropriate tool for a specific job.

    That being said, I can heartily recommend the K&R book that is posted above. Some of the basic exercises in that book will give you a solid perspective into what is going on at THAT level of computing. From there, you can decide where you want to go, what interests you more.

    The pedagogy of computer science is a bit more complex than your simplification of what worked for you.
     
  19. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #19
    I am writing from the perspective of someone who has done a lot of application programming (not writing compilers or device drivers). I've done everything from small 1 week freelance projects to huge $30 Million, 2-year projects. I can think of very few cases where I or anyone on my project team has had to deal with low-level memory-management issues. I agree with you that a programmer should be aware if he's creating excessive objects in memory, and should make use of profiling tools. That needs to be done even in a garbage collected language like Java For example, in Java normally a finite amount of memory is allocated to the Java Virtual Machine, and you have to be aware of, for example, storing too much information in session state for a high-traffic web application. But I fail to see how the situation would be improved by doing away with garbage collection.

    Look, in my 10-year career I've done primarily Java-based web projects which are in general *very* demanding in terms of performance (think of the number of transactions on a large public website), but have a very high degree of object "churn" (because of the nature of web applications, most objects are Request scope and can be discarded after the request). And garbage collection just has not been an issue.

    True, there are scenarios where a language like C/C++ will be necessary. But for the vast majority of applications I don't think it really is. Certainly, to program a desktop application it's not necessary. Java or Visual Basic are greate applications for desktop application programming (though obviously the VB would be for Windows programming...)
     
  20. jnwhiteh macrumors newbie

    Joined:
    Nov 2, 2006
    #20
    As quoted below, the question was specifically how to better understand memory management and garbage collection, in addition to building applications and writing code on a mac. Regardless of whether you feel its a valid question or topic to be learning at his level, it doesn't seem to make sense to stifle his curiosity on something that could be very valuable-- or just plain interesting.

    I'd like to note that he didn't say "I want to learn how to write 2 million dollar professional applications today!" Rather than "Don't bother.. just use a language that does it for you," perhaps you could suggest some titles that helped you learn how to be a better software engineer-- HOW to write better comments, documentation, whatever you feel is important.
     
  21. rtharper macrumors regular

    rtharper

    Joined:
    Sep 6, 2006
    Location:
    Oxford, UK
    #21
    I think both of us are getting far afield of where we meant to go (in any case, I certainly am). I don't think garbage collection should be done away with. I program in Java, Python, and Haskell all the time. I think that garbage collection has its place in certain applications. That being said, a programmer is very lucky if he finds himself in a situation where his whole career lets him ignore memory management. At the very least, learning how free, malloc, calloc, and realloc are used in C is something every programmer should know.

    Also, the concept of pointers is essential to understanding even java (when I say pointers I mean the concept of references, which is more generalized, I suppose). Java uses references in a weird call-by-value sort of way, and understand what references and how they work can be very important, especially when dealing with concurrency.

    So don't get me wrong. I don't hate on garbage collection. I hate on ignoring the details of programming even if the housekeeping is done for you.
     
  22. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #22
    You make valid points. To original poster and everyone above: my intention is not to disparage the inherent value of learning how computers work. As I said, I wholeheartedly applaud it and I enjoyed studying it myself. I just wanted to make the distinction from what is really needed to do application programming. It seemed like the OP had this feeling that he was "missing" something to get to the "next level" of understanding. I was just commenting that I think that for application programming, in most cases you're really not missing much.

    That being said, I think it's definitely great to know the basics of computer science, much in the same way that it's good to know about any major field: e.g. physics, biology, economics, etc. To the OP: if you really want to know what exactly it is what it is that a software program does, and also the rudiments of want an operating system does, take a look at this freely available course material:

    http://ocw.mit.edu/OcwWeb/Electrica...ation-StructuresFall2002/CourseHome/index.htm

    The material is actually very clearly presented, and it's what actually started me on my current path and away from physics and electrical engineering. Take a look at the diagram on the front page :) As I said, this course will explain computers very well.

    And if you're interested in the actual intro to computer science class, it's here:

    http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/

    Very worthwile though you probably already know at least at some level a lot of the stuff on it...
     
  23. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #23
    P.S. Now I remember where the core of my Computing philosophy comes from: my Electrical Engineering background. Circuit design is light years ahead of Software Engineering. In circuit design, if you need a particular functionality, you find a chip that provides that functionality. It has inputs pins and outputs pins, and the functionality provided is clearly defined. The name of the game is: 1) abstraction, and 2) simple interfaces. So basically, I come from the mentality that black boxes and abstraction are great. I don't need to know *how* a chip works - I just need to know the inputs and outputs. There are people that specialize in integrated circuit chip design, and more power to them. But if my job is to *use* those components to build a higher level structure, I really don't *need* to know how the chip was implemented, I can narrow my focus to externally visible characteristics (which are not only input/output and latency, but can include power consumption, heat dissipation, etc.)
     
  24. jnwhiteh macrumors newbie

    Joined:
    Nov 2, 2006
    #24
    Thanks for the resources.. I parse almost anything put in front of me.. so I'll add these to my list =). OCW is a very handy resource to be sure!
     

Share This Page