Skip to content

Instantly share code, notes, and snippets.

@antmdvs
Last active August 12, 2019 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antmdvs/37a92cd1194c550f63d0f6f4412a5c2f to your computer and use it in GitHub Desktop.
Save antmdvs/37a92cd1194c550f63d0f6f4412a5c2f to your computer and use it in GitHub Desktop.

Discoverability: Strive for 1 type per file.

DO:

Foo.cs:

public class Foo {}

DON'T:

Foo.cs:

public class Foo {}

public class Bar {}  // this should be in Bar.cs

Readability: Prefer declarative over imperative

DO:

return debitAmounts.Sum(); 

DON'T:

var sum = 0;
foreach (var debitAmount in debitAmounts)
{
  sum += debitAmount;
}
return sum;

DO:

var termMonths = loan.TermInMonths;
var loanAmount = loan.Amount;
var interestRate = loan.interestRate;
var inServiceDate = vehicle.InServiceDate;
var vin = vehicle.vin;

DON'T:

int termMonths = loan.TermInMonths;
double loanAmount = loan.Amount;
double interestRate = loan.interestRate;
DateTime inServiceDate = vehicle.InServiceDate;
string vin = vehicle.vin;

Readability: Prefer foreach (...) statement over ForEach() extension method to make looping constructs easier to spot.

Readability: Use simplified type names unless fully qualified type names are necessary to avoid type collision.

DO:

using Foo.Bar.Baz;

public void DoSomething(Qux qux) {}

DON'T:

public void DoSomething(Foo.Bar.Baz.Qux qux) {}

Use "" not string.Empty

Use == over .Equals when comparing 2 non-object types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment