Live data from Hacker News

Where to begin when learning C? Start by making lots of errors

morganwilde.svbtle.com

61–70 of 90 posts

Re: Where to begin when learning C? Start by making lots of errors

#61
post #33

Earlier quoted context omitted.

People don't like K&R? I can understand it not being suitable for children and the very beginner, but it's one of a very few programming books that is useful, succinct, pragmatic, doesn't get bogged down in APIs, and is written clearly. (The companion book "Programming in the UNIX environment" is the get-you-started guide from the very beginning, although it assumes 1970s terminal defaults)

K&R is the best second C programming book.

And first is?

Re: Where to begin when learning C? Start by making lots of errors

#62

Earlier quoted context omitted.

"Programming is learned by writing programs" - Brain Kernighan And that is what anyone who goes through K&R will do: Reading and writing lots of real programs. A simple program is worth a thousand words! Which unfortunately the majority of technical books just can't get right. Explain the concepts in 5 full dull pages, and then at the end "Hey, checkout this little snippet of code, which by the way does nothing reall…

> A simple program is worth a thousand words! Whereas, the less said about complicated code, the better.

Complicated code speaks for itself.

Re: Where to begin when learning C? Start by making lots of errors

#63

Earlier quoted context omitted.

K&R is the best second C programming book.

What's the first?

You shouldn't read that as "second best book," it's "best second book," i.e. reading a more introductory book would be a prerequisite to reading K&R.

Re: Where to begin when learning C? Start by making lots of errors

#64
post #14

Earlier quoted context omitted.

"Programming is learned by writing programs" - Brain Kernighan And that is what anyone who goes through K&R will do: Reading and writing lots of real programs. A simple program is worth a thousand words! Which unfortunately the majority of technical books just can't get right. Explain the concepts in 5 full dull pages, and then at the end "Hey, checkout this little snippet of code, which by the way does nothing reall…

I'd like to add some emphasis on reading . For a beginner, writing is obviously very very important as the way to get to the point where he can just sit down and solve a given task. But reading lots and lots of code (from many different sources) will help him pick up idioms and find common & good solutions to specific problems. Even for a smart person, I think it'll take a lot of time and effort to arrive to the clea…

I'll second this notion. I no longer write C, but it is what I learned in high school. My teacher had an interesting class requirement: we needed to review one C/C++ Users Journal article. Length, difficulty, or topic didn't matter - just read a trade article and write about it. We also had to code a lot, and we had to write code by hand on paper tests, and we had some fun competing, but the journals let me know what the Real World was doing.

It takes a large volume of work to really get into programming, and I think that reading is easier than writing, so it's a fast way to dig in (keeping in mind that feedback is critical - so reading without writing has severe diminishing returns)!

Re: Where to begin when learning C? Start by making lots of errors

#65
post #58
post #29

Install Valgrind. It makes error messages a lot less cryptic (my #1 problem with C... not that's it's limited to C). If you don't get proper feedback, it's not learning, just banging your head against the wall.

I've had a heck of a time getting Valgrind working on a mac (especially since Mavericks), hardly finding any resources about it. Is there an alternative, or do you have any advice on getting it to work?

XCode comes with profiling tools. It's not easy to stray outside of Apple's own development tools.

Re: Where to begin when learning C? Start by making lots of errors

#67
post #16

This situation is why there is "hello world"; that program seems trivial but actually has important implications; for instance, that your environment works, that you know how to feed programs to the compiler, that you can actually run the output. I never took "hello world" seriously until I started doing embedded systems work; it's now an extraordinarily important tool for me (I work an anomalously weird number of di…

Agreed. "Hello world" is how you test that you are able to create a particular software artifact at the most basic level. My first kernel device driver was a NetBSD one called /dev/hello; it simply spit out "HELLO WORLD " over and over, for as long as you cared to read it. But it showed me how drivers do I/O and that I could write one and link it in.

Re: Where to begin when learning C? Start by making lots of errors

#68
post #22
post #16

This situation is why there is "hello world"; that program seems trivial but actually has important implications; for instance, that your environment works, that you know how to feed programs to the compiler, that you can actually run the output. I never took "hello world" seriously until I started doing embedded systems work; it's now an extraordinarily important tool for me (I work an anomalously weird number of di…

I once had a particularly slow week at work, and decided to write an article about how "Hello World" works in C. How it really works -- including compiling, linking, system calls, operating system involvement, hardware I/O, communication between ICs, etc. The path from the block of text to photons emitting from the screen, with fairly detailed explanations at every level. I ended up with a 50 page LaTeX document that…

My (admittedly, considerably more humble) attempt is http://eli.thegreenplace.net/2012/08/13/how-statically-linke...

It takes on an even simpler program, namely:

  int main() {
      return 42;
  }
But digs in the C runtime, Linux kernel and touches on compilers, linkers and loaders.

Hope it's helpful

Re: Where to begin when learning C? Start by making lots of errors

#69
post #22
post #16

This situation is why there is "hello world"; that program seems trivial but actually has important implications; for instance, that your environment works, that you know how to feed programs to the compiler, that you can actually run the output. I never took "hello world" seriously until I started doing embedded systems work; it's now an extraordinarily important tool for me (I work an anomalously weird number of di…

I once had a particularly slow week at work, and decided to write an article about how "Hello World" works in C. How it really works -- including compiling, linking, system calls, operating system involvement, hardware I/O, communication between ICs, etc. The path from the block of text to photons emitting from the screen, with fairly detailed explanations at every level. I ended up with a 50 page LaTeX document that…

> How it really works -- including compiling, linking, system calls, operating system involvement, hardware I/O, communication between ICs, etc. The path from the block of text to photons emitting from the screen, with fairly detailed explanations at every level.

That reminds me of JBQ's blog post from shortly after Dennis Ritchie's death: https://plus.google.com/112218872649456413744/posts/dfydM2Cn...

I would love to see that document if you still have it.

Re: Where to begin when learning C? Start by making lots of errors

#70

A minor point, but important to understand: the error came from the linker, not the compiler. It compiled just fine.

Regarding that: >an empty file is not a valid C program, and the compiler will not hesitate to tell that to you with a big, fat error message.

Didn't someone win a IOCCC some years ago by providing an empty file that got compiled successfully?

Post reply on HN