Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by dleanjeanz Nov 19, 2014 at 3:41 PM 12 replies 4.6k views
Original Post
dleanjeanz
dleanjeanz

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]
rAm_y_
rAm_y_

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

DiegoSLTS
DiegoSLTS

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

viper110110
viper110110

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

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 ob
Bregma
Bregma

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 Friends(int id);

Stephen M. Webb
Professional Free Software Developer
Servant of the Lord
Servant of the Lord

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.

Ovicior
Ovicior

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

What will you make?
dleanjeanz
dleanjeanz

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]
mark ds
mark ds

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.

Ravyne
Ravyne
Saving keystrokes is never a good reason to abbreviate or give something a name that's less accurate/descriptive than one that's longer. By all means, use the shortest name that's accurate, but never sacrifice accuracy for brevity.

That being said, if you follow that guideline but find yourself having trouble giving things reasonably short names, then it can be an indication that your function is doing too much -- in particular, if you find yourself reaching for a conjunction like "and"/"or" its almost always a sign that you should split your function -- doing so will make your code more flexible and less coupled.
throw table_exception("(? ???)? ? ???");
IndyOfComo
IndyOfComo

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.

Here is my technical background info.
dmatter
dmatter

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

DvDmanDT
DvDmanDT

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.