November 2nd, 2008 | Satish | 7 Comments

I was reading through Mike Slinn’s article on InsideRIA called “Good Code is Beautiful” where he is talking about importance of writing code as beautiful as you would expect it to work. Well this reminded me how I transformed from following style of vertically spacing parenthesis to vertically compressed parenthesis style.

 

From This:

private function foo():void

{

   if(…)

   {

        

   }

   else

   {

        

   }

}

To This:

private function foo():void {

   if(…) {

        

   } else {

        

   }

}

I agree that vertically spacing parenthesis style is easy to read but again depends on how you look at it and individual taste. But it doesn’t work sometimes.

When I first started to work on Flex 1.5 I faced many problems but one of the particular problem which forced me to switch my liberal way of writing code to writing compressed code (I mean positively). The error is commonly known as “The 32k Error”. The Flex 1.5 compiler seems to consider empty spaces and commented lines while compiling code and sometimes this caused nasty compiler 32k Error. There are many reasons why this error would pop up during compilation and not all are known, however most common are:

  1. Number of code lines or file size.
  2. Using too many nested looping statements and process heavy data in it (I don’t know why)
  3. Or any other reason you might find… (they are not know to me)

Once we encountered this error then it took us days or sometimes weeks to figure out what is causing the error and how to rid it, but over the course of time I learnt that major cause is number of lines in your file so better write a code vertically compressed manner and remove commented or unused code and split large files into many small AS files.

 

Today I am so used to writing vertically compressed code that I think it is the faster (you save hitting Enter key ;) ) and best way to maintain your code in a long run and its best way to save space (not that you have to pay for space, but you never know).

 

Cheers,

Satish

7 comments to “Why do I follow compressed parenthesis coding style?” Leave your Comment
  1. lab9 says:

    I use and prefer vertical spacing style, because it visualy sets a level of imbrication of code. I allows to immedialty see the beginning and the end of a nested code. matter of taste in my opinion…

  2. Satish says:

    @lab9, As I said I was a follower of vertical spacing style but now I prefer compressed style it is all about individual taste, but sometimes you have to taste it in order to love it :)

  3. Keith Peters says:

    Those aren’t parentheses. They are braces.

    http://en.wikipedia.org/wiki/Bracket

  4. maliboo says:

    AFAIR 32k limit was for *COMPILED* code, not source code. And parenthesis “style” is ONLY in source.

    function()
    {
    kind(“regards”)
    }

  5. Satish says:

    What I am saying is you get “32k error” when you are compiling your application, what that means is compiler would not compile the source code if it is exceeding 32k limit. And this is well known issue if you are working on large project and trying to compile your source code into .SWC file.

  6. Satish says:

    @Keith,
    Damn, those words are confusing, lol :)

    I follow both compressed parenthesis and compressed braces style, I hope this is more accurate. I meant all types actually:
    # round brackets or parentheses: ( )
    # square brackets or box brackets: [ ]
    # curly brackets or braces: { }

    Thanks.

  7. Matt Platte says:

    Me (too) for compression. Writing code using a widescreen display (1280×800) makes vertical space more valuable than horizontal space.

Leave a reply

We love to hear your views.