Do not believe any documentation

TL;DR; Do not believe any documentation. It might be incorrect or you may not understand it. Test everything.

MSDN lies

A few months ago I was writing some code in C# to get executable paths for all running processes. Generally, I tried the most common approach using BCL:

string executablePath = process.MainModule.FileName;

However, for some process instead of getting MainModule I got, guess what? NullReferenceException! Of course, it is not documented MainModule. What happened? Processes like Windows Defender or Windows Telemetry are protected. Even a Windows Service running as SYSTEM account (in user mode) cannot see all processes details. I would say that it is a bug in BCL, but they should really at least mention it.

This is just a really minor thing. Some time ago the volatile keyword has been described incorrectly on MSDN. Fortunately, it has been corrected after a few years. Still, at the same time, MemoryBarrier documentation is telling bullshit. If you want to dig deeper, I highly encourage you to read: http://www.albahari.com/threading/part4.aspx.

The saddest thing is that C# 8.0 is coming. Yet we still do not have finalized language specification even for C# 6.0 which was released in 2015…

GoLang language specification lies? Ufff not this time

Next example from GoLang (spotted today).

Arithmetic operators apply to numeric values and yield a result of the same type as the first operand.

https://golang.org/ref/spec#Arithmetic_operators
fmt.Println(2/3.0) // prints 0.6666666666666666 (sic!)

Try it yourself: https://play.golang.org/p/xT_Slh5Aog4

Digging deeper it occurred that it is correct behavior.

If the untyped operands of a binary operation (other than a shift) are of different kinds, the result is of the operand’s kind that appears later in this list: integer, rune, floating-point, complex. For example, an untyped integer constant divided by an untyped complex constant yields an untyped complex constant.

https://golang.org/ref/spec#Constant_expressions

I have almost submitted an issue on https://github.com/golang/go., but someone did it before: https://github.com/golang/go/issues/11166. 

Do not believe YOU UNDERSTAND the language specification.

 

Leave a comment