Sentient351
52 posts
|
Hi everyone,
I’m sorry for bringing up this topic again, but I find myself having a problem. I’ve decided to start naming my accessor methods using actionscript’s built in getters and setters as opposed to naming them things like getVx, etc. The “problem” is that there is something I find so visually disruptive about having underscores anywhere in my code, and I was wondering if there were any other conventions that were common in differentiating private variables from their publicly accessible methods?
I realize that this probably seems a bit ridiculous and that it really doesn’t matter what I name them, but I’m also coming to find that I have a bit of OCD when it comes to how my code is visually laid out and organized. I’ve been just adding m_ before my private variables for now so I can just replace all later when I figure out how I want to name them, but are there any alternative conventions that offer a more elegant solution that are fairly standardized?
I hope this doesn’t seem like a waste of forum space. It’s just been something that’s really bugging me, as I like to have things a certain way but also want to make my code easily understandable to other people.
Thanks!
|
|
|
JamesObscura
250 posts
|
The best naming convention is your own. Unless you plan on doing large projects with multiple programmers using your code, you don’t really need to use getters/setters in the first place. The only conventions you should really follow if you work on your own, are the ones for keeping your code organized and fast.
|
|
|
BigJM
468 posts
|
I was actually thinking about this the other day: it’s kind of silly that you can’t have methods in the private and public namespace with the same name. They are different namespaces after all. With that said, you could do something like this:
package {
public class Test extends Object {
private namespace ap = "unique uri blah blah blah"
ap var prop:String
public function get prop():String { return ap::prop }
public function set prop(v:String):void { ap::prop = v }
}
}
Although I don’t know if that’ll be better than underscores for you. I personally think they’re a good way to differentiate between private variables directly linked to public accessor methods.
|
|
|
EndlessSporadic
10478 posts
|
Originally posted by JamesObscura:
The best naming convention is your own. Unless you plan on doing large projects with multiple programmers using your code, you don’t really need to use getters/setters in the first place. The only conventions you should really follow if you work on your own, are the ones for keeping your code organized and fast.
This. There are as many naming conventions as there are programmers. Find one that you are absolutely content with. I find underscores unappealing as well so I avoid them unless the variable name is a constant (all caps with underscores – VARIABLE_NAME_NUMBER_ONE). Remember that the compiler doesn’t care what you name things, so feel free to make a system that works for you.
|
|
|
Draco18s
6860 posts
|
I’ve done LeadingCaps for private variables, with the public getter/setter being named the same, but in normalCaps form.
|
|
|
EndlessSporadic
10478 posts
|
Originally posted by Draco18s:
I’ve done LeadingCaps for private variables, with the public getter/setter being named the same, but in normalCaps form.
I’m the exact opposite.
|
|
|
Sentient351
52 posts
|
Thanks for the suggestions. I played around with the namespace idea, and I also tried just making a dedicated accessor namespace to use for all of my getters and setters so I could leave the private variables themselves alone, but that seemed like it would potentially cause unnecessary confusion, having to import the namespace into every class that was using accessors. When I tried to make a separate namespace for private variables to use as the default within the class (using public accessors), AS3 still insisted that I had ambiguous variable references, even when I added a classwide use namespace directive.
Oh well, I guess I’ll just settle on prefixing things as necessary or seeing how leading caps looks. Thanks for your help!
|
|
|
radarek
25 posts
|
I’ve been strugling with the same thing when I started programming in AS3. I concluded that using ‘_’ prefix for all private/protected variables is not as bad as I thought at the beginning. It’s just a matter of time.
Leading cups probably would be much harder for me. First big letter is translated by my brain to “aha, it’s class name” :).
|
|
|
jerimo
1037 posts
|
I always freak when things are not consistent, though that also includes having things named in diferent formats, even when dealing with different namespaces and or any othe categorisation, so I just always have leading caps, underscored for seperating words, and “-” for seperating the actual name to details i want to add. EX form my current project ((C++ BTW)):
Character_Handler
Character_Monster-Extension
Character: To show they are form the same base class ((the first being the base class)), the second to have the name of the new class, and the last to show the detils, that it’s an extension to another class ((These are file names though))
|
|
|
Senekis93
4090 posts
|
I tend to use underscores for some numerical variables, which are related to some other value (like value*2 or value*.333) ie: this (ignore my float→int→float dumbness).
|