Sunday, November 30, 2008

Some ramblings on basic Exception Handling

I'd like to show two examples of really bad Exception Handling which I came across the last months.

Example 1

Try{
Foo();
}catch(Exception ex)
{
}

Please don't ever do this. It makes your software a pain in the ass to debug. The user, your co-developers and yourself will have to waste a lot of time finding the reason of some unexpected behaviour (= a bug).

Example 2

Try{
Foo();
}catch(Exception ex)
{
LabelErrorMessage.Text = "Some error occured".
LabelErrorMessage.Visible = true;
}

I agree, you can't just give the user an ex.ToString(). But this errormessage really sucks.

You should try to give the user a meaningful errormessage.
For example: This action went wrong. Here a few reasons why this might have happened. Please contact us and tell us what you were doing when it went wrong. We will try to fix it.

Or even better, use logging in the background. I have some experience with log4net and I think it's a really good system. You can show the user a non-nerdy error message and log all the nerdy stuff in the background to a database or textfile.

Saturday, November 22, 2008

Interview with Ecbruck

Ecbruck is Microsoft MVP and is a respected admin of forums.asp.net. He is known for his high quality replies/solutions. So I thought it might be intresting to have a chat with him!

Me: Who are you? Where do you work? On what project are you working?
Ecbruck: My name is Ed Bruck. I live in Des Moines, IA, and currently work as a contractor for the Pioneer HyBred company. During the past year, I've been working on a 3.5 .Net Windows application which is to replace an existing financial system for the company. This is long-term Windows project slated through next Fall, and it may be a while before I get back to good old Web development.
As a member of a dozen or so developers, I am charged with working on one primary function of the application. This includes all front-end, back-end, and middle-tier work required to complete the task.

Me: The good old Web development? How long have you been programming and what other technologies have you been into? Next to a windows application and asp.net webapplications?
What is the primary function you are working on? And can you tell me what you understand under front-end, back-end an middle-tier? The winform, the database, and your DAL and BLL?

Ecbruck: My true passion is definetely web development so I really want to get back to it at some point. That's why I stay so active on this forum so I don't lose my focus. I've been an active .Net programmer since the first Beta came out somewhere in 2001. Before that, I was an ASP developer. I won an HTML class back in the late 90's by sinking a putt during a job fair. I guess that's what really started it all as I was so intrigued about the web. Unlike a lot of other developers, most of my programming and research is done on the job only because I try to seperate my work and personal life.
My primary function right now would be building up a services architecture for our application. When I say front-end, I refer to building forms, grids, etc... Or DAL is quite extensive and is broken up into many pieces as we are utilizing a services architecture which rely hevily on the use of Linq and the EnterpriseLibrary. The BLL would encompass all of our business rules, validation, etc... We utilize the DevExpress tools for our front end, and are currently hooked up to a Sql Server 2005 database.

Me: How do you use the Enterprise Library? Is it just a set of best-practices everyone who is working on the project tries to follow? You also said you are using Linq, but does the Enterprise Library already supports guidance for Linqs?
How do you use Linq in your DAL? How do your functions look like? Are you sending strings and integers as your parameters, or are you using data transer objects? What are you returning?
You also said that you try to seperate your work and personal life. Isn't programming kind of a hobby? Do you do nothing at all at home what involves programming (like reading forums, ...)

Ecbruck: We use the EnterpriseLibrary for security, logging, validation and dependency injection. I would say that we use the library as more a set of tools which we have used to build the foundation of our system. We used to use LinqToSql in our application via the DAL, but ran into many problems with regards to the Context. Therefore, we switched to writing our own Table mapping files and load our tables directly with Linq. Most everything in our system is object-based, therefore most of our DAL methods ONLY accept objects. We however may or may not return objects depending on the need.
I think about programming problems at home, but I usually don't write any code at home. If I get up early enough on the weekend, sometimes I'll pop into the Forums to do some moderating or answers some questions, but any code I write would come off the top of my head. What I usually do is come in early to work to put in some extra time devoted just to the Forum.

Me: Can you give some examples of issues with the Context?If you only use objects in your DAL, where do you store their classes? Do you store the classes in an extra DTO layer? Are you creating a different project for each layer?
Ecbruck: The primary problem with contexts is that if you aren't always working with the same instance of the context you can end up with a variety of errors when attempting to insert or update an entity.
Our objects are primarly stored within a Models project. Our solution consists of around 60 individual projects. We have individual projects for each primary function in our system, and within that function we have a seperate project for the UI, tests, and another for any function related classes. It's quite a solution.

Me: To flip the conversation around a bit. A lot of stuff is happening in the .NET web developement area. We've got MVC, ADO.NET dataservices, Ajax, Silverlight.. which is all relatively new.
What are your opinions on these technologies?  And how do you think a developer should deal with all these new technologies? It's hard to keep-up-to date with everything and it is impossible to master all of these. Should a developer just focus on the stuff he needs everyday or is it important to keep your interests wide?

Ecbruck: I've used just enough AJAX to be dangerous, although I haven't yet dabbled into MVC or Silverlight. Since I'm a Contractor, my position is that if the company wants me to use Slverlight, then I'll learn it at their expense. Otherwise, I pretty much stick to the basics and expand only when needed. Now if a new Framework should come out, then I'll jump all over that. Now of course this is just me. If you are just learning, then I'd at least know a little about each as this will make more well-rounded.

