Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relearning C: New idioms? [closed]

Tags:

c

idioms

I'm relearning C after not having touched it since 2000 or so. I've been working in Ruby since then, and I discovered a whole world of programming idioms I never knew existed.

What important C techniques, books, idioms, etc. have arisen in the past decade, if any? I know about the C99 and C11 standards, but where else should I be looking? Or has C style remained constant even as OOP and FP have become the norm?

like image 659
Jay Levitt Avatar asked Feb 13 '12 13:02

Jay Levitt


1 Answers

C doesn't support at language level nothing more than procedural programming - and that's a precise choice, because it was born to be mostly a "portable assembly" and it's used to work as tightly close to the machine as possible (without resorting to assembly). Most assembly languages do not provide much more, in terms of programming paradigms, than a stack and function call statement (some micros not even that) - and that's what C is modeled upon.

After all, there's a reason why C++ and Objective C were born: C has to keep its design philosophy, and to add more abstract stuff people had to actually fork the language.

That being said, there's nothing stopping you to write e.g. OO code in C - actually, many people do that (I'd say that it's one of the most diffused idioms in C), but you don't have to expect almost any syntax sugar for that: you'll have to use structs for the data, "normal" functions to "emulate" methods, composition for inheritance, pointer tables for polymorphism, and so on. Still, I don't know if this counts as a "last decade" idiom, it is being used since much longer.

like image 187
Matteo Italia Avatar answered Sep 27 '22 20:09

Matteo Italia