View Single Post
nergal
Veteran Member
Join Date: Apr 2012
Old 04-23-2016 , 13:05   Re: New API and Syntax
Reply With Quote #728

Quote:
Originally Posted by BAILOPAN View Post
Yes, you can do this. I don't really understand your efficiency question, but since methodmaps don't allocate memory it shouldn't matter. There are a few antipatterns in your code though. In general it is not a good idea to have one parameter mean something entirely different based on a flag. It's better to do this:

PHP Code:
methodmap BaseMap
{
    public 
BaseMap(int client) {
        return 
view_as<BaseMap>(GetClientUserId(client));
    }

    public static 
BaseMap FromUserId(int userid) {
        return 
view_as<BaseMap>(userid);
    }

    
property int userid {
        public 
get() {
          return 
view_as<int>(this);
        }
    }
    
property int index {
        public 
get() {
            return 
GetClientOfUserId(this.userid);
        }
    }
}; 
This is a common way of having two constructors for clarity:
PHP Code:
BaseMap map1 BaseMap(client);
BaseMap map2 BaseMap.FromUserId(userid); 
Constructing an object multiple times just to access properties is also an anti-pattern, but since your methodmap doesn't do anything effectful or expensive it doesn't matter.
I see, thanks Bailopan! Before I stop lurking for a long time, I have one last question.

Are timers still limited to 0.1 seconds for the smallest possible interval or has this been changed?

If they still are limited to 0.1s, will that change in the future?
__________________

Last edited by nergal; 04-23-2016 at 13:05.
nergal is offline