Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that they clutter interfaces, encourage exception swallowing, etc. It seems to me like null inhabiting every type is a way around the language - like I want the type of this to be X, but it's actually X or null; it just doesn't look like that and is easy to forget. Don't checked exceptions provide a way for the type of something to be X or throws Exception instead of it appearing to just be X? It provides an in-code way to specify how something can fail.

Nulls in every type and unchecked exceptions seem like they are dual concepts, but one is scorned and the other praised. Why is that?

share|improve this question

1 Answer

Most people who scorn NULLs have never actually written in a language without them. People who scorn checked exceptions have written in a language with them. People have seen the downsides of checked exceptions much more then the downsides of NULL-less programming. Popular languages have used checked exceptions, but no popular language has gotten rid of NULLs.

Both of these idea are trying to prove some notion correctness in a program. In my view, that sounds like a good idea in theory but tends to fall apart in practice. The effort and restrictions placed on your attempts to prove correctness are generally not worth the benefits of the limited amount of correctness being proved.

Many specific criticisms of checked exceptions exist. I'm not going to repeat them all here, I'm sure that's been done to death. NULL may not have the same issues show up. However, the lack of widespread NULL-less programming may mean that we simply haven't had time to see them. Or perhaps checked exceptions simply produce more problems then NULL-less programming does.

share|improve this answer
4  
As somebody who has used Java (the only language with checked exceptions I know), I hate checked exceptions. So do some of the best Java developers I have ever met; they even wrote their own Java-like language without them (Gosu). I have also used a language without nulls (Haskell) and it is awesome. – Tikhon Jelvis Jan 14 '12 at 1:04
I dunno what I would do without nulls but I definitely have been happy without checked exceptions. Definitely have their purpose in certain environments. – Rig Jan 14 '12 at 1:12
@TikhonJelvis, I don't doubt it. I just suspect that's not the category most people find themselves in. – Winston Ewert Jan 14 '12 at 1:24
1  
@WinstonEwert You say I'm going to repeat them all here. Aren't you mising a not in that sentence? – PersonalNexus Jan 14 '12 at 3:22
@PersonalNexus, thanks – Winston Ewert Jan 14 '12 at 3:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.