I catch complaints, now and then, about my putting left braces on a line by themselves. I originally got this habit because my CS professor would give us 0% if we didn't do that religously! Now I have a hard time reading code because the braces don't line up. Furthermore, I keep seeing bizarre indenting which I think is a far more serious problem.

IMHO we should allow the left braces to be on their own line, or not, depending on the taste of the programmer -- keeping in mind Bill Shannon's rule #0 about formatting (match the existing style).

Here is an example of what I mean. This comes from the very beginning of the most public class we have in AppServer -- PELaunch

    if(args[0].trim().equals(STOP)) {
        // check if instance is already running
        if (isInstanceRunning()) {
            PEMain.shutdown();
        return;

        } else {
            getLogger().log(Level.INFO, "instance.notRunning");
        return;
        }
        }
Why are the "return"s indented out? Why are two closing braces at the same level of indent (I see this constantly) I think the way I would formatted it is clearer: (let's not even go there about the else being pointless!). When you line up the braces this way you never have the odd "lined-up closing braces" appear because it would stick out like a sore thumb.
    if(args[0].trim().equals(STOP))
   {
        // check if instance is already running
        if (isInstanceRunning())
        {
            PEMain.shutdown();
            return;
        }
        else
        {
            getLogger().log(Level.INFO, "instance.notRunning");
            return;
        }
    }
Comments:

"putting left braces on a line by themselves. I originally got this habit because my CS professor would give us 0% if we didn't do that religously" He should have been fired. That's outrageous.

Posted by Toby on October 14, 2006 at 05:47 PM PDT #

助听器协会网 天津助听器之家 中国助听器与耳聋康复网 中国助听器大全 斯达克助听器北京验配中心 丹麦助听器上海验配中心 湖南助听器网 名品助听器(南京)直销店 助听器价格查询网 北京助听器第一验配中心 助听器聋儿互助康复中心 上海助听器大世界 助听器中国聋儿康复网 中国助听器信息网 中国助听器折扣网 中国名牌助听器直销网 国际品牌助听器(北京)直销中心 安徽助听器资讯网 助听器(广州)验配中心 贵州助听器信息港 广东助听器之窗 广西助听器验配网 江苏助听器特价网 中国聋儿助听器直销网 甘肃助听器直销网 宁夏助听器网 浙江助听器在线 山东助听器信息网 中国助听器联合交易网 进口轴承 噪音 消音

Posted by sdwe on October 14, 2006 at 06:30 PM PDT #

婚纱摄影 婚纱影楼 非油品 中石化 网页制作 网页设计 网站建设\ 网站制作 网站设计 设计 北京网站设计 网站推广 北京网站推广 北京网站制作 北京网页设计 北京网站建设 网站优化 yahoo竞价 google推广 google排名 google优化 法语 钟表 塔钟 钟表 家用中央空调 格力中央空调 助听器 助听器 助听器 法国留学 法语培训 进口轴承 skf轴承 nsk轴承 轴承 进口轴承 skf轴承 fag轴承 轴承\ 轴承 进口轴承 进口轴承 直线轴承 skf轴承 nsk轴承 北京装饰|装修 家装|家庭装饰 办公室装饰|装饰公司 装修公司|工装装潢 装饰装修|北京装饰公司 家居装修|室内装修 房屋装修|家庭装修公司 装修设计|室内装潢 家居装潢|家庭装潢 装潢设计|室内装潢设计 充气床 充气用品 充气游泳池 野营用品 户外用品 充气船 气垫床 钓鱼船 帐篷 户外帐篷 瑞士军刀 intex充气床| 中央吸尘 家用中央吸尘 商业中央吸尘 吸尘器 中央吸尘系统 工业吸尘 风灶清洗 通风清洗 中央空调管道清洗 机器人管道清洗 管道清洗机器人 机器人清洗 检测机器人 吸尘机 别墅吸尘 宾馆吸尘| 网站建设 网站制作 网页设计 网页制作 网络推广 网站优化 网站推广 GOOGLE优化 进口轴承|nsk轴承|skf轴承 充气床|充气用品|充气游泳池|野营用品|户外用品|充气船|气垫床|钓鱼船|帐篷|户外帐篷|瑞士军刀| 北京酒店<a> 上海酒店<a> 广州酒店<a> 长沙酒店<a> 张家界酒店<a> 南京酒店 <a> 深圳酒店<a> 天津酒店<a> 重庆酒店<a> 昆明酒店<a> 桂林酒店<a> 井冈山酒店<a> 酒店<a> 西藏酒店<a> 宾馆<a> 宾馆预定<a> 杭州酒店<a> 北京酒店<a> 上海酒店<a> 广州酒店<a> 长沙酒店<a> 张家界酒店<a> 南京酒店 <a> 深圳酒店<a> 天津酒店<a> 重庆酒店<a> 昆明酒店<a> 桂林酒店<a> 井冈山酒店<a> 网站制作<a> 网站策划<a> 网页美工设计<a> 网站设计方案<a> 网站建设公司 网站制作公司 网站推广公司 网页设计公司 网站设计公司<a> 进口轴承 噪音 消音

Posted by dsfwe on October 14, 2006 at 06:31 PM PDT #

If you put 20 people in a room and ask what is the correct indenting style, you will get 20 different opionions. Who is correct? The manager of course. Yes, having a common style across all files does make the code easier to read, but why pay engineers to edit whitespace. Why not just use a utility like gindent which only adds about 1 second to the development time, instead of many minutes and lots of interactions about style. Why, no you have to do it my way......

Posted by King Bee on October 14, 2006 at 09:35 PM PDT #

I applaud your CS professor. Set a standard and then enforce it. I wish everyone was as consistent. BTW your second example is exactly the way I code in C and Perl.

Posted by Volker A. Brandt on October 15, 2006 at 02:03 AM PDT #

The human eye (brain) can detect even tiny differences in asymmetry quite easily. A symmetric style (braces on their own lines, matched in indent levels) ties in with that natural ability, offering a larger scale pattern easily scanned with only a casual glance.

The view that an asymmetric brace style is as good as a symmetric one flies in the face of this natural ability. The pattern formed (space occupied) by matching braces on their own lines, equally indented, is more visually prominent than using asymmetric '{' and '}' characters, which must be painstakingly acquired by scanning the ends of lines (at varying positions for each line).

That perhaps is the most troubling--the non-uniform indentation of the '{', which can be further to the left for *more* heavily-indented lines--a violation of a reasonable expectation that places more heavily indented material further to the right as shown below. There is no placement consistency with such an approach.

if ( very long expression ) {
   if ( short-expr {
       if ( s ) {
           if ( long long long long long expr ) {
               ....
           }
       }
   }
}

The above example is pretty goofy as far as patterns go; no placement-consistency and no visual symmetry with the braces; the pattern formed is not reinforced by having a matching brace; only blank space is available to help make the visual scanning easier. Just draw a continous line through the '{' characters and the meandering route is evident. Add to that the often semi-random placement of closing braces (which seem to be encouraged by the semi-random placement of the opening '{' brace, and it's a recipe for tough slogging. Here's a very commonly-seen style (the "mishmash" style) that's found in a lot of code. I'm sure it's encouraged by the lack of placement-consistency of the '{' :

int foo( ... args ... )
{
  if ( expr1 ) {
      ....
  } else {
      ...
  }
  }

A better way--one style to suit them all, one style to search visually, one style to bind the code together in a common approach:

if ( very long expression )
{
   if ( short-expr
   {
       if ( s )
       {
           if ( long long long long long expr )
           {
               ....
           }
       }
   }
}
Compare the prior example to the one above. The example above shows strong placement-consistency, and the visual symmetry is reinfored by the symmetric use of braces.

Just as with a photograph, strong compositions are made by strong visual patterns; small details rarely make a photograph strong, unless there are many, and taken as a group, and at that point its pattern recogition on a broad scale--with braces, the issue is matching up individual pairs.

Posted by Lloyd Chambers on October 16, 2006 at 10:46 AM PDT #

best site http://www.onlinecasino.org.in

Posted by Online Casino on October 25, 2006 at 04:13 AM PDT #

this is cool, this is what we want dude......

Posted by Tiffany Cuff Links on November 13, 2009 at 06:29 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by codeplumber