logo
468x60-2-495


  • Home
  • Privacy Policy
  • About
search
top
Sep 1, 2010 Posted on Sep 1, 2010 in Hints and Tips | 10 comments

Open Mike: Brackets

Allman or K&R? This is Open Mike, a series of discussion posts to throw the cat amongst the pigeons. These posts are all about you — we want to hear your opinions, ideas, and thoughts. To kick things off, let’s talk about brackets. 1: Do you Cuddle? “Cuddling” braces means writing them like this: function [...]

View full post on Activetuts+

banner ad

10 Responses to “Open Mike: Brackets”

  1. Scarybug says:
    September 1, 2010 at 5:43 pm

    I cuddle, but I don’t cuddle } else {. I imaging the function or condition as the head and the end } as the tail.

    I pad, because FlashDevelop auto-pads, and I like my code to be consistent.

    I only nest if I’ve removed a boolean operator from the condition. Too many parens starts to make it look like LISP.

  2. Thomas J Bradley says:
    September 1, 2010 at 5:51 pm

    I agree with your second point: when I write my own code I do not pad, but when I am teaching students padding is essential in helping understand; specifically when students are far away from the screen or when they are looking back and forth between my code and theirs.

  3. alexxcz says:
    September 1, 2010 at 6:17 pm

    Sometimes I mix them when I want tighter code but most of the time I use Allman style. IMO it’s cleaner and it feels natural.
    I use tight padding style just for because it looks cleaner to me. Mostly I use padding for variable declarations only for the purpose of nice formatting:

    private var _someVar :String;
    private var _anotherVar :Object;

    public var publicVar :Number;

    Also I sort the variables by their modifier and their data type. I usually do this after I finish with a class or when I’m in the mood for doing something else than coding.
    As for nesting I use it only on complex conditions to make it easier to understand the order of the statements.

  4. Martin says:
    September 1, 2010 at 6:26 pm

    Allman
    tight
    don´t nest

    I thinks a good reference for these questions is also: http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions

  5. Michael Williams says:
    September 1, 2010 at 7:17 pm

    Cheers, Konstantin — I’m actually going to be asking about prefixes and capitalisation and so on in the coming weeks, so we can talk about those then :)

  6. Andrew says:
    September 1, 2010 at 7:24 pm

    1. I cuddle, raised on C++ I think a lot of them cuddle.

    2. I used to not pad, but as a flash development instructor I have found padding helps students read the code, so I have adjusted to padding (4th example) for that reason.

    3. I don’t nest as in the example above, only when I want to show a clearly defined set of operation order. Such as, if( ( condition1 || condition2 ) && condition3 )

  7. Dan says:
    September 1, 2010 at 8:19 pm

    1. Allman Style
    2. Tight
    3. Nest

  8. James says:
    September 1, 2010 at 8:44 pm

    I mostly cuddle my braces,although i have been trying to move away from it.Hard to break a habit I’ve been using for so long though.I do sometimes find myself both cuddling and using Allman style in the same code,which is not a good thing ….for having consistent code.

    I like the tight style for parentheses.

  9. Terje says:
    September 1, 2010 at 9:18 pm

    I’ve switched between cuddle and Allman style. At the moment I cuddle, but reading this article made me go back to Allman… I love the tip about commenting out the condition. Easy and quick.

    And I am certainly a no-padding guy who finds nesting paranthesis in conditions a better read.

  10. Konstantin says:
    September 1, 2010 at 9:29 pm

    1. I like Allman style more, but I used to cuddle them when I was a beginner. My codes looked messier when I did it :D

    2. I use tight style most of the time, but I don’t really pay any mind to this

    3. I nest conditions in parenthesis only when it’s necessary, like in some math expression.

    I would also add another questions like:

    Do you use underscore in the names of private variables?

    private var _someVar:Number;

    or?

    private var someVar:Number;

    I use ks_ instead of underscore, which (I believe :D ) makes my codes more unique, lol

    Or some other conventional stuff like using all caps for constant names.
    I always do it, since I read Colin Moock’s essential actionscript 3

Leave a Reply

Click here to cancel reply.

search search search search search
Find an Article
Categories
  • Flash Video Training
  • Hints and Tips
  • Recommended
Please Support Our Sponsors
Recent Posts
  • Workshop Coding Challenge: Fix This Breakout Game
  • Enable the Latest AIR SDK in Flash Professional CS5.5+
  • Quick Tip: Versioning Your Files With Dropbox (via Webdesigntuts+)
  • Workshop: Nuclear Outrun – Critique
  • Understanding Variables, Arrays, Loops, and Null: The Post-it Note Analogy
Tag Cloud
2011 ActionScript Active Activetuts+ Adobe animation Basic Basix Best Build Button Character Create Creating Critique Custom design Effect Effects Files Flash from Game Guide HTML5 Introduction Macromedia Motion Muzzle part Player Premium Professional Quick Silverlight Simple Text Tool Tutorial Tuts+ Tween Using Video website Workshop
About Our Site:

Hey there and welcome to "Flash Video Training Source", a resource for anybody interested in learning more about Adobe's great tool. We feature educational videos, which will help you master Adobe Flash and help you get to know all of its features. We at "Flash Video Training Source" believe that video training and video... more

Why don't you follow us on Twitter and get the latest video tutorials twitted to your account. Just click on the floating twitter bar to your right!

Go Back In Time
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  
Pretty Blank Box
top

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Archives

  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
Powered by WordPress  |  Designed by Elegant Themes  |  Lightning Fast Hosting by Site 5 Hosting