* Posts by jorick

3 publicly visible posts • joined 7 Aug 2013

Can't agree on a coding style? Maybe the NEW YORK TIMES can help

jorick

Re: ARRRGGGGG!!!!!!

"all functions have precisely one entry point. They should have only one exit point"

MISRA-C requires it!

jorick

Re: 4 SPACES?!

Our company has decided to use the IAR compiler to build the code for our embedded system. The reason was that it generated the tightest ARM code and the project we had contained 251K of executable code in 256K flash memory. The IAR compiler was the only one that could fit the code into the allotted space. That being said, IAR is the horse that we hitched our cart to, and we aren't switching to a different one.

Last month we encountered a bug in the IDE portion that caused builds to fail. I traced it down to a combination of factors, one of which was a certain configuration of tabs in the source file. I eliminated the tabs and the build proceeded normally.

I have no idea why the IDE would be concerned with tabs in a source file (although I know that there is some scanning of the files to determine dependencies, etc.). I've been very lenient about tabs in our department (even though we have a coding standard that forbids them) but they started affecting our work so I had to remove all tabs from the project and tell all the software engineers that tabs were no longer allowed. Fortunately, all the engineers agreed this was the best way to go.

By the way, we used to have an engineer that swore upon tabs and got angry when my editor automatically converted all tabs to spaces when I edited the file. One day he was entering some aligned character strings into the code, and he used tabs to perform the alignment. The C compiler didn't care and dutifully added the tabs to the code. The display driver only worked with the standard space-to-tilde characters and generated a wild pointer when it came upon the tab which wasn't in the character table. The system crashed miserably and some serious debugging time was wasted trying to find the bug.

The moral of these stories is to stick with stuff that's guaranteed. The space is guaranteed to give you one character width regardless of where it's placed, and is guaranteed to work with virtually all display drivers. The tab will not give you a guaranteed width, and may cause strange behaviour or even cause a crash if used.

jorick

Re: Putting the first one at the end of the line is just stupid.

I don't know how many times I've done this:

if (Test == 1)

---Line1 = 1;

---Line2 = 2;

} else {

---Line3 = 3;

---Line4 = 4;

}

I've told all the people that work under me to put braces on their own line aligned with the if. We work in the medical industry and we can't afford to have bugs in our code that could jeopardize lives. I wrote a coding standards document for our company based on Netrino's standard that helps us write bug free code. It's anal but it gets the job done.

If vertical space is a problem, then either your coding style is wrong or you need a better editor. Nobody should be writing functions containing hundreds or thousands of lines of code. If I have a function that's over 100 lines, I'll look for ways of breaking it up into multiple functions that are more readable and maintainable.

As for the editor, I use SlickEdit. The document window can either be in the main SlickEdit window or in it's own child window that can be moved anywhere on the screen. I use the Terminal 6 font which gives me over 120 lines of code in the window. And my 1680x1050 monitor can hold three files side by side. Yes, my editor can search for matching braces, but I've got better things to do with my time than trying to find mismatched braces. I actually haven't used that function in over a year because our brace standard makes it so easy to see any mismatches.

By the way, for anyone who doesn't see the problem in the snippet above, the first brace is missing. Aligning the end brace with an if isn't enough to ensure that the code is correct.