void is a bug

Having studied Haskell and F# and done a lot of C# coding in functional style I realize that “void” declaration in C-family of languages is a bug in the type system.

It appears where a type should be, but is in fact an instruction to forget everything you know and hold dear and treat the calls to this function differently.

Enter Action vs Func<Unit> distinction. What it comes down to is that you have to duplicate all the code that works for Func<> to get its functionality for methods that don’t have a value to return.

.ForEach() doesn’t have to exist and yet, there’s gazillion implementations floating around for something that could have been implemented (once) as something like a fold().

.NET 3.5 should have included and promoted Unit type.


void is a bug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s