3 ms·
C as a context free language? Bullshit. How many global variables are there? How many functions with ridiculous names like htons? Edit: I realize that "contex
by MarkPNeyer 16y ago
C as a context free language? Bullshit. How many global variables are there? How many functions with ridiculous names like htons?
Edit:
I realize that "context free language" was a poor choice of words; i meant it in the sense that linus did - his claim that you can 'look at a piece of code and understand what it does' is laughable in the face of accepted c programming styles.
- stcredzero 16y agoIronically, this is an overloaded usage to the words "Context Free Language." (Whether you intended it or not.)
- j_baker 16y agoI'm not really sure you understand what a context-free language[1] is. I suppose global variables can be seen as being context-sensitive, but functions with weird names definitely don't qualify a language as context-sensitive. [1] http://en.wikipedia.org/wiki/Context-free_grammar http://en.wikipedia.org/wiki/Context-free_grammar
- koenigdavidmj 16y agoNo, what he means is that something like foo * bar; Can mean two different things. If foo is a defined type (typedef int foo, for example) then that declares a variable bar of type foo. If it is not, then we're multiplying variables foo and bar.
- j_baker 16y agoYes, that is context-sensitive, but it's pretty tame. First of all, if I look at that, I can tell it's probably a pointer. After all, it doesn't make much sense to multiply two variables and then not do anything with the result, does it? On the other hand, it can mean a variety of things in C++. Are we multiplying numbers? Is foo or bar an instance of a class that has the * operator overridden? Is there a global overload of the * operator? Are we declaring a pointer?
- kenjackson 16y agoBut in a well-written program the use of overrides would make sense. Just as much as this function: ExitProgram(); should be clear in the context of a program. Now it's possible that this function actually creates a new process that then plays tic-tac-toe. But in a decent program, it will do its best to be consistent with what you expect. Likewise, if I see A * B, I expect that we're multiplying A and B. What does multiplication mean? Depends on the application, but I expect it to make sense. And with a decent IDE you should easily be able to get the def for the '*', just like you'd get the def for any other function. The problem isn't in the C++ language, but rather the C expectation that many developers have.
- deleted 16y ago[deleted]
- huherto 16y agoI think he means that many global variables create a big context. Which as you point out, it is not the same as context sensitive.
- numeromancer 16y agoThe "context-free"dom you reference here is purely syntactic. Linus here is certainly discussing the semantics of the language, since he is discussing reading and understanding the code. For that you need at least a (perhaps mental) syntax tree, of which there may be many for a given program, and which requires semantic context to disambiguate.
- eru 16y agoYes. C and C++ are about equally bad in their usage of side-effects.