Peace For All

June 4, 2006

Why Checked Exceptions are a Good Thing(tm)

Filed under: C#, Programming, technology — Devlin Bentley @ 2:13 am

I am playing around with C#.  Win32/C# class and all that.

I am opening a Graphics file.   A dialog pops up, the user selects a file.  If the user hits OK, I construct a new Bitmap using the file.

That latter bit is copied straight from the MSDN article on the same topic.

Now I <i>now</i> that this is wrong.  All the user has to do is select an invalid file type and exceptions will get thrown all to heck.  They won't be CRITICAL exceptions mind you, not for this simple application, but the application will keep on functioning, assuming that a valid file has been opened.

This is stupid.  Why the hell can't the compiler say "Hey, Devlin, by the way, that constructor there can throw an exception."

I know it can.  Do I want to go and dig through MSDN finding the exact exception name?  Not really.  For whatever reason, IntelliSense is not popping up a list of exceptions that can be thrown by the Bitmap constructor.

What do i want to happen?  I want to hit a hot key, have basic exception handling code thrown up for me, and then go in there and customize the handling.

Yah, sure, I just turned in 30 pages of Java code for class on Friday, and yah, sure, I would estimate that about 8 to 10 pages of that (at least!) is exception handling.  This is because I went about and handled my exceptions <i>properly</i> (informing the user which of their actions is causing a problem and how to remedy the problem, for instance), and got some good information pushed out for myself, the developer, as well at the same time.

And yes, a lot fo that execption handling code is for situations that I <i>personally</i> know will never happen.  Invalid IO exceptions in case arguments passed into a constructor are invalid, in cases where I had just created the object that was being passed in, so I <i>knew</i> that it was valid.

Yah well, I still feel more comfortable handling <b>extra</b> exceptions than not handling <b>enough</b> exceptions.  Requiring the programmer to explicitly break their stride and go in too add every single exception that could happen is just ludicrius.  Especially when the IDE can do it for me!

I am sure that there is some button in Visual Studio to do exactly this, but why shouldn't the compiler bug me if I haven't hit it yet?  Worst case worst, I hit compile and ship the software out the door, and <i>it breaks with ease</i>

The cost benefit trade off of checked exceptions is minimal.  Visual annoyance in return for more stable code.

Finally, I must say this.  It requires discipline to properly catch checked exceptions.  But I believe that it requires even more discipline to catch unchecked exceptions.

June 3, 2006

What I had for breakfast today

Filed under: Life in general — Devlin Bentley @ 5:50 pm

Home made potato pancakes with added sausage.  I was all out of white onion so I had to use purple onion instead.  I just finished off the last one, they actually tasted a lot better a few hours after I made them, as the onion's flavor had time to spread out a bit.

Either way, delicious and simple.  They would be even simplier to make, but my cooking skills are so bad that it took me 10 or so minutes to get all the ingrediates out and ready, 20 minutes to dice the onions, and another 20 or so to mix up the flour and eggs.

Oh well, tasted good at least!  🙂 

May 30, 2006

Ranting about Web Design and WP templates

Filed under: technology — Devlin Bentley @ 2:47 pm

I take issue to people who use fixed size, well, anything. Fixed sized fonts are my biggest complaint (especially when they are set at 2 pixels or so…).

Now I realize that XHTML and CSS are not the best tools to work with. Indeed, just trying to get any two elements to line up <i>and</i> have the same height can be a daunting task, but widths…

Widths people, are easy. Instead of going <tt>width: 800px;</tt> and then centering the page, you go <tt>margin-left: 25%; margin-right: 25%;</tt> and be done with it.

Yes I know that then you have to size everything else relative, but honestly, is making your make both usable AND future-proof(ish) really that bad? (yes it is that /hard/, but the end result is something that you can be proud of)

Either most WP themes use absolute widths, or they just set the margins to something stupid like 40% on each side. I have yet to figure out which bit of stupidity it is exactly.

Oh, kudos[1] to the web designers from taking a page out of the programmer’s handbook and instead of making configuration options, just saying “edit the source”.

[1]Sarcasm.

Blog at WordPress.com.