| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Paintball Freak
|
I'm really curious to see how you guys name your variables and functions... I've been troubling with this for a while and I've been changing my coding style every 2 months because of this and I had enough, I want to know how others do this:
For example, we have a class that has a private variable in it and I want to define a getter and setter method that will help me manipulate my data ( variable )... the stupid thing about ActionScript is that I can't name the function the same way as my variable... so I hate 2 options: give a different name to the function, or a different name to the variable... but in certain cases it's just stupid... example: ActionScript Code:
So, how do you guys name your stuff? How do you handle this annoying naming conflict? Thanks a ton.
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. |
|
|
|
|
|
#2 |
|
fearless
Join Date: Feb 2008
Location: Italy
Posts: 48
|
That's one of the reasons why I don't use getters and setters :P
Anyway, if you don't like underscores (me neighter) you can do something like that for private variables: p_hour, pHour, prHour, hour_p, hour_pr... and so on I use p obviously to indicate private while the getter and setter stay the same. Just my 2 cents ![]()
__________________
Federico "FNX" Nisoli Lead Programmer - FNX Games http://www.fnxgames.com http://fnxdevbox.blogspot.com |
|
|
|
|
|
|
|
|
#3 |
|
Paintball Freak
|
Yeah, that would be an option... but I kind got bored of using that
Anyway, thanks for the feedback, appreciate it. ![]()
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. |
|
|
|
|
|
#4 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
In my opinion the way you name you private variables isn't really all that important. People get too hung up on this detail. Personally I just add an _underscore if, and only if, I have a getter or setter. FlashDevelop does this when it auto-generates getters and setters too. Getters and setters absolutely have a use too. Whether you like to use getSomeProperty() or get someproperty { return _someproperty} is up to you, but I have to disagree with fnx that they should be avoided for not liking underscores.
What's more important (in my opinion) is language convention. I'm not sure if you code in English or not but this is something I do for my code in English. 1) all variables/properties should be named with a noun when possible. examples: Code:
width height children 2) functions/methods should be named with a verb that describes what the function does. examples: Code:
closeAllDoors(); resetInitialProperties(); moveLeft(); 3) Nothing should be abbreviated that isn't an industry-wide common abbreviation. This is very important for people learning to code and people reading your code who may not speak your language very well. Also, it helps those who may just use a different set of abbreviations for things. It also improves readability for reasons described in #4. example: Code:
clickSnd should be clickSound vertLine should be verticalLine moveL should be moveLeft 4) Don't use "Hungarian" type notation for variables. It's severely decreases readability because it puts some letters in there that aren't a word. Humans read words by "glancing" at the overall shape of a word then comparing that shape to their memory. Also, variables are already able to be strongly typed and that information is already provided via compile time errors and is auto generated by just about every IDE out there. examples: Code:
strFirstName should be firstName : String numCurrScore should be currentScore : Number Ultimately though all this has another, more important effect on your code: it creates code that is it's own documentation. You've probably heard the "self documenting" code mantra before but this is really how it's done. If things are well named, you can come back to old code and know what everything does at a glance. example: ActionScript Code:
I'll bet you can guess what all of that would do, and where it would go. You probably already recognize all this too because these are guidelines Adobe/Macromedia used in coding Flex and the ActionScript language itself. If you want to read more, have a look here: http://opensource.adobe.com/wiki/dis...ng+Conventions I don't agree with all of what they say but it's a good read for picking up some ideas about situations you may have wondered about and finding ideas for other stuff you may encounter. Last edited by pj-co; 11-15-2008 at 01:36 AM.. |
|
|
|
|
|
#5 |
|
Paintball Freak
|
Thanks for the reply pj-co. I was aware of the naming conventions just that they never seem to cover the situation I was talking about. I too have been using underscores in certain situations when dealing with getters and setter, all I wanted to know if there are any people out there who found a more elegant way of doing this...
I'm a perfectionist and in my opinion, it looks ugly when 80% of the variables are named without underscores and then we have 4 vars that use underscores... it might be confusing for someone who does not understand the way you write code. That's the main reason I started this thread, too see if anyone found an intelligent way of dealing with this problem but at the same time keep the code readable and easy to understand.
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. |
|
|
|
|
|
#6 | |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
Quote:
![]() |
|
|
|
|
|
|
#7 |
|
Paintball Freak
|
Yeah, but it might not be as obvious to others.
anyway, I think I'll change my style ( but this time finally ) and I'll start using underscores for private vars... if that's what people are used to, it's fine with me. ![]()
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. Last edited by fx.barrett; 11-15-2008 at 03:54 PM.. |
|
|
|
|
|
#8 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
I don't use _them _for _all _private vars, just vars with getters/setters
![]() |
|
|
|
|
|
#9 | |
|
Paintball Freak
|
Quote:
![]()
__________________
FLASHFORUM.RO - You must speak Romanian in order to join. BLOG.WISEBISOFT.COM - Share and Experiment. |
|
|
|
|
|
|
#10 | |
|
fearless
Join Date: Feb 2008
Location: Italy
Posts: 48
|
Quote:
![]() Anyway, I totally agree with you on all conventions, when I have to follow the "best practice" I use _varName too, but, when I'm not forced to, I avoid using getters and setters only because they enlarge my source for nothing, I have plenty of functions that only return or set a value.. When I can code "my way", I set private vars only for vars used by the class and public everything that must be seen "outside". Never said that my approach is the right one ![]() Cheers
__________________
Federico "FNX" Nisoli Lead Programmer - FNX Games http://www.fnxgames.com http://fnxdevbox.blogspot.com |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Naming conflict | superpeppe | ActionScript 3.0 | 2 | 07-05-2007 01:54 PM |
| removing stuff from SOAP request? | gerry81611 | ActionScript 2.0 | 0 | 01-11-2005 05:16 AM |
| drop down menu stuff.... | nemoNslumberlnd | Simple Stuff (Newbies) | 3 | 11-24-2004 09:08 PM |
| Naming it a 'class package' or not. | Stimpson | Other Flash General Questions | 3 | 09-16-2004 09:02 PM |
| my flash doesnt have the lines when drag stuff around... please help out | jake | Simple Stuff (Newbies) | 4 | 11-09-2001 01:34 AM |