Live data from Hacker News

On becoming an expert C programmer

isthe.com

71–80 of 80 posts

Re: On becoming an expert C programmer

#71
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…

> - Read an authoritative source (K&R is good; there are better ones)

Which would you recommend?

Re: On becoming an expert C programmer

#72
post #41

Earlier quoted context omitted.

I've been programming (dabbling, to be honest) in LISP since about 1980, I've never shipped any products in it. I wrote a couple of toy interpreters in college (after reading Allan's Anatomy of LISP ) and some small projects, but nothing massive. I read SICP when it first came out and did most of the exercises. Yet Scheme was a terrible language to ship software in (commercial implementations were basically toys). I…

Aight, to each his own, a lot of Haskell mystery vanished when I saw it explained in terms of simpler languages (pattern matching, lazy evaluation, curryfication etc etc) but apparently that's not what's bothering you.

I think FP languages' reputation of being hard to learn is partly owed to intimidating terminology that makes certain concepts appear more difficult than they actually are.

Re: On becoming an expert C programmer

#73

Earlier quoted context omitted.

I really think C is much easier to get good at than other languages. There is no mystery with what's going on in the computer when you learn C, the builtin functions, how big something is, how things work, etc. When you learn higher level languages there is significant mystery in everything. It means you can write a lot of code having no idea what's going on under the hood, which is good. That's the point of a higher…

> It means you can write a lot of code having no idea what's going on under the hood, which is good. I'm not so sure that's good. The more stuff there is under the hood that you have no idea about the more places bugs can hide in.

Depends on the quality of the runtime. For instance, C# and Python are really good and well-documented. Your Java environment can vary quite a bit, but you probably have control over it.

Howlers like PowerBuilder and InstallShield are just hopeless amateurville and leave me giggling with awe at how fantastically bad they are; they are worth looking at if you want to get a sense of how lucky you are.

Re: On becoming an expert C programmer

#74
post #60

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…

> But c? c is basically portable assembler. I wouldn't call myself an expert, but I avoid calling C portable assembler. I tend to think of C as having low level data manipulation and high level flow.

It might not be applicable anymore, as the compiler optimizations become more advanced to the point that it is hard to predict the translated machine-code. This is one of the most important points with regards to tool-chain specific knowledge. The other is proper usage of the debugger.

Re: On becoming an expert C programmer

#75

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…

The development of a (good) web-server in pure python likely still requires knowledge of language internals. If depending on libraries, it just depends on the libraries. Web frameworks with "Batteries included" seem rather rare on the C shore, though, maybe because statically compiled languages are in general not used as frequently in web-development. Therefor it's an unfair comparison.

To leverage C's power, libraries should also tend to stay general enough, too, no?

Most compilers or interpreters are complicated under the hood. Fixing a bug in the compiler to get your code working (and submitting a patch), that's mastery.

Re: On becoming an expert C programmer

#76
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…

Read an authoritative source (K&R is good; there are better ones)

K&R is a classic, but is it a good way to learn proper C programming technique?

This makes one wonder -- from Zed Shaw's online version of "C The Hard Way" [0]:

I myself believed that until I started writing this book. You see, K&RC is actually riddled with bugs and bad style. Its age is no excuse. These were bugs when they wrote the first printing, and the 42nd printing. I hadn't actually realized just how bad most of the code was in this book and recommended it to many people. After reading through it for just an hour I decided that it needs to be taken down from its pedestal and relegated to history rather than vaunted as state of the art.

He goes into more detail in his critique, e.g.

Where K&RC runs into problems is when the functions or code snippets are taken out of the book and used in other programs. Once you take many of these code snippets and try use them in some other program they fall apart. They then have blatant buffer overflows, bugs, and problems that a beginner will trip over.

There's more -- and he goes through some K&R code too.

[0] http://c.learncodethehardway.org/book/krcritique.html

Re: On becoming an expert C programmer

#77

Earlier quoted context omitted.

That has nothing to do with C. You would need to do the same thing in any language on any platform.

Most higher level languages do have wrappers around these calls, but you rarely have to worry about things such as async-signal-safety or EINTR, for example. Knowing why such things are problematic isn't of much interest to the average Python programmer, while essential for writing correct and safe C code.

I wasn't talking about "higher level languages", really. Still, you have made a strange statement. Most obviously, if you don't worry about EINTR in Python, your code crashes. This was, in fact, the subject of a recent draft PEP (475) that generated a fair bit of discussion but not much consensus.

To the extent you're better off in Python or any other high-level language than in C, it's because things are removed from your control. Obviously, if you can't do something in a language, you can't do it wrong. That is uninteresting.

And of course EINTR and much signal behavior is POSIX-specific -- as in, you may not even have it (or necessarily anything like it) on other platforms. This, again, is not a "C" thing.

All the world is not POSIX.

Re: On becoming an expert C programmer

#78
> Always, always, always write code as if it will last 30 years.

Well said. But if i do 'git blame' and see a code is like 30 years old. First thing to come to my mind is it must me some kind crappy old legacy code

I know it is wrong. It is substance that matters. But lately somehow i programmed to myself to like newer code then older code. I need to step out that misconception.

Re: On becoming an expert C programmer

#79
post #59

Earlier quoted context omitted.

I'm a self-taught programmer. I started with Pascal (what seems like an age ago), then C, then VB5/6, then C# and JS and a bunch of other programming languages. At this point I felt like I could pick up about any mainstream programming language very quickly. And then I tried to tackle Haskell. That was about five years ago, and I think I'm still at beginner/intermediate level with it. But I realized something. These…

Modern C# does provide some FP constructs (in the form of LINQ, lambdas etc.). I know that having used them a lot made it easier for me to grasp Scala.

I found the reverse to be true - Learning FP paradigm stuff in Scala helped me pick up C#.

Finding out about Linq made me research functional-relational mapping for Scala. FRM makes so much sense to me.

Re: On becoming an expert C programmer

#80
post #63

Earlier quoted context omitted.

Not a valid comparison at all. One is a learned skill, the other is an innate phenotype.

That's true, but the point is that this correlation could be pure coincidence, or at least not causative. (If it actually occurs to start with - it would be interesting to create a poll and verify whether most reputed programmers are indeed more musical than general population.) Many programmers have stereotypical geek interests like RPG, Star Wars etc. but it doesn't mean that these contribute to their programming s…

Except there is a large body of research which shows the effect of music on cognitive ability to support the assertion
Post reply on HN