Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

brent0saurus

macrumors regular
Original poster
Feb 16, 2006
228
1
This has to be the longest thread about "Hello, World!" i've ever seen. =)

At least we've established that the source material was horribly misleading at this point.

-Lee

can anyone recommend a better online tutorial? another user posted some great links for unix. but this tutorial seemed like a nice easy step by step process to learning the basics of C but i guess it's very misleading. i should've known from all the grammatical errors.
 

JVene

macrumors newbie
Jul 22, 2008
29
0
I think I posted something along these lines before in this thread, but let me put it a different way.

One problem is the assumption that a step by step guide on the basics of C makes any sense. I know C, and I know it doesn't.

C was created to support machine level portability; the ability to support something close to machine language performance/efficiency, without tying the code to a particular processor (this was back in the days when the owner of a computer might be expected to MAKE their own operating system, simply as part of ownership)

From this viewpoint, C should be understood as a mixed level language, something that mixes assembler level programming with higher level programming constructs. You don't typically interact directly with the processor, but you do interact rather closely with the machine itself (memory management is the primary area every C programmer must work with at this level).

This means, quite simply, that the study of C isn't easy, and doesn't lend itself to either a simple step by step guide, or any notion that an understanding of the basics would somehow be enough to give you the skills to actually make anything. There is a 'critical mass' of comprehension required before any of it makes enough sense that the student is functional beyond the level of introductory, trivial applications. I don't mean that as a judgment, I'm making statement regarding the nature of using C for making software.

C requires the programmer to have a sufficient understanding of the machine to take control. It's used to make operating systems, high performance applications (especially before C++), and is not usually used to make less ambitious applications.

As such, it will require the student to cover a number of books or studies to get past the basics, because in C, the basics are actually fairly deep when compared to the introductory lessons for languages like Java, C#, Visual Basic or the like.

It's been so long since I learned C that I have no links (there weren't links in my student days ;) ), but I can say that you'll need to cover lots of ground before there's enough of that critical mass for you to feel 'capable'. Oddly, hello world does bring up a host of issues, as you've discovered, that's just a lot more complicated than you'd ever expect.

That said, I should also point out that those of us with years of experience cringe at the notion of a C beginner's path to study. I went through it, but to make a hello world application in C++ is actually easier than in C, though I can write it almost exactly the same way, or I can use C++ idioms so that much of what you've already learned doesn't even apply. It actually doesn't help to learn C before learning C++, if you assume that C++ is a language you'll ever want to learn. Obviously, though, if you're going to learn objective-C, even you intend to use objective-C++, you'll need to understand enough of both.

The learning curve to cover the basics is probably about 6 months. Any less and you know enough to be 'dangerous' but not enough to get out of trouble. In that time you'll revisit the same ideas from different perspectives, which is why you'll probably not find a really good, step-by-step guide.

I know there are a few that position themselves as such - introductions to C programming, but you'll probably do better with some of the 'standard' texts rather than online tutorials. You'll need the descriptive narrative from an authoritative author that can explain things clearly, and as completely as required for a solid introduction in C. Without a solid introduction, you're going to wind through a longer path to understanding, just as you've encountered thus far.

Books (big ones, 900 pages or so) are the way to study this language, along with trial, error, debugging and experimentation - guided by research from knowledgeable authors.
 

dcr

macrumors member
Jun 10, 2002
57
0
This tutorial sucks at least...

o.m.f.g. what else can I say

how about that the comparison section makes the totally newbie mistake of using the assignment operator instead of equality? or that it thinks !(a>0) means a is negative? :)

