My advice on implementing stuff in C:
My advice on implementing stuff in C:
Posted Oct 18, 2010 18:23 UTC (Mon) by cmccabe (guest, #60281)In reply to: My advice on implementing stuff in C: by HelloWorld
Parent article: Russell: On C Library Implementation
> everywhere, which is just useless clutter. When a header file changes, you
> have to recompile every file that includes it, even if the change is
> totally irrelevant for some files, for example when you removed an unused
> function prototype or added a comment
Well, it sounds like you should be advocating Google Go then, rather than C++.
> You can't do #if sizeof (int) >= 4, and you can't do stuff like declare a
> function only if it's not declared already
Actually, you can. Check out static_assert in boost and BUILD_BUG_ON in the kernel.
> The C preprocessor is just as extralinguistic as those code generators,
> the only difference is that it's called by the compiler driver, while
> other such tools aren't.
This is a case where what seems like a small detail to academics is actually a huge deal for practical programmers. Having one preprocessor instead of hundreds really simplifies a programmer's life.
> Also, the C preprocessor clearly isn't powerful
> enough to replace code generators even for C. Just look at the numerous
> code generators in use every day, like flex, bison or ecpg, or those
> things that generate "config.h" for a C program. On the other hand, Java
> has annotations and annotation processors, which can replace many uses of
> code generators.
I haven't thought about it deeply, but I don't think that any macro preprocessor would be powerful enough to replace flex or bison. If you want to define your own domain-specific language without using code generators, just use a high-level language like Ruby.
Also, my understanding is that Java annotations are usually used in conjunction with code generators and static analyzers, rather than apart from them.
