NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
object refcounting (Score:1)
public class MyBaseObject {
public static int REFCOUNT;
public MyBaseObject() {
REFCOUNT++;
}
}
public class DerivedObject extends MyBaseObject {
public DerivedObject() {
super();
}
public static void main(String[] args) {
for (int i = 0 ; i
Re: (Score:1)
In other words, my :)
Carexample, but without theCar.Is it common to want to implement reference counting in this way? What's the use case?
Re: (Score:1)
I have never used static class variables in Java. They seem like a subtle disaster waiting to happen. Also I try (where possible) to program without side-effects.
Moreover, Java doesn't have proper destructors, so you can't decrease the count in any reasonable way.
Is there perhaps a more reasonable use case for a kind of object-level namespace? It would be horrible in practice, but something like public static HashMap MyBaseObject.OBJECT_VARIABLES...
Sounds
How about this? (Score:1)
So you have a shared counter, an alias of it per instance (which seems redundant, but makes it work*... perhaps by some means one could persuade the compiler to compile it away, as it's constant as a reference), and accessors for inheriting.
Rakudo doesn't like the 'has $.x := $y' construct (ye
Re: (Score:1)
I was reminded by TimToady that something very much like this is already possible :)
class Car { my $.cars-produced = 0; #`[...] }. It's spec'd and everything, in S12:731. Hope that helps.Re: (Score:1)
Oh, yes, that's exactly the thing.
I think
has $.x := $ywould have its uses, too; i'll poke around (in spec, code, #perl6) to see what might block/enable it.Gilad Bracha doesn't like static state (Score:1)
I found this interesting post where Gilad Bracha rants about static state [blogspot.com] in objects. Makes me think Perl 6, for all the static state it hasn't, maybe has a bit too much anyway. :)
And an mjd post (Score:1)
I keep finding other blog posts about static state. This post [plover.com] by Mark Dominus warns against keeping object information outside of the object. He does so in an almost embarrassingly reasonable way. Though he doesn't mention static state, he does argue against global state, of which static state is merely a milder version.