开发者

What's the best format to write my functions in?

which format is best practice?

format A

function FunctionA () 
{
    while () 
    {
        >>some code<<
    }
    if ()
    {
        &开发者_StackOverflow社区gt;>some code<<
    }
    else if ()
    {
        >>some code<<
    }
}

format B

function FunctionB () {
    while () {
        >>some code<<
    }
    if () {
        >>some code<<
    } else if () {
        >>some code<<
    }
}


It doesn't really matter, as long as you adhere to one style, and when in a project with multiple people agree on one style and all use that style.


It's all up to your preference. There is no real "best".

I prefer format A because I can put comments in the space provided by the opening braces.

eg.

function FunctionA () 
{// this function does some stuff
    while () 
    {
        >>some code<<
    }
    if ()
    {
        >>some code<<
    }
    else if ()
    {
        >>some code<<
    }
}

But some people may prefer the format B as it is more compact.

But others may prefer even more obfuscated code like this:

function ObfuscatedFunction () {while () { >>some code<<}if (){>>some code<<}else if () { >>some code<< }}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