2202.md

November 17, 2019 ยท View on GitHub

Language syntax makes code more concise. The abstractions make later refactorings easier (and sometimes allow for extra optimizations).

Prefer:

(string, int) tuple = ("", 1);

rather than:

ValueTuple<string, int> tuple = new ValueTuple<string, int>("", 1);

Prefer:

DateTime? startDate;

rather than:

Nullable<DateTime> startDate;

Prefer:

if (startDate != null) ...

rather than:

if (startDate.HasValue) ...

Prefer:

if (startDate > DateTime.Now) ...

rather than:

if (startDate.HasValue && startDate.Value > DateTime.Now) ...

Prefer:

(DateTime startTime, TimeSpan duration) tuple1 = GetTimeRange();
(DateTime startTime, TimeSpan duration) tuple2 = GetTimeRange();

if (tuple1 == tuple2) ...

rather than:

if (tuple1.startTime == tuple2.startTime && tuple1.duration == tuple2.duration) ...