coding-style

do interfaces belong in files of their own

As as rule of thumb I generally put classes in a file of their own. Visual studio seems to encourage this but what is appropriate with regards to interfaces? e.g. I have Class Foo that implements interface Bar public interface IBar { } public class Foo : IBar { } it seems natural to group these within the same file until anoth...

To "this" or not to "this" in C#?

Possible Duplicates: When do you use the this keyword? Best practices for using the this keyword in C# I have a style question regarding the this keyword. Do you use this when self-referencing auto-implemented properties or methods within a class for the sake of clarity? For one example, in your Constructor, do you write you...

Erlang style - case vs function pattern matching

I've got to the stage where I've written quite a bit of Erlang code now, and I can see some style (bad or good) creeping into the way I've been writing it. This particular idiom I'd like some opinion on - is it better (more readable/faster/whatever) to convert case style statements to function pattern matching? E.g. Compare (a contrive...

How to indent long conditionals for 'if' statements?

My question relates to this previous question, but the solutions offered don't address the problem I have outlined below. After a google search I haven't found any code style guidelines that address the specific problem of long conditionals in an if statement like this. if( isNull(value1) || isToLong(value1) || hasBadFormat(valu...

.net Placeholders & StringBuilders

When we build our web apps we construct alot of HTML dynamically and the output them to placeholders at run time. One reason for this is to control our HTML output to optimise it for SEO and now that we have been doing this for a while its become 'the way we do it'. Generally its when we are looping through results. My question is, Is ...

Cell Phone Programming?

Can someone point me in the right direction. I am looking to develop an application for a Verizon enV Touch, but I am totally clueless when it comes to this. Any advise on the technology used, the development tools needed, or application programming for cell phones in general is greatly appreciated. I basically need "Cell Phone Applicati...

PHP Function Abuse?

I have a large system that I have coded and I wish to make the code (dare I say) more simple and easy to read. Unfortunately before this, I haven't used functions much. I have many different MySQL Queries that are run in my code, I feel that if I make the various displays into functions and store them in a separate file it would make t...

Where Should Using Statements Be Located

Possible Duplicate: What is the difference between these two declarations? I recently started working on a project with using statement located inside the NameSpace block. namespace MyApp.Web { using System; using System.Web.Security; using System.Web; public class MyClass { I usually put my using statements above ...

What indenting style do you use in SQL Server stored procedures?

None of my SQL Server stored procedure editing IDEs seem to have any tools to enforce indentation styles, so I find that a lot of the stored procedures I see are all over the place. I find indenting really improves readability though. I would like to codify some stored procedure indenting standards in our company's coding style guide, ...

Coding Smells

Possible Duplicate: What are some bad programming habits to look out for and avoid? This is not a Code Smells question, but a Coding Smell Question aka programmer's working habits. What are known coding smells and steps to correct them. Example: Coding Smell: the programmer never checks to see if there is an existing class or...

Are you concerned about the aesthetics of your code?

I don't know if I'm the only person in the world which gets a bad feeling in my stomach if my code isn't "pretty". For example if I get a assignment that another person has been doing before me. I can't help it to clean the code and make it look "pretty". I don't know if it's some kind of OCD. It's like I see the code as some kind of a...

Holding onto object references

Given the below setup and code snippets, what reasons can you come up with for using one over the other? I have a couple arguments using either of them, but I am curious about what others think. Setup public class Foo { public void Bar() { } } Snippet One var foo = new Foo(); foo.Bar(); Snippet Two new Foo().Bar(); ...

In C/C++ can anybody provide some thumb rules for writing small function using inline or macro?

Discussing with people, asking in interviews, or being asked in interviews, I do not know if I know exactly when to write a function as inline or write it as a macro. Apart from compile-time and run-time consideration, is there any suggestion from coding standard point of view. I think this is one of those question where it comes to the...

Use of extension methods to enhance readability

What is the general thinking on the use of extension methods that serve no purpose other than enhancing readability? Without using extension methods we might have the method IEnumerable<DependencyObject> GetDescendents(DependencyObject root) {} that could be called with var descendents = GetDescendents(someControl); or foreach (v...

Enforcing code execution sequence

Sometimes you just have a list of operations that need to be performed in a set order, like when implementing a sequence diagram. What are the best ways to enforce code execution order, to prevent refactoring introducing subtle bugs through a change of sequence? Let's assume that existing unit tests would not catch any problems caused b...

What is the best way to return two lists in C#?

I am almost embarrassed to ask this question, but as a long time C programmer I feel that perhaps I am not aware of the best way to do this in C#. I have a member function that I need to return two lists of a custom type (List<MyType>) and I know beforehand that I will always have a return value of only two of these lists. The obvious ...

Opinion Poll on Unnamed Structs

Having a bit of internal debate in my group about the use of unnamed structs\unions in our C++ code. I'd like to get feedback from the community of what you think. Should they be used at all? When is it valuable? What are the pitfalls? etc. Example: union SFlags { struct { unsigned int A : 1; unsigned int B...

Lisp: Elegant way to strip trailing nil's from a list? (Review)

I want to write a function that removes trailing nil's from a list. I first tried to write it elegantly with recursion, but ended up like this: (defun strip-tail (lst) (let ((last-item-pos (position-if-not #'null lst :from-end t))) (if last-item-pos (subseq lst 0 (1+ last-item-pos))))) ; Test cases. (assert (eq nil (strip-t...

C# Namespaces/Folders: when is getting too organized/creating too many namespaces not right?

Hello: I like trying to stay organized when developing, grouping related *.cs flies together into their own folders: ->Project --->Enums --->Exceptions --->Extensions --->Providers --->Configuguration --->Design --->etc. Manager.cs As you all know, Visual Studio, by default, creates a new Namespace for each folder: Company.Product...

C# Action/Delegate Style Question

What is considered better style for an event definition: public event Action<object, double> OnNumberChanged; or public delegate void DNumberChanged(object sender, double number); public event DNumberChanged OnNumberChanged; The first takes less typing, but the delegate one gives names to the parameters. As I type this, I think nu...