Live data from Hacker News

To become a good C programmer (2011)

fabiensanglard.net

51–60 of 106 posts

Re: To become a good C programmer (2011)

#51
post #24

The more I learn C the more I hate it. At first it seems simple and easy but reading "Expert C Programming" is reading a laundry list of what's really messed up with the language. 80% of the problems would be solved by some sane syntactic sugar that compiles down to C

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…

Objective-C, actually. I had really only used Java and a little C++ and PHP before I learned it to start doing iOS development (still iPhone OS at the time), and while I initially hated the syntax and found it confusing, I really ended up appreciating a lot about how things were done in the language. Although that was mostly things which originated in Smalltalk.

Re: To become a good C programmer (2011)

#52
post #35
post #7

Earlier quoted context omitted.

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.

Even "i" can be changed to "index". My rule of thumb is this: If you wouldn't use the abbreviation when speaking, don't use it when coding. I don't understand why 'i' has been given a pass. The argument boils down to saved keystrokes. Typing is not the bottleneck.

My guess would be that it derives from the mathematical notation for sums.

But apart from that, I think using i,j,k as index variables in for-loop has become such a de-facto standard that I would only prefer long names such as "count" or "index" in situations where multiple indices may cause confusion. But then I'd probably use even more specific names than "count" or "index".

Re: To become a good C programmer (2011)

#53
post #38

Earlier quoted context omitted.

No the representation model is fine. It's where C tries to be something other than portable assembly where it goes awry. E.g. C has more syntax for arrays than actually exists at runtime, which leads to surprising behavior. The problem with array arguments discussed in the LKML thread posted above is a great example.

I am having trouble identifying "the LKML thread."

[deleted]

Re: To become a good C programmer (2011)

#54
post #40

Earlier quoted context omitted.

I disagree: no static typing --> annoying runtime errors, no 'use strict'..

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.

Re: To become a good C programmer (2011)

#55
I cannot recommend Understanding and Using C Pointers by Richard Reese highly enough (http://www.amazon.com/Understanding-Using-Pointers-Richard-R...)

Learning C syntax is pretty easy. Learning to use the standard library is mostly a matter of reading man pages and other people's code. But I found understanding pointers and memory management completely opaque until I read that book. It definitely brought me from "beginning C hacker flailing about" to "intermediate C hacker flailing about in a more dangerous way".

Re: To become a good C programmer (2011)

#56
post #49

Earlier quoted context omitted.

I think he means that he works like this: 1. Write some C 2. Dump the corresponding assembly code 3. Modify the code by hand

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.

Re: To become a good C programmer (2011)

#57
post #23

I found that, after learning the basics of the language via K&R or a similar book, the best way to get a good understanding of C and its weird corner cases and eccentricities is just to go through the comp.lang.c FAQ page. http://c-faq.com/index.html It's pretty comprehensive, and I found the level was pretty good for a "not total newbie, but still not familiar with the subtilties" level that can be kind of hard to f…

Making a blogging engine in C would be very informative (though difficult).

i think fefes cms is written in C... [1]

[1] http://www.fefe.de/poweredby.html

Re: To become a good C programmer (2011)

#58
post #48

Earlier quoted context omitted.

I am having trouble identifying "the LKML thread."

I think he meant this: https://lkml.org/lkml/2015/9/3/428 (It's Torvalds on a bug made harder to spot by using array arguments in C, which you shouldn't do.)

Thanks so much! Agreed.

Re: To become a good C programmer (2011)

#59
post #23

Earlier quoted context omitted.

Making a blogging engine in C would be very informative (though difficult).

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.

Re: To become a good C programmer (2011)

#60
post #23

I found that, after learning the basics of the language via K&R or a similar book, the best way to get a good understanding of C and its weird corner cases and eccentricities is just to go through the comp.lang.c FAQ page. http://c-faq.com/index.html It's pretty comprehensive, and I found the level was pretty good for a "not total newbie, but still not familiar with the subtilties" level that can be kind of hard to f…

Making a blogging engine in C would be very informative (though difficult).

Not terribly difficult. I wrote my own blogging engine in C [1] which I still use [2] (it also uses this library I wrote: [3]). Last modification I made: support for gopher [4] for that "retro feel."

[1] https://github.com/spc476/mod_blog

[2] http://boston.conman.org/

[3] https://github.com/spc476/CGILib

[4] gopher://gopher.conman.org/

Post reply on HN