Software Engineering discussion

8 views
Code Complete > Layout and Style

Comments Showing 1-5 of 5 (5 new)    post a comment »
dateUp arrow    newest »

message 1: by [deleted user] (last edited Jun 05, 2011 07:15AM) (new)

Of course, the only proper brace style is like this:


if ( foo ) {
   bar();
}

and no one should ever do this:

if ( foo )
   {
      bar();
   }

(just kidding)

Although endlessly controversial in specifics, I think that proper (or at least consistent) formatting is crucial. I find that the best programmers also take care in how their code looks.

When teaching programming to people who are new to it, and when they bring me some code to look at for help, more often than not it is a visual mess. The first thing I tell them to do is run it through a pretty printer or lay it out cleanly by hand. Most times, after they do that, they can then find the bug themselves.

As an aside, I am reading this book in ePub format on an iPad, and the code listings are all fairly messed up with line wraps!


message 2: by Erik (new)

Erik | 165 comments I liked the quantity of code examples in this chapter, but it did make the page count increase. I can understand why other chapters had fewer code examples in an already big book.

Yes, MS Visual Studio has suggested format and will use it's intellisense feature to make formatting changes for curly brackets and other syntax structures. It's no fun to fight the IDE's suggested format, so I usually don't try to.

I have been writing and working with Quine programs in my "fun" time lately. If you search the internet for Quine code examples, they are some of the most unreadable code I've ever encountered. I think if I tried to write code formatted that way it would be littered with bugs. Those Quine's authors must be very tallented.


message 3: by [deleted user] (new)

Wow, I didn't realize that Quine programming blossomed into such a big hobby!


message 4: by Erik (new)

Erik | 165 comments I enjoy Quine programming, but I have not applied it to any real world problems or applications yet. There are several blog entries that discuss Quine programming. I read what I could find. Most Quines seemed to aim towards making the code as short as possible, which loses readability.

I wrote a tool to automate the code-data synchronization tasks. I tried to make my Quine very OO rather than aiming for shorted code. I was using C# and .Net.

My quine compiles its clone and kicks it off in a new process, which makes for a fun endless loop (almost virus-like) effect.


message 5: by Aleksander (new)

Aleksander Shtuk | 84 comments My favorite section in this chapter is “How Much is Good Layout Worth?”. I think layout can be “measured” by the desire of programmer to come back to code that was done using rules of that layout. I wish some people write math expressions on a paper before translating it to code using same spaces and brackets. I bet those people have some advice for me too :)


back to top