Read the the rest of Peter Norvig’s article here on his site.
Read the the rest of Peter Norvig’s article here on his site.
بحث سینا و مهرداد در کامنتهای این پست سینا من را یاد این نوشته Bruce Eckel درباره Exception Handling در Java انداخت، به خصوص این بخشش:
The theory is that if the compiler forces the programmer to either handle the exception or pass it on in an exception specification, then the programmer’s attention will always be brought back to the possibility of errors and they will thus properly take care of them.
I think the problem is that this is an untested assumption we’re making as language designers that falls into the field of psychology. My theory is that when someone is trying to do something and you are constantly prodding them with annoyances, they will use the quickest device available to make those annoyances go away so they can get their thing done, perhaps assuming they’ll go back and take out the device later. I discovered I had done this in the first edition of Thinking in Java:
try{
...
} catch (SomeKindOfException e) {}
And then more or less forgot it until the rewrite. How many people thought this was a good example and followed it? I began seeing the same kind of code, and realized people were stubbing out exceptions and then they were disappearing. The overhead of checked exceptions was having the opposite effect of what was intended, something that can happen when you experiment (and I now believe that checked exception were an experiment based on what someone thought was a good idea, and which I believed was a good idea until recently).