# 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.

## 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

##### Share on other sites

Looks ok to me, are you too lazy to type it out?

##### 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 on other sites

Keep it. It's useful for looking over code.

##### 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(...) {

...

...
}

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

##### 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 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 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 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 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.