coding-style

acceptable fix for majority of signed/unsigned warnings?

I myself am convinced that in a project I'm working on signed integers are the best choice in the majority of cases, even though the value contained within can never be negative. (Simpler reverse for loops, less chance for bugs, etc., in particular for integers which can only hold values between 0 and, say, 20, anyway.) The majority of ...

Line width formatting standard

Do you follow a standard for wrapping long lines in source code? What line length do you find most comfortable to read? Sometimes I find people who program on wide-screen monitors and like to use its full width for displaying source code. I prefer shorter lines, around 80-100 characters, but I have a hard time trying to convince colleag...

What are your favorite C++ Coding Style idioms

What are your favorite C++ coding style idioms? I'm asking about style or coding typography such as where you put curly braces, are there spaces after keywords, the size of indents, etc. This is opposed to best-practices or requirements such as always deleting arrays with delete[]. Here is an example of one of my favorites: In C++...

The use of config file is it equivalent to use of globals?

I've read many times and agree with avoiding the use of globals to keep code orthogonal. Does the use of the config file to keep read only information that your program uses similar to using Globals? ...

Is there any Code Style Analysis Tool for C#?

Here in Brazil we call it "Padrão de Codificação", probably in English this is called Coding Pattern or Code Style, a set of constraints to developers build their code following rules for naming variables, methods, classes, for instance. Another constraints can be written, not only for naming things. Our company has a coding pattern for...

Javascript clarity of purpose

Javascript usage has gotten remarkably more sophisticated and powerful in the past five years. One aspect of this sort of functional programming I struggle with, esp with Javascript’s peculiarities, is how to make clear either through comments or code just what is happening. Often this sort of code takes a while to decipher, even if you ...

Where to wrap a line of code, especially long argument lists?

What's your preferred way of wrapping lines of code, especially when it comes to long argument lists? There has been several questions relating to wrapping lines (such as When writing code do you wrap text or not? and Line width formatting standard), but I haven't been able to find one which covers where to wrap a line of code. Let's s...

Enforcing a coding style

Years ago when I was starting a small development project, the other developers and I sat down and agreed on a compromise brace and indentation style. It wasn't anybody's favourite, but it was something that nobody really hated. I wrote a .indentrc configuration file to that style, and had a check-in trigger that would run indent on ev...

Is lining up operators a worthy style?

some_var = foo() another_var = bar() or some_var = foo() another_var = bar() Including changing the whitespace as lines are added or removed to keep them lined up. Does this really look good? Is it worth the mucking up of the diff? ...

Are style-enforcement tools useful?

A recent question about StyleCop alerted me to the use of tools to enforce coding style. I would feel very annoyed if I were required to run one of these tools while I was developing. Do people really find them useful? Why or why not? Everyone that has answered so far has indicated that they think that style/formatting rules are useful,...

How do you format your Compound Statements in Delphi and C#?

As a long time Pascal and Delphi developer, I always line up my begin and ends thus : begin if x = y then begin ... ... end else for i := 0 to 20 do begin ... ... end; end; What drives me nuts is code formatted thus : begin if x = y then begin ... ... end else for i := 0 t...

Do you try to make your code look pretty?

I might be one anal programmer, but I like code that looks good from a distance. I just found myself lining up a CSS style so that instead of this: #divPreview { text-align: center; vertical-align: middle; border: #779 1px solid; overflow: auto; width: 210px; height: 128px; background-color: #fff" } it now looks like: #divPrev...

Is there a good reason to use upper case for T-SQL keywords?

The default seems to be upper case but is there really any reason to use upper case for keywords? I started using upper case because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored procedure. But then, I feel terrible for my baby (5th) finger that always needs to hold down the S...

Understanding Dijkstra's Mozart programming style

I came across this article about programming styles, seen by Edsger Dijsktra. To quickly paraphrase, the main difference is Mozart attempted to figure everything out in his head before writing anything, while Beethoven made his decisions as he wrote the notes out on paper, creating many revisions along the way. With Mozart programming, v...

How to make the cleanest code when reporting progress to a user?

I've struggled for the last couple of months to come up with some clean code to report progress to a user. Everything always seems to boil down to: ReportProgress("Starting Task 1"); doTask1(); ReportProgress("Task 1 is done"); ReportProgress("Starting Task 2"); doTask2(); ReportProgress("Task 2 is done"); //etc... where report progr...

SQL Server 2005: "Protecting" stored procedures from FMTONLY mode used by MS Access

Some of the stored procedures we have contain conditional logic, like this: Create Procedure dbo.DoSomething(Some Parameters) As ... If (Some Condition) Begin Set @SomeVariable = SomeValue End ... Select ... When such a stored procedure is used as a recordsource for an MS Access form, and us...

Should I capitalize my constants?

What do you guys think? Should constants be capitalized? Or is that an archaic practice? So... const int MY_CONSTANT = 5; vs. const int myConstant = 5; ...

Annoying or idiotic naming conventions?

What programming or naming conventions have you come across that really rub you the wrong way? For those that aren't aware, in C# we can wrap blocks of code with a #region directive, which allows you to collapse these blocks in Visual Studio for readability. So the convention on this team is to wrap all combinations of access modifi...

Is it still necessary to put a space before closing an empty element in XHTML?

W3C recommends putting a space before the closing tag in XHTML, because this would give a better backwards compability with some browsers, e.g. write <br /> instead of <br/>. But are there still browsers out there, that would not tolerate that you omitted the space? (W3C do not mention which browsers cause problems.) I know it doesn't m...

PHP coding standards

I've been looking for some guidelines on how to layout PHP code. I've found some good references, such as the following: http://www.dagbladet.no/development/phpcodingstandard/ and this question on SO. However, none of that quite gets to what I'm specifically wondering about, which is the integration of HTML and PHP. For example: is ...