Live data from Hacker News

On becoming an expert C programmer

isthe.com

31–40 of 80 posts

Re: On becoming an expert C programmer

#31

Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors), and reading and knowing the ANSI C standard. Of course, just knowing the language in and out is not enough, you also have to be a good programmer in general (algorithms, "design patterns", software architecture, software engineering, etc). But writing C code without undefined behavior, and avoiding its numerou…

"Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors)" I am an expert in C, I had been decades writing on it and other languages, and managing teams of coders. We created a company that used it a lot. I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of. I have lots of experience writing assembler,fort…

> I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of.

"Undefined behaviour" is a very simple and well-defined term when it comes to languages like C. Undefined behaviour is code who's behaviour is specified to be arbitrary. And languages like C is famous for having them.

(I'm assuming that you were being honest about not knowing about undefined behaviour means in C, and not trying to re-frame the word to mean something else.)

An example is overflow on signed integers. Strictly speaking it does not help that you know "how computers work" since you have no guarantees about what will happen if an overflow happens in your program. You can't assume that a wrap-around will happen and base your program on that, since that might be a faulty assumption on some compilers.

Undefined behaviour allows the compiler to assume that it never happens and introduce optimizations based on that assumption. For example, use of initialized variables is undefined. This allows the compiler to avoid having to initialize variables (like arrays) to some default value when they are declared.

Re: On becoming an expert C programmer

#32
post #11

There is plenty of C code to look and learn: Linux, PostgreSQL, lua & luajit, sqlite, redis, cairo, nanomsg, libuv, etc. etc

Id's Quake and Doom sources are a classic in this matter. I looked a bit at wsw, a fork of Quake 2. Now, my code is full of structs with function pointers. It's like I just internalized the more elaborate syntax and now it's all Hammers and Nails. I mean, function pointers to functions returning function pointers, for example. typedef int (*foo) (); foo * bar (); foo * p = bar; not rocket science, but ambiguous at fi…

http://ideone.com/ZOvq0n

You probably meant this:

http://ideone.com/wuZI2o

Re: On becoming an expert C programmer

#33
In my experience, one of the easiest ways is to just get employed by a company, where coding is done in C. You will have to code in that language a lot and the colleagues can help you. I also learned a few languages myself in my spare time (PHP, Python), but that is not nearly as effective.

If you want to really be an expert on C (or in anything imho), you just have to do it fulltime.

Re: On becoming an expert C programmer

#34

Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors), and reading and knowing the ANSI C standard. Of course, just knowing the language in and out is not enough, you also have to be a good programmer in general (algorithms, "design patterns", software architecture, software engineering, etc). But writing C code without undefined behavior, and avoiding its numerou…

"Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors)" I am an expert in C, I had been decades writing on it and other languages, and managing teams of coders. We created a company that used it a lot. I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of. I have lots of experience writing assembler,fort…

e.g.

Take the following

a = f() + g() * h();

Now in this, it is undefined whether g() is going to be executed first or h(). The precedence in this case, I mean. Precedence is well defined for operators, but there are certain things, which I still haven't figured out yet.

Re: On becoming an expert C programmer

#35
For me c is kind of a wierd language. Wierd in that the language itself is incredibly simple, I think anyone could learn c syntax and usage in about 2 days max. But I think where most people get hung up with on c are the concepts, you do need to know about compiling and linking, static vs dynamic libs, lots of details about how computer architecture / memory works, and to get anything done you need know POSIX and the concepts behind any libraries you use. Its not like ruby or other dynamic languages where you could basically have no idea how HTTP works and still write a webapp.

Re: On becoming an expert C programmer

#36

Earlier quoted context omitted.

"Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors)" I am an expert in C, I had been decades writing on it and other languages, and managing teams of coders. We created a company that used it a lot. I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of. I have lots of experience writing assembler,fort…

e.g. Take the following a = f() + g() * h(); Now in this, it is undefined whether g() is going to be executed first or h(). The precedence in this case, I mean. Precedence is well defined for operators, but there are certain things, which I still haven't figured out yet.

It is unspecified not undefined. Important difference.

Re: On becoming an expert C programmer

#37
post #19

Earlier quoted context omitted.

>If you understand how computers work it is extremely reliable bar none. On my processor, INT64_MAX + 1 will be INT64_MIN, a negative value. But the compiler is free to turn for (int64_t i = 1; i > 0; i++) { f(i); } into an infinite loop. Understanding how the computer works without reading about undefined behavior will make you fall into these kinds of traps.

missing overflow guards is just one of the big disappointments in c, if you have experience with asm for any popular processor atm.

Wasn't part of the scope of the language. It's a doble edged sword, but I could see that being a good thing too. If you want raw speed, and know what you're doing, it could be OK not to have overflow guards.

Re: On becoming an expert C programmer

#38

Earlier quoted context omitted.

"Not mentionned, about being an expert C programmer, is knowing the pitfalls of C, (cf. undefined behaviors)" I am an expert in C, I had been decades writing on it and other languages, and managing teams of coders. We created a company that used it a lot. I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of. I have lots of experience writing assembler,fort…

> I can't understand what undefined behaviors C has, because it is the most simple and defined language I do know of. C has lots of undefined behaviors because the language was designed to be easy for compiler writers to implement. As such, a lot of decisions were left to the compiler writers, which is what "undefined" means. Here is a (probably partial) list of undefined behaviors in C. (For a full list you'd have t…

Sure, there is a lot of code you could write that results in undefined behaviour. However, none of it is code that you should write, nor is it code that an expert would write.

Re: On becoming an expert C programmer

#39
post #12

There's nothing magic about learning C versus any other language. - Read an authoritative source (K&R is good; there are better ones) - Read a bunch of good code (I mostly read tools and kernel sources) - Write crappy code and get better Generally I want to write 10K lines of code in a new language before I probably don't suck at it. Varies on the language and paradigm, going to C++ from C took like five years (figur…

Before learning Haskell, try learning lisp through SICP. Haskell is wonderful but it's mostly (not really but bear with me) syntactic sugar over lazy application, which is explained in SICP (as opposed to eager evaluation used almost everywhere else). Syntactic sugar makes the whole thing appear like dark magic but it's not. It's a few minimalistic rules applied over and over (at both language and meta levels).

Re: On becoming an expert C programmer

#40
"DBell is one of the best programmers on the planet."

How would one verify this?

I tried a couple of his sample C programs.

One of them was one source and one header file and compiled easily and quickly. A+. But then I looked at what the program did and realized I had written several iterations of the same utility myself years ago, using only the shell, sed, tr and ed or vi. I guess maybe his point of writing this in C is that he envisions a system that lacks those programs?

Then I tried another sample, which was a little more complex.

It failed to compile. Looks like he assumed Linux but failed to state the program is not portable. F.

I am always on the lookout for truly great C programmers.

Is DBell really as good as Noll says?

Post reply on HN