5 ms·
The `static` keyword in C is too confusing. It's hard to explain to beginners. Especially if these beginners come from Java, where it has even more meanings. I
by AlexanderDhoore 12y ago
The `static` keyword in C is too confusing. It's hard to explain to beginners. Especially if these beginners come from Java, where it has even more meanings. I don't understand why we have to use the same keyword over and over again.
- toolslive 12y agoThere is an ever growing list of overloaded keywords that mean different things to different people and programming languages. And yes, it's confusing. A short list that's semantically fuzzy: - thread - type - class - module - functor - virtual machine - ...
- jdswain 12y agoOften times the reason for overloading keywords is the reluctance to introduce new keywords, as this can cause backward compatibility problems. Instead of adding a new keyword and possibly breaking existing code that may use that keyword as a variable name or a function name, an existing keyword that sort-of fits is used for the new feature. While maintaining backward compatibility is good, this does make the language confusing. Static is probably one of the worst offenders, but I think that C++ especially has quite a few of these cases now.
- userbinator 12y agoIn C it only has two meanings, both of which make sense if you think of them this way: 1. "static globals stay in the same file they are defined in." 2. "static locals stay allocated even when the function they're defined in is not being executed."
- ekr 12y agoI think C (and Unix) was the original context in which the static keyword appeared, and as such, changing its meaning would be a terrible idea. A C programmer has to deal with things a lot more complex than the syntax (which IMHO is much clearer than any more modern language, in the context in which it is most commonly used, i.e. system programming). So if someone is 'confused' by the fact that a keyword has two different (albeit related meanings) in the language, and is too bothered to check a manual, or the internet for an explanation, how is that person supposed to write a driver or an operating system, or use low level ipc/communication mechanisms, or debug an elusive deadlock? C is not JavaScript, get over it.