seriously, stay away from this site unless you want to be confused.
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
I agree with JVene that simple step by step tutorial is not enough to learn C programming. You need solid book, persistence and a lot of free time. You can make substantial progress in six month. I'm not familiar with current crop of beginners C programming books but can recommend latest edition of good old "C Primer Plus" by Stephen Prata.
Classic "C Programming Language" by Kernighan and Ritchie is a good second book for mid-level C programming.
If you want to get a taste of programming in a shorter time I would strongly recommend to start with Python:
Python Programming: An Introduction to Computer Science by John Zelle
http://www.amazon.com/Python-Programming-Introduction-Computer-Science/dp/1887902996/
and
Python Programming for the Absolute Beginner, Second Edition (For the Absolute Beginner) by Michael Dawson
http://www.amazon.com/Python-Programming-Absolute-Beginner-Second/dp/1598631128/
 

brent0saurus

macrumors regular
Original poster
Feb 16, 2006
228
1
To learn C, not to learn C...
I'm confused as what relates to what...
Jvene helped a lot (and i thank you for that) with my "what to learn first" problems but i'm still a little confused. Jvene says that "It actually doesn't help to learn C before learning C++, if you assume that C++ is a language you'll ever want to learn."
but then goes onto say that if i want to learn objective c and objective c++, i'll need to understand both.

