Live data from Hacker News

To become a good C programmer (2011)

fabiensanglard.net

61–70 of 106 posts

Re: To become a good C programmer (2011)

#61
Very cool. I would like to see a similar recommendation for TCP/IP, DNS, and perhaps HTTP 1/2, including SSL. (Although I suppose you could start with C and then just get involved with the linux kernel, linux net utils, and nginx. But that's like, hardcore.)

Re: To become a good C programmer (2011)

#62
post #24

Earlier quoted context omitted.

I would say generally I feel that way about any language I've learned. Initially they are pretty easy and the examples given include slick solutions to contrived problems. Then you get into wanting to do real work and you learn about all the corner cases and ambiguities and landmines that are hidden farther afield. Can anyone name a language that they've grown to like more the more they learned about it? I would gues…

My favorite language remains 'C'. You don't have to even look at the corner cases, landmines and ambiguities - use the subset of the language that works. Other than things like signed integer weirdness, most complaints about 'C' revolve around the library. Well, don't use those parts of the library.

[deleted]

Re: To become a good C programmer (2011)

#63
post #19

What's a good practical but small enough project you can do with C? Typically if you are learning Ruby or Node, people recommend creating a blog. What's something like that for C?

I made a small database software engine. Learned a lot about pointers and C syntax, and I still use the software sometimes. SQLite is written in C, if you didn't know.

Re: To become a good C programmer (2011)

#64
post #2

This is the first time I have seen sizeof used like this: sizeof( &array[0] ) This looks equal to: sizeof( array ) at first glance, which would give the size of the entire array in bytes, but of course the &array[0] expression is really: &*( array + 0 ) which simplifies to: array + 0 which is a pointer. And using sizeof on it gives the size of a pointer to int. Edit: (&* array) will also give a pointer. --- This is j…

Here are the relevant parts of the C standard: C89 3.3.3.4 "The sizeof operator... When applied to an operand that has array type, the result is the total number of bytes in the array." C89 3.2.2.1 "Except when it is the operand of the sizeof operator or the unary & operator, or is a character string literal used to initialize an array of character type, or is a wide string literal used to initialize an array with el…

I doubt Torvalds telling everyone that sizeof was a function helped with this confusion.

Re: To become a good C programmer (2011)

#65
post #49

Earlier quoted context omitted.

4. Assemble 5. Load into assembly debugger 6. Learn There is "C", the language, which can be relatively simple. Or hopelessly opaque depending on the author. I think of C the language as just a shorthand for assembly. Only because that's how I use it. http://www.lysator.liu.se/c/bwk-tutor.html But then there is "C" in practice: the specifications, the "standard" libraries, preprocessors, Makefiles, autoconf, etc.

But what would qualify as an "asm code generator" if not a compiler? There are other free compilers. Clang comes to mind.

Spitbol has one.

Re: To become a good C programmer (2011)

#66
post #59

Earlier quoted context omitted.

If you build it on ribs2 (with garbage collection) it wouldn't be too hard.

I'm not sure if I think writing C with a garbage collector is a good exercise for learning the subtleties of the language.

If you figure out how the garbage collector works (it's a C library) then you'll learn :)

Re: To become a good C programmer (2011)

#67

Very cool. I would like to see a similar recommendation for TCP/IP, DNS, and perhaps HTTP 1/2, including SSL. (Although I suppose you could start with C and then just get involved with the linux kernel, linux net utils, and nginx. But that's like, hardcore.)

i think 'TCP/IP Illustrated' is good if you want to get into networking.

Re: To become a good C programmer (2011)

#69
post #7
post #3

K&R is often recommended, and it's certainly fun to read and accessible. But I've also heard it's outdated, and doesn't rally focus much on modern C software design, mostly because the world knew little about it when K&R was written. Thoughts?

I think the style should be avoided; code shouldn't be compact and variable names should be descriptive. Artificial example: for( int i = 0 ; i should be: for( int count = 0 ; count It may be allowed to use i in place of count here, but this is the only place where single name variables should be permitted and only if i is really just a simple array index iterator.

I hope you don't have a stroke:

https://github.com/jsoftware/jsource/blob/master/jsrc/cip.c

...just one of the many source files that make the interpreter for the J language.

Re: To become a good C programmer (2011)

#70
post #54

Earlier quoted context omitted.

While I like static typing, there's a lot more that goes into making a language good or bad than that. On the whole, python seems pretty good to me. I'd take it over Java 90% of the time.

I learned to appreciate static typing after "diving into" a large Python codebase. Even with a good IDE (PyCharm), it was freaking hard to understand what the heck was going on. With all the fun in quick prototyping, there's no way I'm going to use a dynamic language for anything serious.

If a Python code base that's large carries no tests it can be a nightmare to walk through (I've walked through my own ones that I wrote before I had learnt testing too). Statically types languages are great but if they are also oop I find that unless someone really knows how to hold back on the "make things an interface" mentality you can end up with a large codebase that looks just as crazy as a dynamically typed one.

Point here being that everyone's mileage will vary with dynamic and statically typed languages. But over time as the code base grows, the helpfulness of the language type becomes less (to the point of irrelevance). Instead the value of how cleanly the code has been written and maintained matters much more. Code with good tests, classes that are divided logically, well named methods and variables, etc, should be able to tell you what you are looking for regardless of language type.

Post reply on HN