0
votes
2answers
58 views

Overloading Methods With Different Behavior - Style

I have a style question about overloading methods/constructors. I have a constructor which does something very simple, and then calls a method with some side effects. Sometimes however I don't want ...
2
votes
4answers
617 views

DTOs matter on ASP.NET MVC JSON Action?

I recently came across an internal project where they were using DTOs throughout the solution, and when I sat down to implement a new MVC controller with a JSON REST endpoint I decided to use an ...
2
votes
3answers
240 views

Should I make a variable readonly when I modify it, but I don't actually set it outside of the constructor?

Background: I was writing some code. It looked something like this: class X { private List<int> _myList = new List<int>(); public void MyMethod(int x) { ...
6
votes
3answers
368 views

Is the usage of internal scope blocks within a function bad style?

There are some (quite rare) cases where there is a risk of: reusing a variable which is not intended to be reused (see example 1), or using a variable instead of another, semantically close (see ...
3
votes
3answers
816 views

When are chained assignments (i.e. a=b=c) bad form?

I'm working on a VB.Net WinForms project and found myself writing code like this: this.Fizz.Enabled = this.Buzz.Enabled = someCondition; I couldn't decide whether that was bad code or not. Are ...
2
votes
4answers
2k views

Microsoft's coding standards for ASP.NET controls

I cannot find any naming standards/conventions in MSDN for naming ASP.NET controls. One of the following standards tends to be used by programmers: lblAddress AddressLabel Address According to ...
7
votes
7answers
1k views

Prevent developers from using constants

I have one one software system which allows developers to specify an ID or name to create NodeReferences. Both work fine, but ID's are not guaranteed to be the same across different environments. I've ...
2
votes
2answers
477 views

coding style for If condition [duplicate]

I came across below style of writing if statements in C#, on msdn code examples. Usually when I write if statements, the conditions I would write `(Customer != null) I want to know if there is any ...
11
votes
4answers
470 views

Always pull out common cases and branch separately? [duplicate]

We had a disagreement in a code review. What I had written: if(unimportantThing().isGood && previouslyCalculatedIndex != -1) { //Stuff } if(otherThing().isBad && ...
2
votes
2answers
270 views

Style for creating IEnumerable unions

There isn't any cool LINQ sugar for creating unions. The Enumerable.Union() method is usually called like this: var bigList = list1.Union(list2); The alternative is to call Enumerable.Union() which ...
3
votes
5answers
264 views

Using 'new' in a projection?

I wish to project a collection from one type (Something) to another type (SomethingElse). Yes, this is a very open-eneded question, but which of the two options below do you prefer? Creating a new ...
5
votes
4answers
1k views

Switch or a Dictionary when assigning to new object

Recently, I've come to prefer mapping 1-1 relationships using Dictionaries instead of Switch statements. I find it to be a little faster to write and easier to mentally process. Unfortunately, when ...
3
votes
6answers
1k views

Using prefix incremented loops in C#

Back when I started programming in college, a friend encouraged me to use the prefix incrementation operator ++i instead of the postfix i++, citing that there was a slight chance of better performance ...
4
votes
3answers
665 views

Should I prefer properties with or without private fields?

The codebase I'm working in now has the convention of using private fields and public properties. For example, most classes have their members defined like this: // Fields private double _foo; ...
1
vote
7answers
8k views

If condition not true: default value or else clause? [closed]

I have searched Programmers and Stackoverflow and was not able to come up with a satisfying answer, even though I'm quite sure it must have been asked many times before. The only question I found has ...
7
votes
4answers
2k views

Are fluent interfaces more flexible than attributes and why?

In a EF 4.1 Code First tutorial the following code is given: public class Department { public int DepartmentId { get; set; } [Required] public string Name { get; set; } public virtual ...
7
votes
4answers
402 views

Warn about 3rd party methods that are forbidden

Note: This question refers to code written in Java or C#. I am managing a couple of large projects where we have discovered issues (not necessarily bugs) with some 3rd party/SDK methods and have ...
9
votes
2answers
931 views

Is this awkward spacing some type of style?

In reading another programmers code, he uses a format I have never seen. E.G. namespace MyNs.HereWeAre {//tab here for some reason public class SomeClass ...
9
votes
4answers
925 views

C# return variables

In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned ...
4
votes
4answers
2k views

How to ensure a single coding standard in .NET with tool support

Probably, the basic situation is familiar to everyone. You have agreed on certain coding standards in your team and now it is time to make sure that everybody follows them. Some do it via heavy ...
3
votes
1answer
466 views

Has anyone thoroughly compared C# common coding standards?

Most of the C# programmers I know embrace one of the common coding standards. However being aware of the standards is one thing, telling the differences is another. Browsing the common coding ...
2
votes
4answers
271 views

Do more object declarations affect the program?

I am programming in Windows Forms and MySQL. If I declare this in the program, I can use the connection and command objects in the whole .cs page: MySqlConnection connection = null; MySqlCommand ...
41
votes
14answers
4k views

Should I encourage junior developers to use explicit or implicit typing?

I am looking to solicit the community's opinion on whether or not it would be advisable to teach junior developers to code with implicit typing (using var) or should I encourage the use of explicit ...
6
votes
3answers
557 views

Programming standards and principles to become better programmer [closed]

I am a c# developer. I have always been interested in increasing my skills and knowledge and trying to pickup new technology. However now I want to enhance my knowledge in Programming standards and ...
5
votes
3answers
589 views

Is it bad idea to use flag variable to search MAX element in array?

Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation ...
15
votes
9answers
5k views

Why are people so strongly opposed to #region tags in methods?

I hear a lot about keeping methods short and I've heard a lot of programmers say that using #region tags within a method is a sure sign that it is too long and should be refactored into multiple ...
4
votes
4answers
265 views

How do you proactively guard against errors of omission?

I'll preface this with I don't know if anyone else who's been programming as long as I have actually has this problem, but at the very least, the answer might help someone with less xp. I just stared ...
10
votes
3answers
3k views

What should I include in XML documentation comments?

I'm trying to make a point of documenting my code better, especially when it comes to the XML comments on class members, but often it just feels silly. In the case of event handlers, the naming ...
13
votes
6answers
1k views

When should I use a 2-property class over a pre-built structure like a KeyValuePair?

When should you put Key/Value type of data in it's own class instead of using a pre-built generic structure, such as a KeyValuePair or a Tuple? For example, most ComboBoxes I create contain a ...
10
votes
9answers
2k views

LINQ Style preference [closed]

I have come to use LINQ in my every day programming a lot. In fact, I rarely, if ever, use an explicit loop. I have, however, found that I don't use the SQL like syntax anymore. I just use the ...
10
votes
5answers
2k views

Why have a method that returns a bool/int and has the actual object as an output parameter?

I see the following code pattern all over the place in my company's codebase (.NET 3.5 application): bool Foo(int barID, out Baz bazObject) { try { // do stuff bazObject ...
13
votes
12answers
938 views

What is the regarded current best practises regarding the “this” keyword in front of field and methods in c#?

Unless it is needed to differentiate between a variable and field with the same name, I never put this. in front of a field or any member access in C#. I see this as no different to m_ prefix that ...
2
votes
3answers
326 views

C# Coding Standard - Position of Attribute in relation to Target

I had thought that this was one of the few solved problems in C# coding standards / style; Attributes always appear on the line above the thing to which they are applied a la [SomeClassAttribute] ...
3
votes
1answer
155 views

FromXYZ vs Overloaded Method

I'm trying to think of the cleanest way to implement a couple of methods that open a file. Consider the following method signatures: public static DomainObject Load(Uri urlToFile) { /* downloads ...