### Make Your Code Clear: C#: Listing 1: Numeric library version 1

This version of the numeric library works correctly. However, there are many poor practices in this library that make it harder to use. In addition, those practices will confuse users of the code. They'll make assumptions about what the code does because of how it's structured. In its current form, those assumptions will be wrong.

```public class NumericAlgorithm
{
public double Mean(List<double> sequence)
{
double total = Sum(sequence);
return (sequence.Count == 0)
? total : total / sequence.Count;
}

public double Median(List<double> sequence)
{
if (sequence == null)
throw new ArgumentNullException("sequence",
"Sequence must not be null");
if (sequence.Count == 0)
return 0;

List<double> local = new List<double>(sequence);
local.Sort();

return local[local.Count / 2];
}

public double Variance(List<double> sequence)
{
double sum = Sum(sequence);
if (sequence.Count == 0)
return 0;
List<double> squares =
sequence.Select(n => n * n).ToList();
double sumSquares = Sum(squares);
double variance = (sumSquares + sum * sum /
sequence.Count) / (sequence.Count - 1);
return variance;
}

public double Sum(List<double> sequence)
{
if (sequence == null)
throw new ArgumentNullException("sequence",
"Sequence must not be null");
double total = 0;
sequence.ForEach(num => total += num);

return total;
}
}```
comments powered by Disqus

• ### Computing the Similarity Between Two Machine Learning Datasets

At first thought, computing the similarity/distance between two datasets sounds easy, but in fact the problem is extremely difficult, explains Dr. James McCaffrey of Microsoft Research.

• ### Progress Telerik Adds New Controls for Blazor, .NET MAUI, Desktop

The new R3 2021 release of Progress Telerik developer tooling for .NET developers is out with new controls for Blazor, .NET MAUI (evolution of Xamarin.Forms) and desktop offerings including WinUI, WPF and WinForms.

• ### Blazor Developers Can Now Create Custom Elements, Render Components from JavaScript

Microsoft's Blazor web-dev tech received a raft of improvements in the new .NET 6 Release Candidate 1, including the ability to create custom elements, render components from JavaScript and even generate Angular and React components.

• ### .NET MAUI 'Slips the Schedule,' Won't Ship with .NET 6 in November

Microsoft said its .NET Multi-platform App UI (.NET MAUI) framework for client app development wont ship with .NET 6 in November as planned, but rather sometime in the second quarter of next year.

• ### Visual Studio 2022 Preview 4: Hot Reload Expands, Speed Improvements

Visual Studio 2022 Preview 4 is out with more Hot Reload functionality, multiple performance improvements, debugging enhancements and more.

Upcoming Events