Live data from Hacker News

How to convince any C developer to dump gcc and use clang

fseek.me

11–20 of 97 posts

Re: How to convince any C developer to dump gcc and use clang

#11
post #2

Part of being a C developer (or C++ template) developer is in fact understanding what the compiler spits out. So, this did't convine me enough because "two or more data types" made me skip right a head to the definition of Point. :-) My point is Clang is good but friendly error messages is not the only reason I would change to Clang.

But it is a compelling reason. Imagine all of the brain cells you can reclaim by forfeiting that C++ error message intuition that you now have.

First we need full C++ coverage in clang. Onward!

Re: How to convince any C developer to dump gcc and use clang

#12
post #5
post #3

An even better reason to use clang: it supports Apple's new syntax for blocks. I'm trying to think of a new project to write in C now just to take advantage of the simple anonymous functions and closures that are possible.

Proprietary extensions are one reason that gcc is so hard to unseat. You're always better off writing standard code if you want it to work in ten years.

Hardly proprietary. Apple gave the "block" patches to the gcc team. Gcc isn't interested in them, they are holding off for some future C++ syntax, though I don't see how that helps C programmers.

Meanwhile, I got seduced by gcc's nested functions which are not supported by clang. Apparently they are non-trivial in clang so won't appear soon if at all.

Two incompatible mechanisms for function decomposition are annoying.

("blocks" does a lot more, but for the afflicted project I don't need that. Just nested functions would be spiffy, it saves the plethora of arguments being passed to each function if you keep them at file scope.)

Re: How to convince any C developer to dump gcc and use clang

#14
post #6

I'm not sure this screenshot is convincing. Do you see the last error message? In the second error message clang found that `horisontal` doesn't exist and suggested `horizontal`. That's fair enough. The last error message actually assumes the code said `horizontal`, which is just horribly wrong. I think that the compiler should never ever report an error on code that is not really there. What would happen if the prog…

"What would happen if the programmer got a list of error and started fixing from the end?" I always fix the first 1 or 2 reported errors and try to recompile. I assume everyone did. A traditional "report on errors which are actually there each time they happen" compiler will give you tons of completely spurious errors which happily disappear once you fix the first few. In the instance you point out, it could just use…

I agree, but it might be helpful if it put something in saying that it had made that assumption. For example they could say

[...] has type 'double' (assuming argument horizontal was intended)

With you on the reported errors and trying to recompile; more helpful error messages later in the build would remove some of those compile-fix-compile cycles.

Re: How to convince any C developer to dump gcc and use clang

#17
post #6

I'm not sure this screenshot is convincing. Do you see the last error message? In the second error message clang found that `horisontal` doesn't exist and suggested `horizontal`. That's fair enough. The last error message actually assumes the code said `horizontal`, which is just horribly wrong. I think that the compiler should never ever report an error on code that is not really there. What would happen if the prog…

"What would happen if the programmer got a list of error and started fixing from the end?" I always fix the first 1 or 2 reported errors and try to recompile. I assume everyone did. A traditional "report on errors which are actually there each time they happen" compiler will give you tons of completely spurious errors which happily disappear once you fix the first few. In the instance you point out, it could just use…

I usually try to fix as many errors as I can identify before recompiling. And yes, I usually fix from the bottom up, because that way my changes don't alter the line numbers of future fixes. On large projects, recompile time can be significant.

Re: How to convince any C developer to dump gcc and use clang

#19
post #6

I'm not sure this screenshot is convincing. Do you see the last error message? In the second error message clang found that `horisontal` doesn't exist and suggested `horizontal`. That's fair enough. The last error message actually assumes the code said `horizontal`, which is just horribly wrong. I think that the compiler should never ever report an error on code that is not really there. What would happen if the prog…

It's quite common and accepted for compilers to make assumptions about the rest of the code, and for those to be wrong if your code is broken.

For example, the C# compiler has a large number of passes, and it will do no more passes after seeing an a previous pass. Thus, you might knock a file down to one error, fix that error, and then find that you have a couple dozen more errors.

Re: How to convince any C developer to dump gcc and use clang

#20
post #6

I'm not sure this screenshot is convincing. Do you see the last error message? In the second error message clang found that `horisontal` doesn't exist and suggested `horizontal`. That's fair enough. The last error message actually assumes the code said `horizontal`, which is just horribly wrong. I think that the compiler should never ever report an error on code that is not really there. What would happen if the prog…

"What would happen if the programmer got a list of error and started fixing from the end?" I always fix the first 1 or 2 reported errors and try to recompile. I assume everyone did. A traditional "report on errors which are actually there each time they happen" compiler will give you tons of completely spurious errors which happily disappear once you fix the first few. In the instance you point out, it could just use…

One point was mentioned - recompiling time may be huge.

On the other hand - if the recompile time is tiny, I don't bother with any specific order, I just fix what I see as trivial first. But when you see the clang's very verbose errors - how many can you fit on the screen? 10? 15? To make sure none of the last ones depend on some code guessing, you'd have to scroll to the top every time, instead of just fixing what you see.

I'm still not a fan of guessing - badly reported error is still better than properly reported error on a nonexisting code (potentially incorrectly guessed).

Post reply on HN