kndg said:
Okay, had read the second link you posted but still couldn't get myself
convinced. Anyway, I'll leave it as it is, and since the language does
not have it, I'll have to live without it. Maybe, it will make me
rethink why the language designer choose not to have it and how the
class should be designed.
As I said, even your benchmark code shows a clear example of an
implementation that doesn't belong in some arbitrary class. If you have
a real-world example of where you are trying to use a static local
variable, then we would have something more concrete to discuss.
As it is, your ability to comprehend the justification for not
supporting static local variables is dependent on your ability and
willingness to consider a class design in which you believe some data
member should be encapsulated within a method, rather than in the
containing class, and _then_ to extrapolate the argument in favor of
refactoring that design into two separate classes.
A person predisposed to the static local variable implementation is not
necessarily the best person to rely on to do that extrapolation.
But, if you would provide a concise-but-complete code example that
illustrates what you feel is an appropriate, real-world use of a static
local variable, I will be happy to point out why that example really
should be factored differently.
(btw, its the most constructive discussion I have read so far, and I
wonder why Paul is leaving the discussion too soon. He has presented the
best argument so far... though being cornered by the MVPs)
If someone opens with calling the language design "stupid", IMHO they
have already failed to present "the best argument". Also, his original
code example is contrived, because it opens with the presumption of an
implementation detail that doesn't belong in correct, maintainable code.
(I can see _maybe_ putting a recursion counter in for diagnostic
purposes – though, frankly, knowing the _total_ call count for a
recursive method is dubious as compared to something more realistic,
like the _current_ call count – but you wouldn't want to leave that in
for production code, and for diagnostic purposes, who cares where the
variable is?)
Note also that Paul's approach to language design appears to be "if
there's no apparent disadvantage to the feature, toss it in", which is
quite different from the approach taken by any sane language designer.
That is, normally one approaches language design by including only those
things with clear, positive benefit that justifies the cost.
In any case, you can probably guess that it's not my opinion that Paul's
argument in favor of static local variables is anywhere close to the
"best". In fact, he not once provides a single concrete example of
where the use of a static local variable is in fact the very best
solution to a particular implementation problem.
Pete