May 16, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CE3AD39.BBC8F78A@deming-os.org... > When gc.fullCollect() is called, I would like the garbage collector to call > Flush(0) on all of my registered pool objects. This is usually called a "destructor". =) Don't forget, destructors are always called when objects get destroyed, be it a delete operator or a GC cycle. By the way, there are no default values for function arguments in D. |
May 20, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | In article <ac0dfr$26p6$1@digitaldaemon.com>, "Pavel Minayev" <evilone@omen.ru> wrote: > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CE3AD39.BBC8F78A@deming-os.org... > > > When gc.fullCollect() is called, I would like the garbage collector to > call > > Flush(0) on all of my registered pool objects. > > This is usually called a "destructor". =) > Don't forget, destructors are always called when objects get destroyed, > be it a delete operator or a GC cycle. In garbage-collected languages other than D, this is usually known as a "finalizer", though sometimes the thread that calls the finalize method is called the finalizer. <http://www.google.com/search?hl=en&q=garbage+collector+finalizer&btnG=Go ogle+Search> -- C. Keith Ray <http://homepage.mac.com/keithray/xpminifaq.html> |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sandor Hojtsy | syntactic sugar Try could act simular to an "if" statement, where "{" can be left if one statement follows. ie int fn() { my_type1 my_obj1 = new my_obj1; try my_type2 my_obj2 = new my_obj2; try my_type3 my_obj3 = new my_obj3; try whatever(); finally my_obj3.close(); finally my_obj2.release(); finally my_obj1.destroy(); } //If that looks any neater? I don't know, parhaps my layout style could be improved. PS - I hope my tabed layout is not wrecked by the news writter. "Sandor Hojtsy" <hojtsy@index.hu> wrote in message news:abvl54$1fd8$1@digitaldaemon.com... > I was interested if anyone will notice that correctly this is written as: > > int fn() > { > my_type1 my_obj1 = new my_obj1; > try { > my_type2 my_obj2 = new my_obj2; > try { > my_type3 my_obj3 = new my_obj3; > try { > whatever(); > } finally my_obj3.close(); > } finally my_obj2.release(); > } finally my_obj1.destroy(); > } > > I consider that noone has noticed this, > a sign of lack of understandability, and of difficult debugging. > I cannot think of any syntactic sugar that could help here. > It needs more fundamental changes. > > Yours, > Sandor Hojtsy > > |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> wrote in message news:acl30i$2sht$1@digitaldaemon.com... > syntactic sugar > > Try could act simular to an "if" statement, where "{" can be left if one statement follows. It does. There's no such stupidity as in C++, which requires { } around try-block. |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> ha scritto nel messaggio news:acl30i$2sht$1@digitaldaemon.com... [...] > int fn() > { > my_type1 my_obj1 = new my_obj1; > > try my_type2 my_obj2 = new my_obj2; > > try my_type3 my_obj3 = new my_obj3; > > try whatever(); > finally my_obj3.close(); > > finally my_obj2.release(); > > finally my_obj1.destroy(); > } [...] I hate this... I vote for mandatory brackets. Ciao |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | Roberto Mariottini wrote:
> "anderson" <anderson@firestar.com.au> ha scritto nel messaggio
> news:acl30i$2sht$1@digitaldaemon.com...
> [...]
>> int fn()
>> {
>> my_type1 my_obj1 = new my_obj1;
>>
>> try my_type2 my_obj2 = new my_obj2;
>>
>> try my_type3 my_obj3 = new my_obj3;
>>
>> try whatever();
>> finally my_obj3.close();
>>
>> finally my_obj2.release();
>>
>> finally my_obj1.destroy();
>> }
> [...]
>
> I hate this...
> I vote for mandatory brackets.
I disagree - the language should be internally consistant, therefore anywhere where block statements are permissable it should be possible should be possible to be replace them with a singe statement - even if the result is less than perfect, as in this case.
C 2002/5/24
|
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | "Roberto Mariottini" <rmariottini@lycosmail.com> wrote in message news:acla54$84a$1@digitaldaemon.com... > > "anderson" <anderson@firestar.com.au> ha scritto nel messaggio > news:acl30i$2sht$1@digitaldaemon.com... > [...] > > int fn() > > { > > my_type1 my_obj1 = new my_obj1; > > > > try my_type2 my_obj2 = new my_obj2; > > > > try my_type3 my_obj3 = new my_obj3; > > > > try whatever(); > > finally my_obj3.close(); > > > > finally my_obj2.release(); > > > > finally my_obj1.destroy(); > > } > [...] > > I hate this... > I vote for mandatory brackets. > > Ciao > That's a POV (point of view). I agree that, in this situtuation brackets look better. Sometimes those brakets can look ugly though, and triesome code blotters. |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | "Roberto Mariottini" <rmariottini@lycosmail.com> wrote in message news:acla54$84a$1@digitaldaemon.com... > "anderson" <anderson@firestar.com.au> ha scritto nel messaggio > news:acl30i$2sht$1@digitaldaemon.com... > [...] > > int fn() > > { > > my_type1 my_obj1 = new my_obj1; > > > > try my_type2 my_obj2 = new my_obj2; > > > > try my_type3 my_obj3 = new my_obj3; > > > > try whatever(); > > finally my_obj3.close(); > > > > finally my_obj2.release(); > > > > finally my_obj1.destroy(); > > } > [...] > > I hate this... Don't like it - don't use it. But let other people do what they want. By the way, the code above is not correct: there are TWO statements in each try-block (since declaration is also a statement), so curly braces are required And it's not that awful. Consider something like this: Foo foo = new Foo; try foo.bar(); finally delete foo; And compare this to: Foo foo = new Foo; try { foo.bar() } finally { delete foo; } Now, which looks better? =) It's a matter of taste, after all. |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to C.R.Chafer | "C.R.Chafer" <blackmarlin@nospam.asean-mail.com> wrote in message news:aclb1b$8rh$1@digitaldaemon.com... > > I disagree - the language should be internally consistant, therefore anywhere where block statements are permissable it should be possible should be possible to be replace them with a singe statement - even if the result is less than perfect, as in this case. Sure, then we can apply it to functions: int func(int x, int y, int z) return x+2*y+3*z*x; void func2(int x, int *y) *y = func(x, x+*y, x-*y); Or to switch: switch(number) case 1: return 0; Good. And what about structs: struct Astruct int i; Beautiful. :-( I vote for mandatory brackets everywhere (so the language would be internally consistant). Ciao. |
May 24, 2002 Re: real destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Hi, "Pavel Minayev" <evilone@omen.ru> wrote in message news:acl7qf$4mq$1@digitaldaemon.com... > > Try could act simular to an "if" statement, where "{" can be left if one statement follows. > > It does. There's no such stupidity as in C++, which requires { } around try-block. It is specified that it is required, see: http://www.digitalmars.com/d/statement.html#try So, if it works for you without them, either the specification or the implementation is flawed. Regards, Martin M. Pedersen |
Copyright © 1999-2021 by the D Language Foundation