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

Started by
12 comments, last by DvDmanDT 9 years, 4 months ago

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!

Twitter: [twitter]DleanJeans[/twitter]

Advertisement

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

"Set Position By Original Center" sounds like "Reset Position" to me, but without more details it could mean a lot of things.

But maybe the whole "SetPosByOrigCenterOnEvent" can be removed, if it only calls SetPosByOrigCenter() and ignores de event you can just directly call that method instead.

Anyway, a long name isn't bad unless the language doesn't support it, it would be bad if the name is long because the function does too many things, but that's another problem that doesn't require renaming, it would require refactoring.

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)

Honestly, I am with viper. Way back in the day, I use to try and shorten C routine names, but over the years, I have found that long function names are not bad. I have found that when you try and shorten names you end up cutting corners. For me at least, well named functions (no matter how long) make old code a lot clearer to read and easier to debug.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

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);

Stephen M. Webb
Professional Free Software Developer

I also use long function names. Most of the time they are automatically code-completed when I start to type them.

However, that function name is rather unclear to me, which is a different problem.

As Diego says, how does "Set Position By Original Center Point" differ from ResetPosition()?

Can't you just call:

SetPosition(GetOriginalPosition()) anyway? Do you even need a special function for SetPosByOrigCenter()?

Now SetPosByOrigCenterOnEvent() sounds like it is setting up some kind of internal callback that will be triggered when a specific event occurs. It doesn't sound (to me) like it is happening instantly.

And since the event is completely ignored anyway, you might as well just use SetPosition(GetOriginalPosition()) in that situation as well, unless I'm misunderstanding something.

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

What will you make?

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

Twitter: [twitter]DleanJeans[/twitter]

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.

This topic is closed to new replies.

Advertisement