| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
January 17, 2008 Local Function Scope Keyword | ||||
|---|---|---|---|---|
| ||||
I wrote this up here: http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator the problem it attempts to solve is that sometimes you want to know what function you are in and the "this" keyword won't help you unless you hardcode all your function names in everywhere. instead i suggest the word "scope" (or something else) to mean "the current function instance under the current class instance" and possibly "this.scope" to find the class's entrypoint (the first function called by an external class/function) I havent fully thought it through but i'm in the middle of some funky delegate / call stack shenanigans in c# and something like this would save me a bunch of variables/hard coded function names and generally make it look cleaner. | ||||
January 17, 2008 Re: Local Function Scope Keyword [+] | ||||
|---|---|---|---|---|
| ||||
Posted in reply to RicHardacre | RicHardacre wrote:
> I wrote this up here: http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator
>
>
> the problem it attempts to solve is that sometimes you want to know what function you are in and the "this" keyword won't help you unless you hardcode all your function names in everywhere. instead i suggest the word "scope" (or something else) to mean "the current function instance under the current class instance" and possibly "this.scope" to find the class's entrypoint (the first function called by an external class/function)
>
> I havent fully thought it through but i'm in the middle of some funky delegate / call stack shenanigans in c# and something like this would save me a bunch of variables/hard coded function names and generally make it look cleaner.
Vote in favor, not that anybody cares.
self as a keyword is still free :)
--downs
| |||
January 17, 2008 Re: Local Function Scope Keyword | ||||
|---|---|---|---|---|
| ||||
Posted in reply to RicHardacre | RicHardacre wrote: > I wrote this up here: http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator > > > the problem it attempts to solve is that sometimes you want to know what function you are in and the "this" keyword won't help you unless you hardcode all your function names in everywhere. instead i suggest the word "scope" (or something else) to mean "the current function instance under the current class instance" and possibly "this.scope" to find the class's entrypoint (the first function called by an external class/function) > > I havent fully thought it through but i'm in the middle of some funky delegate / call stack shenanigans in c# and something like this would save me a bunch of variables/hard coded function names and generally make it look cleaner. I like the idea though scope probably shouldn't be reused for this purpose. Python uses something similar a __name__ variable which can be checked to see if the code is been executed as the main module: if '__main__' == __name__: print "I'm the main module." However, I would have implemented the example as follows: public void AddNewUser( string Name ) { Lock l = Database.tblUsers.Lock(); Add( Name, l ); l.Unlock(); } public void AddNewUser( string Name, Lock l ) { Database.tblUsers.Insert( Name, l ); } public void AddUsers( string[] Names ) { Lock l = Database.tblUsers.Lock(); foreach( string Name in Names ) AddNewUser( Name, l ); l.Unlock(); } Also, I would love to have __FUNCTION__ and __CLASS__ compile time variables in D like there are in PHP. It would simplify logging. Cheers. -- Julio César Carrascal Urquijo http://jcesar.artelogico.com/ | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply