Hacker News new | past | comments | ask | show | jobs | submit login

when talking about different things in different languages I always shudder and have to think about "static", going from java to c++ this was horrible



'static' in C is the worst - it has 2 different meanings within the same language. Does anyone know the reason for this confusing design decision?


Reason for this is that static actually does exactly same thing in both cases: defines global variable without externally accessible name and makes it accessible in enclosing scope. (exact standarteese being "internal linkange with static storage duration")


It's actually quite remarkable the number of places a single keyword can be used. We have

  * Static functions in C
  * Static variables in C
  * Static members in C++
  * Static instance variables in Java
  * Static methods in Java
The strange combination of C++'s namespaces and static begets static members, which almost make sense in context. But then Java stole the syntax and not the rest of the language (thank god), leading to its strange, almost contradictory usage.


In Java there are also static inner classes and static initializers (static code blocks that initialize static data)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: