Re:Linus vs C++, again
by koenigdavidmj on Thursday June 10, 2010 @04:55PM
(#1421638)
No, 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.Yes, 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?
Re:Linus vs C++, again
by kenjackson on Thursday June 10, 2010 @05:44PM
(#1421845)
But 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.
I think he means that many global variables create a big context. Which as you point out, it is not the same as context sensitive.
Re:Linus vs C++, again
by numeromancer on Thursday June 10, 2010 @07:00PM
(#1422071)
The "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.
[1] http://en.wikipedia.org/wiki/Context-free_grammar