Jump to content
  • Advertisement
Sign in to follow this  
dleanjeanz

Need a short name to replace a really really long function's name

This topic is 1425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all, thanks for reading this post.

Now I just get to the point.

 

I've got a function named: SetPosByOrigCenter().

That means: Set Position By Original Center Point

 

Then I've got this: SetPosByOrigCenterOnEvent(e:Event)

public function SetPosByOrigCenterOnEvent(e:Event) {
     SetPosByOrigCenter();
}

That means: Set Position By Original Center Point On Event

 

Yeah, their name are really long, right?

Like 18-25 characters.

 

So I'm just asking if you guys would mind finding a new name for these functions

Please, thanks!

Share this post


Link to post
Share on other sites
Advertisement

 

I think long function names are generally a good thing as they are more descriptive. As long as you have some sort of autocomplete, you shouldn't have to type it all out, and most nowadays support just typing the initials (SPBOCP). If you are looking to reduce the length of the names, think about what information is implied by the function parameters and return type.

 

If I have a function

public List<Friend> GetListOfFriendsByID (int id)
{
    //Return new list with my friends
}

I can see that it clearly returns a List and I can clearly see that I am passing in an id. I can now shorten the name to

public List<Friend> GetFriends (int id)

Clearly you are getting data.  It should really just be public List<Friend> Friends(int id);

Share this post


Link to post
Share on other sites
Here's the explanations:

What the function SetPosByOrigCenter() does is: set the position by setting it to the x (and y) of the original center point minus half of the width (and height) of the object (the object here is a button)

public function SetPosByOrigCenter():void {
     //this: the button
     this.x = origCenterPoint().x - this.width / 2;
     this.y = OrigCenterPoint().y - this.height / 2;
}

What the function SetPosByOrigCenterOnEvent() does:

public function SetPosByOrigCenterOnEvent(e:Event):void {
	//e:Event is a must for event function in AS3
	SetPosByOrigCenter();
} 

The function SetPosByOrigCenterOnEvent() is called every time the button is transformed in size like these buttons in Frantic Frigates:

public function Button(...) {

    ...

    this.addEventListener(MouseEvent.MOUSE_OVER, TransformSizePOnEvent);
    this.addEventListener(MouseEvent.MOUSE_OVER, SetPosByOrigCenterOnEvent);
            
    this.addEventListener(MouseEvent.MOUSE_OUT, ResetSizeOnEvent);
    this.addEventListener(MouseEvent.MOUSE_OUT, SetPosByOrigCenterOnEvent);
            
    this.addEventListener(MouseEvent.CLICK, ResetSizeOnEvent);
    this.addEventListener(MouseEvent.CLICK, SetPosByOrigCenterOnEvent);

    ...
}

Maybe, I just rename it ResetPosition() or let it remain unchanged

Share this post


Link to post
Share on other sites

SetPosByOrigCenterOnEvent

glDrawElementsInstancedBaseVertexBaseInstance

 

You function name isn't even that long compared with the gl function above. However, the point of function names is to be descriptive, irrespective of how long they are. If you come back to this code in 5 years will you be able to tell exactly what the function does without any comments? If not, rename it to something more meaningful.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!