![]() |
Curly braces
Should I place a curly brace at the end a function or on the next line down?
EX: public function curlyBrace() { or public function curlyBrace() { Which is more accepted? |
Typographically, it makes more sense to put the bracket on the new line (or even, more properly, together with the following block it encircles), just the same way, if you had to design a book title, you'd not write it like so:
The Title of the Book you'd do it either like this: The Title of the Book or The Title of the Book The left bracket is opening a block, but if nothing follows immediately, then it feels strange. However Brian Kernighan and Dennis Ritchie formatted the code following their own understanding of typography (and those two are great men!) however, they are programmers, not graphic artists :) So they put the opening bracket on the same line. A lot of people who learned by their book had adopted this kind of formatting. So, there isn't probably right and wrong (and, frankly, C-like languages are typographically ugly anyway), so that only depends on the convention accepted in the place you work. I, personally, find Alman style easier to read, but this is typical of people to find something easier to understand if they are accustomed to doing it that way. |
I started doing k&R, Alman (opening bracket in new line) 2 years ago and I don't think I can go back now. I'm also unable to apply different style for different language so I do K&R/Alman for Javascript, PHP, Phython, Java and in fact any other language I might use. But to answer your question, it's your choice, nothing wrong with one or the other.
|
Personally, I find cuddled braces to be more difficult to interpret if the code is complex.
<div> is usually written on a new line to make the containers easier to visualize. The same logic applies to AS3 IMO. (especially classes) ActionScript Code:
For me, the formatting conundrum is with complex tweens ActionScript Code:
|
ASWC: how do you do either Alman or K&R in Python? Is there such thing anyway? The code formatting in Python is quite rigid and doesn't use curly brackets to denote a block of code, they are used for dictionaries... (well, maybe you can alter the grammar to look non-python-ish, but that's too advanced for me).
|
Quote:
|
The standard convention (according to Adobe) is to align the braces for all statement blocks.
I actually switched to this style a few years ago (against my will haha), but I actually quite like it now. |
I personally do a mix of the styles... Sometimes placing a curly bracket on a new line for a small method or conditions looks ugly in my opinion and just eats up unnecessary space, but then again, some things I do like to be separated nicely so that the code doesn't look like a huge continuous piece of glued text ( having to waste time then figuring out where certain things begin or end... comments could also be helpful but unfortunately, people either comment abusively or not at all - adding a crapload of unnecessary empty spaces / lines between lines of code is also quite ugly and could also make things somewhat hard to follow ).
ActionScript Code:
|
I have a tenancy to compact everything, but it makes it so hard to read.
I just got AS3 Design patterens by FOE but I haven't started it yet. I am half way through Learn AS3 by Oreilly and the author keeps changing between Curly bracket styles so I wanted to learn the most accepted way in case there was a difference, you know like Camel casing and underscore before the new object name. It's easier to read when the braces or on their own line. Mostly, I want to make it easy for other coders to see what am writing and to learn the best actionscript "grammar" practices. Thank you all :cool: |
Quote:
|
| All times are GMT. The time now is 01:03 AM. |
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger