Don't click here unless you want to be banned.

LSL Wiki : brace

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

Braces


What is a brace? Simple, they're these little 'curly-q' brackety characters:

{}


Braces are used to define code blocks. Do not confuse them with brackets!

Indenting Styles

The two most common brace/indenting styles are as follows:

Allman/C-Style
default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
}

K&R/Sun-Style
default {
    state_entry() {
        llSay(0, "Hello, Avatar!");
    }

    touch_start(integer total_number) {
        llSay(0, "Touched.");
    }
}

C-style tends to be more common than K&R, and it's what the LSL editor uses for its default script.

The advantage of the K&R style is that it saves a lot of space. -?
How much space? A linefeed and a tab isn't a lot of space added up... -EepQuirk
The advantage of C-style is that Catherine likes it.
TreadWhiplash likes C-style a lot; and notes that C-style is a hell of a lot more readable in complex code!
ChristopherOmega disagrees with Tread. A smaller number of lines your eye has to scan through makes K&R code easier to read. It's all a matter of taste though.
It ends up being many MORE lines your eye has to scan through trying to find where a codeblock begins. -EepQuirk
As answered in my comment below, that depends upon how much you know (or want to know) your language. Also, when you gauge the scope from the distance you are from the margin, it doesnt matter which style you use in terms of how much more your eyes need to run thru. -ChristopherOmega
StefanNilsson also likes C-style and happily throws in the question of whether or not to explicitly add braces even when the code block consists of only one statement. The Swede says: yes!
I don't do this because it's more efficient to have it all on a single line. -EepQuirk
I tend towards indenting the line after the conditional statement, reguardless of whether it's enclosed in brackets. Saves a couple lines without sacrificing a significant amount of readability. -ChristopherOmega
DolusNaumova wonders if not putting spaces between a closing parenthesis and a brace is still K&R-style?
NornAlbion likes a mix of both styles, using C-style for default and K&R-style for the rest.
IoneLameth likes Python indenting so calls this moot (and seems to mix them in practice).
SkyHoney always adds the braces even for a single statement since she learned Perl, which requires them. Even though it adds an extra line for the closing brace, it makes the code even more beautiful. :)


Bracket | Syntax
There are 20 comments on this page. [Display comments/form]