logoalt Hacker News

mrkeentoday at 12:06 PM1 replyview on HN

I was recently switched from Java to C# at work.

Initially I was impressed by the null detection. Then I found out about defaults. Way worse than null.

C and Go can demand a bit of ceremony with manual error checks. Things get bad if you forget to do the checks.

Java and Checked exceptions forced error-checking, which is a little verbose, and most of the time you can't 'handle' (for any meaning other than log) them, so you just rethrow.

C# went with unchecked exceptions. But with default values, there's no need to throw! Avoid Java's messy NPE encounters by just writing the wrong value to the database.


Replies

neonsunsettoday at 4:17 PM

Default value is only relevant for structs. You can setup an analyzer rule to ban this for structs which have, say, an empty constructor. It’s a similar problem to Go and C++ except it’s worse in the latter two.