Tuesday, December 21, 2010

To Cuddle or not to Cuddle :} setting curly brace defaults in my IDE

After a short stint of not understanding what the heck people were moaning about on twitter (re @jesterxl's comments about cuddling), and thanks to him, I came across Grant Skinner's post about curly braces.

I am personally a cuddler.  I find the code easier to read, and I am of the school of thought that less lines of code is better.  Also, to me logic dictates that if you are starting a block of code, you would emphasize that by showing me on the line that you are declaring the opening of that code, that the code block begins with the curly.  In Ruby, there are no curly's for code blocks, so it doesn't bother me there.

But what bothers me, and Grant mentioned it, is how Flashbuilder autogenerates non-cuddled code blocks. And he griped about it, asking that anyone who knows how to fix the problem please let him know.  Well, here's my quick fix, using Flashbuilder 4 on Eclipse 3.6 on OSX6.5:

-> Preferences (cmd + ,) -> Flash Builder -> Editors -> Code Templates -> ActionScript

For each of these classes, I manually updated the templates so that the curly braces all were at the end of the opening line for package, class and constructor, i.e.

package com.lordB8r.controller{
  public class TestClass{
    public function TestClass():{
    }
  }
}

and methods did the same thing:

private function runTestClass():void{
}

ahhh, breathe deeply, knowing that all auto-magically generated code in AS3 will now conform to my preferences.

And yes, I can export these settings, in case I don't want to manually change all of them for each instance of Eclipse (and then reimport them).

Now, I obviously am not smart enough to be the first person to have come up with this.  There is the following resources I found:

InsideRia's article by Greg Owen
FlexFormatter
ActiveTuts by Jesse Freeman
and the best example so far is someone who actually made real templates of what they use in their workflow:
FBB blogpost by Maxim Kachurovskiy

And you can quickly find your own by using lord google.

2 comments:

  1. Thanks a lot!

    ReplyDelete
  2. Should this work when creating new AS class?
    I updated class, function , package, instructor - but after creating new..AS Class - It doesn't cuddle how I set it up and it sets the cursor at line 1 char 1. Any help would be great.
    Thanks

    ReplyDelete