# Learning C



## Slyck (Jun 5, 2010)

#include <stdio.h>

int main()
{
  printf(
So I've been thinking about learning C. I figure knowledge of something 
other than BASIC might be nice to have. Mainly all I do is casual 
time-killing programming. No fancy games. No 
operating systems. What are your experiences (if any) with this 
language? What should I expect? Is it worth the effort or should I go 
some other route?\n" );
}


----------



## Fallenmink (Jun 5, 2010)

http://www.reddit.com/r/carlhprogramming

Pretty good lessons if you've never touched a programming language before; read the comments as well.

This is pretty damn nice as well: http://www.cs.cf.ac.uk/Dave/C/

Just recommendations on where to learn.

-- On to the actual topic.

I'm the process of teaching myself C after learning a few higher level languages. For me, personally, it's a strange language since I've never had to deal with explicitly manage memory. Not sure what to tell you as to what you'll expect, but perhaps a headache or two, it's not that hard to learn (well...as far as I've seen so far!).


----------



## Nollix (Jun 6, 2010)

Most people will recommend these classics:

The Art of Computer Programming
Structure and Interpretation of Computer Programs
The C Programming Language

Personally I'm dubious of the worth of TAOCP/SICP nowadays, especially if you're not planning on learning ASM, but I respect them as definitive and classic works nonetheless. 
Starting with C is a bit rough though. Maybe learn some Python? After that, pick up a C for Dummies book or something.

EDIT: Also yeah, what net-cat said. Learning C/C++ is about as enjoyable as skewering your balls with a hot rusty nail soaked in sulfuric acid.


----------



## net-cat (Jun 6, 2010)

Slyck said:


> What are your experiences (if any) with this
> language?


It's actually one of my primary languages that I work with.



Slyck said:


> What should I expect?


Pain and suffering.



Slyck said:


> Is it worth the effort or should I go some other route?


Truly, it depends on what you want to do. From what you said, "casual time-killing programming," you may have better luck with a scripting language such as Perl or Python.


----------



## nrr (Jun 6, 2010)

Nollix said:


> Most people will recommend these classics:
> 
> The Art of Computer Programming
> Structure and Interpretation of Computer Programs
> The C Programming Language


OK, so, I originally learned (and, for what it's worth, started programming with) Scheme by way of SICP back in the 1990's, right around the time I turned nine.  It was a pretty good way to start the whole programming thing, and the exercises were doable even then with just a little guidance from my parents when I got stuck.  I, however, highly recommend the PLT version of this text, aptly named How to Design Programs, because it leaves out a lot of the rigid formality of SICP.

TAoCP is a computer science text.  It's more conceptual than much else, and Knuth goes very, very heavy on the math; the MIX/MMIX assembly examples and exercises are purely ancillary.  If you don't have the time to get a CS degree, and your main interest is not programming but actually algorithms and other fundamental parts of CS like graph theory, number theory, some elementary modern algebra, read a section or two per week and do the exercises.

The K&R C book is an absolute must.  If you can find one of the good ANSI/ISO C books that cover either C89 or C99, do yourself a favor and snag one of those as well.  Past that, you're at the mercy of your OS's supplied APIs.  If you're on Windows, read through every single header in every single path in %Include% in the Windows SDK shell and digest as much of the MSDN documentation as you possibly can.  If you're on something UNIX-like, see if you can't grab the sources for your respective operating system and read through them.  For Linux, this entails grabbing both the Linux kernel sources and the sources for GNU coreutils.



> Personally I'm dubious of the worth of TAOCP/SICP nowadays, especially if you're not planning on learning ASM, but I respect them as definitive and classic works nonetheless.


TAoCP and SICP really have nothing to do with assembly.



> Starting with C is a bit rough though. Maybe learn some Python? After that, pick up a C for Dummies book or something.


I actually recommend picking up Python these days as a first language.  It's "there is one and preferably only one way to do it" enough to give beginners a sense of what's right and what's wrong, much like the sense one gets while working, say, calculus problems, and it leaves the option of writing a hack here and there completely open.

That said, I would advise learning C and the appropriate assembly language for your machine's native ISA as soon as humanly fucking possible after that.  Getting a grasp on the lower-level details is still important, even if you find that you can't exactly hack it in either of those environments.  This way, you don't end up like, e.g., our OP Slyck here wherein you erroneously claim on some message board on the Internet that Linux has protection domains while Windows doesn't. 



> EDIT: Also yeah, what net-cat said. Learning C/C++ is about as enjoyable as skewering your balls with a hot rusty nail soaked in sulfuric acid.


I wouldn't go that far.  C++ is wildly complex, yes, but as long as you're nice to it, you're fine.  In the same vein, C is a pain in the ass sometimes, mainly because of shitty APIs, but as long as you live by a few simple rules, you'll find that your own C is 100% maintainable and 100% type safe.



Slyck said:


> Is it worth the effort or should I go some other route?


Just fucking learn it.


----------



## Nollix (Jun 7, 2010)

nrr said:


> TAoCP and SICP really have nothing to do with assembly.


You're right, I don't know why I said that. Though TAOCP does go into ASM if I recall correctly. Good post, btw.


----------



## ToeClaws (Jun 7, 2010)

net-cat said:


> Pain and suffering.



*laughs* Oh yeah.  

Coding is painful no matter what you choose though, and honestly, C is less painful than some other choices.  If you're a real sado-masochist I recommend Fortran or Assembler.  I used to code in C/C++ but got out of it - I'm far too much of a perfectionist to be a coder since I can't stand releasing anything that isn't 100% bullet proof regardless of how long it takes to get it that way.  Businesses don't think that way (though I sure wish they would). :?


----------



## nrr (Jun 7, 2010)

Nollix said:


> Though TAOCP does go into ASM if I recall correctly.


Yes, TAoCP does go into assembly a little bit, but like I said in my original post, the points at which Knuth hops into MIX/MMIX examples are, well, examples.  They're completely ancillary to TAoCP as a whole, and you can safely digest the rest of the material without missing much of anything.


----------



## Ibuuyk (Jun 7, 2010)

net-cat said:


> It's actually one of my primary languages that I work with.
> 
> *Pain and suffering.*
> 
> Truly, it depends on what you want to do. From what you said, "casual time-killing programming," you may have better luck with a scripting language such as Perl or Python.



Sounds like you're describing Java.


----------



## catsin (Jun 13, 2010)

K&R. Great book. Also, you forgot the first quote. That won't compile.


----------



## Shiroka (Jun 17, 2010)

net-cat said:


> Truly, it depends on what you want to do. From what you said, "casual time-killing programming," you may have better luck with a scripting language such as Perl or Python.


 
This. I would recommend Python or, if all else fails, Basic as a first language so you can familiarize yourself with programming in general and not be completely lost when going after more complex and strict languages such as C or Java. Besides, Python is, despite being nearly 20 years old, still largely used worldwide for a large array of applications so you definitely won't waste your time learning it.

Learning some Assembly, or at least its premises would also be a good idea to better understand the inner workings of a computer. Understanding how registries, memory and file allocation work may help you code more efficiently, too.


----------

