Pretty neat. A simple transform, but I prefer this style and miss C's static in some cases.
The doc says that the transformed variable name uses the method name for a suffix to avoid name clashing. But it needs to use the signature, right? Else you would have clashes for two methods with the same name (but different arguments).
I think it should also use $, since that's the convention to avoid clashes with user defined names.
Simply appending a number to the variable name would be adequate to prevent name conflicts. Each method would only access its own static variable, so fancy C++-style name mangling would be overkill.
Also, it seems like (if abused) it would make unit testing really cumbersome without some sort of side-effecting mechanism to expose these persistent variables.
This seems more easily parsed by humans. My immediate faction to this is a positive one. Instead of having to scan the entire class to tell whether or not a variable is static, it's declared in the method itself.
I don think it is very useful or practical. A similar effect can be done using static variables declared outside the methods.
But it is a good example on how to write a plugin, with annotations and instrumentation. So the interesting parts are on the code implementing this functionality.
6 comments
[ 3.2 ms ] story [ 32.2 ms ] threadThe doc says that the transformed variable name uses the method name for a suffix to avoid name clashing. But it needs to use the signature, right? Else you would have clashes for two methods with the same name (but different arguments).
I think it should also use $, since that's the convention to avoid clashes with user defined names.
Also, it seems like (if abused) it would make unit testing really cumbersome without some sort of side-effecting mechanism to expose these persistent variables.
But it is a good example on how to write a plugin, with annotations and instrumentation. So the interesting parts are on the code implementing this functionality.