Me: You are a Microsoft MVP. What does that mean exactly? What are the benefits you are getting? What are the responsibilities you have?
Ecbruck: The MVP is an award that is given to certain individuals who voluntarily share their real world expertise with the community. It's an award that you can only be nominated for by your peers. Besides a certificate, we get complimentary subscriptions to MSDN or TechNet, access to MVP private newsgroups, and technical support incidents. There's also a few bucks to spend at the company store. In addition, we are all invited to Microsoft each spring for the MVP Global Summit where we get to interact directly with our product groups. Because MVP status is awarded based on past contributions, Microsoft has no expectations of MVPs beyond the expectations of courtesy, professionalism, code of conduct, and adherence to the community rules that are asked of all Microsoft community members.

Me: To wrap up this interview. Which is in your opinion the best Microsoft product and which is the worst?
Ecbruck: That's a tough question. I'd have to say I'm very impressed by Linq and LinqToSql. These two have saved me so much code and time and are a great addition to any Developer's toolbox. As far as worst goes, I don't really have just one. Each product has its own flaws which I usually run accross at one time or another. However, I know too that testing any product too thoroughly is never enough.

Thanks alot for the interview. It was very intresting!

Monday, November 17, 2008

History of my Frankenstein pc

This week I decided to buy a new pc, because my old one was randomly resetting, was really out-of-date and because I deserved it :D.
My old pc had turned into a Frankenstein pc over the years, that's why I decided to write a little summary of the modifications I did to it over the years.



1) My new pc only had a 40GB harddrive, which wasn't that big of a problem at first. I didn't have internet at the time! But once my parents got me a broadband internet connection, I was running out of space pretty fast. So I bought a new 200GB harddrive.
2) After installing my new harddrive, I started monitoring my harddrives' health and came to the conclucsion that the harddrives were producing to much heat, so I added the fans. I had to cut a piece out of my case, to give the fans some fresh air.
3) After a year, it was time to add some RAM, so I added 256MB of RAM, which gave me a whooping 0.5GB of RAM!
4) At the time I started playing Counterstrike 1.6 with my schoolbuddies and my VGA couldn't get a stable 100fps in a smoke, so I bought a new VGA from a friend.
5) Now that I added the extra RAM and a new VGA, my pc wasn't stable anymore when gaming, so I needed to add some fans. Fan number 5 was supposed to suck some fresh air into the case.
6) And fan number 6 was there to keep the VGA cool(er).

I'm in love with my new pc . I'm not into hardware, so I asked a friend of mine who works in the local PC store to make an offer.

He came up with a pretty awesome configuration for the price of €666 (number of the beast obv):
1) Motherboard: G112 GIGABYTE GA-MA770-DS3 AMD AM2+ ATX DDR2 1066 S/GBL
2) CPU: AMD PHENOM AM2+ QUAD CORE X4 9850 2.5GHZ 4MB BOX
3) RAM: 2x DDR2 APACER 2GB PC6400/800 LFT CL5.0
4) VGA: G44 GIGABYTE GF 9600 GT 512MB GDDR3 PCI-E TV-O/DUAL DVI SP
5) Harddrive: 500GB Sata

I now have my new pc for 2 days, and it is really awesome. I wasn't used to be able to play cool games anymore and forgot how much fun they can be. I installed GTR Evolutions (I'm a huge fan of race sims) and I installed Far Cry 2. I'm able to play Farcry 2 at high quality and the graphics and the gameplay are just amazing.

If there are other cools games I should play please let me know. Or if you have your own Frankenstein story to tell, I would be happy to publish it here!

Saturday, November 8, 2008

Cheating on Google Adsense?

I was thinking about the Google Adsense concept and architecture.. I don't think Google Adsense can be really that hard to cheat on.

What are the things Google can check?
1. The ip-address of the computer sending the http request (clicking the link).
2. The time between the http requests (the clicks).

How to cheat Google Adsense?
I think a simple program that would do following steps in a loop with a variable time interval would do the trick:
1. Change your ip - address to the outside world.
2. Send a http request to one of the ads (click the button).

My experience?
I wrote a small program which sends http requests in a loop with a variable interval time to the ads without changing my ip address after every request, because my ISP does not allow me to change my IP address that often. And the day after I send 8 http requests to the ads using the same ip address I received an e-mail from Google warning me for invalid clicks.

Ethics?
I tried this just for fun and would never think about really cheating Google Adsense. Just because it isn't Google you are stealing from. You are stealing from the companies who are paying to display their ads!


EDIT You should also not forget to send a http request to your page displaying the ad. They will be comparing the number of unique page views to the number of ad clicks as well!

Wednesday, November 5, 2008

Two powertools: Xobni and Notepad++

I installed two new tools these week which are really cool and I want to share with my readers.

Notepad++

Just think of it as a super powerful notepad. The list of features is just to long to sum up here. So take a look here!

Xobni

This is an outlook plug-in which makes searching for stuff so much easier. Xobni creates an information profile for each person you interact with, and surfaces historical information that is relevant to what you are working on. It shows contact information, conversations, attachments, related people, statistics... And it does all of this very fast!

Download it here!