[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What's the easiest and/or simplest part of Linux Kernel?



On 8/28/2013 2:44 PM, berenger.morel@neutralite.org wrote:
<snip>

Another problem with code probably written by gurus, or which run in
environments were high speed and stability is required, is that the code
will be highly optimized, maybe with non-standard features, probably
with lot of compilation options, etc etc. All of those things makes code
more efficient, but harder to understand. Like macros, that most C
programmers tend to avoid. And because I have learn C as my first
language, I can tell you, that they are true to avoid them, they makes
things hard to read and maintain. But they makes things fast, so I would
not be surprised if there were a lot of them. And not "childish" ones
like the one I made.


While I agree with much of what you said, I definitely disagree with your comments on macros. C was probably the 10th or so language I learned, close to 30 years ago. I found macros, when PROPERLY used, can be quite helpful in making code clearer and more understandable. The trick is to know when to use them and when not, to document them well, and most important, pick good names for the macros. Also, the convention of using all caps for macro names is good; it tells the reader this is a macro being used, and not a function call.

<snip>

* which is doable in C. People saying that C can not do OOP are
incompetent or lie. I do not really like C programming, but paradigm
have nothing related to syntax, only with writer's minds.
Some people may not like OOP, and they will be true, it is not always
good to use it.



Definitely NOT doable in C - you just don't have the tools. While you can do some parts of object based programming like message passing (i.e. calling functions to operate on structure members instead of accessing them yourself), and can even use tricks to "hide" structure members (i.e. the known interface is just a dummy char[appropriate_size] while the real structure is hidden), this can be sensitive to compilers and in some cases even compiler options.

You can't even define constructors and destructors for structures in C, and have to take extra steps to ensure structures are constructed and destroyed properly.

And there is no way you can do inheritance or polymorphism in C.

But I also agree OOP is not always the best choice. Even though I've been doing C++ for around 25 years, I still do a lot of stuff in C where appropriate.

Jerry


Reply to: