Hacker News new | ask | show | jobs
by mrkeen 434 days ago
I grew up with "easy" languages. Pascal, VB, C, C++, Java, C#. And frankly I'm getting real sick of them.

I'm porting Dijkstra's algorithm over to C# at the moment, and in the last several hours here's the two most clownish things that have happened:

1) I have:

  if (node is null) {
    ..
  }
My IDE is telling me "Expression is always false according to nullable reference types' annotations". Nevertheless it enters that section every time.

2) I have:

  SortedSet<int> nums = [];
  Console.Out.WriteLine(nums.Min);
You know what this prints?

  0
The minimal element of a set which has no elements is 0.

Yes, every language has its warts, and anecdotes like this aren't going to change anyone's mind. I only wrote these up because they're hitting me right now in one of those languages that companies use "because anyone can learn them". I like harder languages better than easy languages, because they're easy.

2 comments

This is possible if you disregarded compiler warnings and assigned null to a non-nullable location.
Feels like this should be a compiler error. Or saying otherwise, this location isn't very non-nullable if you can assign null to it
Just add <WarningsAsErrors>nullable</WarningsAsErrors> to the project manifest.
2)

In general I'd recommend using Min() (from LINQ) which works as expected

But this property has this remark: "If the SortedSet<T> has no elements, then the Min property returns the default value of T."

1)

Feels like you used compiler hints incorrectly