I've heard starting with xcode is good because it's easier and faster, but bad because i won't know the basics, but i don't even know what xcode is besides (i think) a tool to make developing easier. does it use objective c? i don't even know the difference between c and objective c.
but then i also (think) i know that objective c is the most popular language for programming for the mac, and then cocoa is the framework that makes it easy to draw list views and things like that.
maybe telling everyone what i intend to do will help with figuring out what i should learn first?
I have a bunch of ideas for some tiny menubar apps, safari plugins, and some finder tweaks (which i'm not even sure is very possible) i've seen Onyx do it but i believe those are things already built into the system that onyx is turning on? but i'm sure i'll have more ideas in the future but hopefully by then i'll have learned things to help me write those apps.
i don't know if this helps decide what i should learn first but i hope it does. thanks in advance.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
To learn C, not to learn C...
I'm confused as what relates to what...
Jvene helped a lot (and i thank you for that) with my "what to learn first" problems but i'm still a little confused. Jvene says that "It actually doesn't help to learn C before learning C++, if you assume that C++ is a language you'll ever want to learn."
but then goes onto say that if i want to learn objective c and objective c++, i'll need to understand both.

I've heard starting with xcode is good because it's easier and faster, but bad because i won't know the basics, but i don't even know what xcode is besides (i think) a tool to make developing easier. does it use objective c? i don't even know the difference between c and objective c.
but then i also (think) i know that objective c is the most popular language for programming for the mac, and then cocoa is the framework that makes it easy to draw list views and things like that.
maybe telling everyone what i intend to do will help with figuring out what i should learn first?
I have a bunch of ideas for some tiny menubar apps, safari plugins, and some finder tweaks (which i'm not even sure is very possible) i've seen Onyx do it but i believe those are things already built into the system that onyx is turning on? but i'm sure i'll have more ideas in the future but hopefully by then i'll have learned things to help me write those apps.
i don't know if this helps decide what i should learn first but i hope it does. thanks in advance.

It sounds like the things you want to do will require Objective-C (not sure about safari plugins, actually, but the other things you mentioned would). To that end, I would recommend starting with C. Someone immediately after I post this will tell you don't need to, because it's totally subjective, but I think a solid foundation in C will take you a long way in understanding Objective-C.

C++ is different... I still think having a solid understanding of C will be helpful. You can start with whatever you want to, but for some people it's probably easier to grasp C++ after they know C, because they can focus on learning the more advanced features of C++ like Objects and templating when they know the basics of programming already.

XCode is an Integrated Development Environment (IDE). It integrates an editor that includes code completion, syntax highlighting, and other niceties with a number of compilers (Java, python, C, C++, Objective-C), a debugger to help you track down bugs, and other programming tools. It also interacts with Interface Builder, a separate program to help you design Graphical User Interfaces (GUIs) in OS X.

It gives you a lot of power, but also abstracts a lot of the nuts and bolts for you. If you already understand the nuts and bolts, and need the power, this is good. If you don't understand the nuts and bolts and your first learning it's abstracting what you're trying to learn, and I think this is detrimental. Again, of course, someone will post immediately after this saying that it's the best way to learn, because this is totally subjective.

Objective-C is a general-purpose programming language which has found it's niche with OS X programming because the Cocoa Application Programming Interface (API) is the best supported API for interacting with OS X. There is a C++ API called Carbon, but it is no longer being improved and may have it's support removed completely or subjugated in future OS releases. If you are starting now and want to target OS X, Objective-C and Cocoa are the way to go.

In all honesty, though, what's most important is starting. Dive in to anything. Maybe it's not what I, or anyone else, says is best. That doesn't really matter. Starting to learn how to program, learning about algorithms, and how to solve common programming problems will serve you best. If you do that with python or C++ or C, with or without an IDE, it really doesn't matter. Once you get started moving around between languages, environments, and paradigms is not terribly difficult. There are a few counterexamples (BASIC seems to be widely regarded as teaching bad habits that are hard to break), but in general just get started with anything and worry about what you want to focus on/specialize in later.

Good luck, get programming.

-Lee
 

brent0saurus

macrumors regular
Original poster
Feb 16, 2006
228
1
thank you very much, Lee. That was a huge help.
a lot of you listed a bunch of books for me to get. Does anyone know "Cocoa Programming for Mac OS X" by Aaron Hillegas?
I've heard this book is great but was wondering if i need to know C before i get into this or if it teaches me C along with cocoa.

Also, does anyone actually use C for programming for the mac? Or do you learn C, so that you can learn Objective C, and then you use Objective C.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
thank you very much, Lee. That was a huge help.
a lot of you listed a bunch of books for me to get. Does anyone know "Cocoa Programming for Mac OS X" by Aaron Hillegas?
I've heard this book is great but was wondering if i need to know C before i get into this or if it teaches me C along with cocoa.

Also, does anyone actually use C for programming for the mac? Or do you learn C, so that you can learn Objective C, and then you use Objective C.

most programming on the mac will be Objective-C, but since it is a proper superset of C you can still use C and it will work fine. A lot of basic C concepts are superceded by Objective-C classes, like char * strings replaced by NSString, arrays by NSArray, etc. The real drive is to learn concepts like flow control, pointers, functions, etc. that you can apply to Objective-C and other languages.

-Lee
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
and what is Python? i'm reading this tutorial now that was recommended ...

Python is general-purpose, high-level programming language.
Python supports multiple programming paradigms: procedural, object oriented, and functional. Python is a great as a first programming language. Many introductions to programming use Python.

i like how it's organized and seems easy to follow buuuut doesn't seem like it will help me with learning C
If your sole goal is to learn C - you better stick with C. If you want to learn basic programming concepts (variables, functions, classes, control flow, data structures, files) Python is a good language/environment to start with.
Majority of people starting with C/Objective-C will never make it. If you can learn basics with Python you have a better chance to learn C (low-level system programing language) and Objective-C later. For many tasks Python is all you need - you can write web apps, command line utilities, automation scripts, servers etc.. The only area where you really need Objective-C is GUI apps. The same is true for Windows (C# and C++).

In general, majority of people grossly underestimate complexity of programming. Following essay "Teach Yourself Programming in Ten Years" http://norvig.com/21-days.html may be useful for you.
 

brent0saurus

macrumors regular
Original poster
Feb 16, 2006
228
1
Python is general-purpose, high-level programming language.
Python supports multiple programming paradigms: procedural, object oriented, and functional. Python is a great as a first programming language. Many introductions to programming use Python.


If your sole goal is to learn C - you better stick with C. If you want to learn basic programming concepts (variables, functions, classes, control flow, data structures, files) Python is a good language/environment to start with.
Majority of people starting with C/Objective-C will never make it. If you can learn basics with Python you have a better chance to learn C (low-level system programing language) and Objective-C later. For many tasks Python is all you need - you can write web apps, command line utilities, automation scripts, servers etc.. The only area where you really need Objective-C is GUI apps. The same is true for Windows (C# and C++).

In general, majority of people grossly underestimate complexity of programming. Following essay "Teach Yourself Programming in Ten Years" http://norvig.com/21-days.html may be useful for you.

Great, thanks! I think i'll try out that Python tutorial, then. Hopefully some of that will transfer to C. And that essay was great. I can already see how long this is going to take; learning one langauge before another, before another, etc etc... pretty frustrating.
thanks again!
 

Cromulent

macrumors 604
Oct 2, 2006
6,816
1,101
The Land of Hope and Glory
Great, thanks! I think i'll try out that Python tutorial, then. Hopefully some of that will transfer to C. And that essay was great. I can already see how long this is going to take; learning one langauge before another, before another, etc etc... pretty frustrating.
thanks again!

The first language you learn is the one that always takes the longest. After you know one or two languages you should be able to pickup a new language (at least enough to write a hacked together application) in a couple of weeks.

The hard bit about programming is learning the concepts. Learning the language itself is the easy part.
 

JVene

macrumors newbie
Jul 22, 2008
29
0
The hard bit about programming is learning the concepts. Learning the language itself is the easy part.

Generally this is quite true. Anyone undertaking a causal or unstructured approach to learning is going to have a longer road learning the concepts behind the science, simply because they're not usually among the things you learn in short on-line tutorials or many of the books that cover a particular IDE (Like those that focus just on XCode or Visual Studio).

It's something like learning the alphabet and the grammar, but then having to figure out just what to say; how to paint a picture in words, set a scene, build a narrative up from smaller details. You don't want your applications to work and act like a kid telling a story with a series of "...and then, he goes like...." - all delivered as if they were a series of questions.

In the higher levels of C++, theory and language begin to merge, and the study isn't particularly easy. Templates, for example, support generic programming and an alternate form of polymorphism, which can't be used simply by knowing the language.

To expand on a point I made earlier (which the OP mentioned was confusing), for the Mac there are three languages involved; objective-C (the part that's unique and NOT C), C, and C++.

C++ was designed to 'absorb' C. When you write in C++, you have a significant blend of the older C syntax within primitives. That is, the use and organization of an object is similar in C++ to that creation of a struct in C. There are minor extensions made to turn a C struct into a C++ object. For objective-C, however, the 'syntax' used to create an object is entirely different from C (or C++), and appears to be a completely different language 'tacked on' to C (some don't like this, others suggest it's a benefit). There is an 'interface' between these languages which must be understood, especially in Mac development, where all 3 may be involved.

You can simply obviate the problem to two languages by deciding NOT to use C++. For the purposes of a 'divide and conquer' plan on learning this stuff, that's probably wise, but C++ is far better for most application use than C. However, there's that interface between the languages, and since objective-C was designed before C++ was generally available, even with objective-C, the interface between the languages is based on C level concepts.

Here's what I mean using a small example.

Objective C makes use of NSRect. Most of the objects in AppKit are 'genuine' objective-C objects, and all of them are named beginning with NS. NSWindow, for example, is an objective-C object representing an operating system object (the Window, obviously), and it has some data associated with the window. NSRect can be used to define the size of the window, but NSRect is presented as a C style struct, not an objective-C object. This struct has a point (the lower left corner), and a size (width and height). NSRect looks the same in C++ as it does in C, but it can be used differently.

In C, to copy the contents of the NSRect from one to another, you can't say this:

NSRect r1, r2;

...assume r2 is setup with some values

r1 = r2;


The line 'r1 = r2' is an assignment, and C doesn't 'know' how to do this for you. In C, you have to use something that copies the memory from r2 to r1, or copy each member value within the NSRect struct. In C++, a default 'assignment' operator is created, so r1 = r2 makes sense to the compiler. In C, a struct is just a way of 'structuring' some related data together, but it doesn't 'do' anything beyond that. In C++, a struct is an 'object' - the same as a 'class', differing only in default permissions. As a result, you can 'do' things with NSRect in C++ that you can't do in C.

In C, r1 = r2 might be replaced with;

memcpy( &r1, &r2, sizeof( struct NSRect ) );

Note quite as obvious is it?

In C, you might also use;

r1.origin.x = r2.origin.x;
r1.origin.y = r2.origin.y;
r1.size.width = r2.size.width;
r1.size.height = r2.size.height;


If you extrapolate this oversimplified example to the complexity of more advanced development, perhaps you can see why someone who knows C++ well would much prefer C++ (and thus, r1 = r2 ) as the accompaniment to objective-C, instead of C.

Unfortunately it's not entirely that simple (though close).

The 'interface' between C++ and the 'objective' part of objective-C aren't formalized by outside standards bodies the way the C and C++ languages themselves are handled. As a result, there are a few rough spots that require you to understand at least some of the 'C' components in this mix. However, you can easily discover them (well, relatively) as part of a study of C++, rather than as a study of C.

For C programmers learning C++, there must be a host of practices, common in C, which must be 'unlearned' in order to apply replacement techniques used in C++. Habits learned as a C programmer must be dropped, and habits are hard to break. The best way to avoid 'bad C style habits' is not to pick them up in the first place, and learn C++ before learning C. Many think this is backwards, because, in my learning days, I had no choice. C++ didn't exist; I had been a C programmer for years before C++ was created. The language was designed, after all, to allow C programmers to gradually adapt to OOP/OOD techniques.

The reality, though, is more associated with practices common to C development. The use of 'smart pointers' in C++ is one primary focal point. C uses 'raw pointers' - the same kind used in assembler programming. C++ can use them, too - and most of us did that for a long time (especially before templates were implemented to permit the creation of smart pointers).

Smart pointers avoid a great many debugging hours and fragility in working code that is simply too important to ignore. C programmers might find them annoying or unnecessary, opting for the familiar 'raw' pointer. Learning to USE advantageous constructs like the smart pointer, before learning something more prone to bugs and design flaws, gives a base of 'better habits' upon which to build one's own practice. It is for this reason (extrapolated out to dozens if not hundreds of such concepts) that learning C++ first is a better choice.

If the 'learn C first' concept is based on knowing 'the base most concepts' first, then the logical extension of that logic would mean you should start with assembler first. Clearly that's not helpful, but it can work (I came from that path). It's much easier to learn concepts that work best, and later, to dive under the hood and see what it takes to make that happen, digging DOWNWARD toward the raw machine, rather than upwards toward higher organization.

Taking that to a logical extension, it's probably better to 'start' the study in Java, Python or related languages.

I'm not one to point, though. My first exposure to programming was on a 6502 based machine, using assembler. When I 'dabbled' in BASIC occasionally, I resorted to 'poking' machine language code in there to make things actually run. To me, C was a 'rescue' of sorts. We've come a long way from that time, and there's decades of ground to cover between 6502 assembler and modern languages and operating systems. The older timers, like me, lived through it so you won't have to :)
 

brent0saurus

macrumors regular
Original poster
Feb 16, 2006
228
1
wow, thank you very, very, very much for all of that. I have a much better understanding of what i'm going to do now. i think i'll use that recommended python tutorial (unless i can find a good c++ tutorial) then C where that takes me... that was really bad i'm sorry. but yeah, then buy a book once i get more into it.
thanks again!!! you've all been a huuge help.
 

m1ss1ontomars

macrumors 6502
Oct 1, 2006
273
2
okay so i just typed "cd /users/brent/desktop and terminal came back with "new-host:/users/brent/desktop brent$" and then i type "$cc hello.c -ohello" and again i get "-bash: hello.c: command not found

:(

i must be doing something wrong

You're typing in the dollar sign, but Terminal has already given that to you. Don't type the dollar sign!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.