PDA

View Full Version : Indent style


cpucpu
08-30-2010, 07:18 AM
Regarding Actionscript and Flashdevelop as my IDE.
I have been ok with hard tabs and this style (tabs appear longer than they are in code quote).

private function someFunction():void
{
//Some statement
}

My concern is whether to use tabs or spaces. I have heard not to use tabs but rather 2 spaces. Some IDEs let you specify tab 'width'(standard is about 4 spaces i think), or even treat tab as X spaces. This recent concern is also for HTML or CSS.

How do you handle this?

maskedMan
08-30-2010, 04:05 PM
What is the reasoning against using tabs? I've never heard of any such thing for ActionScript. In fact, I'd go the opposite route and say never to use spaces in AS... not that it really matters. It's not like we're talking about Python or anything, where whitespace is a real concern.

cpucpu
08-30-2010, 07:01 PM
Well it's official recomendation atFlex coding convetions http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions#CodingConventions-Indentation

maskedMan
08-30-2010, 08:25 PM
Bizarre. Maybe if you're handing off your code to Tadster, he'd care about the distinction ;).

For myself, I don't use notepad to edit ActionScript. I use a code editor that lets you specify the appearance of how your tabs look. If code is formatted in spaces, I can't change that. More to the point, I have to hit the space bar a bunch of times to line up my own code with that other code. Blech. And for HTML / JS, it's really even less important. Though who knows, maybe a tab requires one byte more data to store than two spaces, and they're optimizing for filesize? But if that were true, they'd be minifying the output on the server and it wouldn't matter what you did when you wrote it.

Anyhow, I can't say I've ever met anyone in my Flash career who used spaces. I'm sure someone else will pop in and say the opposite. :)

cpucpu
08-30-2010, 09:08 PM
I don't use notepad to edit ActionScript.
I dont' either. And as a single developer, use a sinlgle AS IDE. So no problems at all.

But as you said, good IDEs allows you to configure tab width.

tadster
08-31-2010, 12:35 AM
I use FlashDevelop too! :) I was able to set it up so that tabs appeared the same in it as they do in notepad... let's see, yep, under tools program settings , Main, then scroll down to indenting, set smart indent to none. And I think there's another plugin I had to turn off too, the one that tabs everything for you...
I never noticed that line about 4 spaces in the conventions, but it's way better to just press the tab key than to have to always space everything up, imo.

CyanBlue
08-31-2010, 12:55 AM
I think that's somewhat of a dumb recommendation if you ask me... You just need to be consistent throughout your classes... Let the editor do the rest for you...

wvxvw
08-31-2010, 10:58 PM
The space becomes a concern when you work with other people and use versioning tools. If someone changes indenting, it will look like a lot of changes has been made to the code. Visual Studio can replace tabs with spaces whily you type or indent code and the editor itself cares about indenting your code correctly. But AS editors don't do it. Well, maybe MPS, but it's different...
On the other hand some rules in Flex Framework conventions seem to be picked randomly from things like Philips rooles or some Java best practices etc, w/o actually thinking if they make sense in the content of AS3. Spaces are uncomfortable. They may be better if you need to view the code via some web browser, but nowadays systems can display the code with configurable formatting and coloring and whatnot... So, I don't use spaces, don't see a reason to do it. Maybe some people like to alighn variable initializers (I find it rather uncomfortable btw), and in that case the tabs or spaces matter, but I don't do that anyway...

mindprism
09-13-2010, 10:34 AM
1) Use a professional IDE other than the ones that come with the platform, this way you have a consistant editor interface whose enhancements stick with you while the platforms change.
2) Use spaces, two of them. Spaces are more predictable than tabs for things like writing macros and regex searches.
3) Use trailing brace syntax --

function x(){
if (1||1){
Alert.show('Always true');
}
}

this saves vertical space and works well with code folding.

4) Never use spaces where they are not neccessary-- in function args etc.
5) Use single quotes primarily.
6) Naming convention: for a datagrid: resultsDG, for an event handler: onResultsDBclick
7) Use very short local var names-- don't try to document the obvious by using longer names.
8) Create a guid for each member and class and put it in the comments for that element, use the guids as unique handles to specific parts of the program that will withstand name changes done by refactoring.

spooner
09-16-2010, 06:18 PM
I think it is entirely a matter of style, and up to your personal desire.

That being said, for AS normal convention and best practice (which really just means what other people will be least confused/surprised by) is tabs not spaces.

btw, the worst thing you can do in large functions is use variables with names like "ref" or "a". If you are a newer programmer, I would be veryExplicitWithVariableNames. You are far more likely to confuse yourself and others with short vars, and misuse them. (Obviously fine to do this for small math functions, etc)

But as I say, thats mostly personal preference.

maskedMan
09-17-2010, 01:33 AM
btw, the worst thing you can do in large functions is use variables with names like "ref" or "a".

Agreed, and this is especially true in AS3. When you compile your code, the compiler replaces your local function variable names with other names of its own choosing. It won't help you to give your variables one or two letter names in an attempt to save performance, or to worry about longer names. They're all the same in the end.

At least, that's true in local function scopes...

drkstr
09-23-2010, 06:07 AM
1) Use a professional IDE other than the ones that come with the platform, this way you have a consistant editor interface whose enhancements stick with you while the platforms change.
2) Use spaces, two of them. Spaces are more predictable than tabs for things like writing macros and regex searches.
3) Use trailing brace syntax --

function x(){
if (1||1){
Alert.show('Always true');
}
}

this saves vertical space and works well with code folding.

4) Never use spaces where they are not neccessary-- in function args etc.
5) Use single quotes primarily.
6) Naming convention: for a datagrid: resultsDG, for an event handler: onResultsDBclick
7) Use very short local var names-- don't try to document the obvious by using longer names.
8) Create a guid for each member and class and put it in the comments for that element, use the guids as unique handles to specific parts of the program that will withstand name changes done by refactoring.

Is this supposed to be ironic?

I suggest the exact opposite of just about everything you mention here...

When in doubt, use the *official* coding convention for Flash Actionscript 3.0.

http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions

damTyD
01-25-2011, 03:22 PM
btw, the worst thing you can do in large functions is use variables with names like "ref" or "a".

Some people may also say "the worst thing you can do is write large functions." But I agree, with you about the variable names "a" or "ref". I've stopped being lazy, and just write the thing out, with the exception of "i", "j", "k", or "e".

I know most people write it like this, but I hate the

function()
{
// code
}

instead of

function(){
// code
}

It is a matter of preference.