Sign in to follow this  

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

This topic is 1124 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

 

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

I'm with Diego--maybe it can be shortened because there's a shorter way of saying what you're doing.

 

Personally, I wouldn't bother with the +Event method if all it's going to do is call a method of the same base name and do nothing else.

 

ButIRecognizeAndEmpathizeWithFolksWhoDoNotLikeTheCurrentPopularConventionOfRidiculouslyLongMethodNames. There's something to be said to reading something short (say under 30 chars) and know which method/value is being referenced, rather than having to read all the way out to characters 55-60 to finally distinguish entities.

Share this post


Link to post
Share on other sites

Based on what I see, I would scrap those functions entirely! Can't get much shorter than that!

 

Rather, your button should be able to keep itself centered at all times, it isn't the responsibility of the user-code to re-center your button. This means events like TransformSizePOnEvent and ResetSizeOnEvent should be calling a setSize() function on the button. This setSize function will adjust the width and height but also recalculate the position of the node relative to the center.

 

Thus, no need for a setPosByOrigCenter function! As an aside, I tend to read "orig" to mean"origin" not "original".

Share this post


Link to post
Share on other sites

The only times I go for shorter names instead of more descriptive names is when I expect to have a bunch of them on a single line or things like that, were it can hurt readability. Actually, I don't really go for shorter names, but those are the cases when I'm annoyed by long names.

Share this post


Link to post
Share on other sites

This topic is 1124 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this