Event Extension Methods

by Khalid Abuhakmeh 6. January 2009 10:41

I'm sure I'm not the first to write these extension methods, and if I am I would be amazed. Here is a small static class to make the invoking of events more readable. When you invoke an event, the code might look like the following.

if (OnCreation != null)
OnCreation.Invoke(sender,e);

I reduced it to an extenstion method that looks something like this.

// No sender or event arguments
OnCreation.IsNotNullThenInvoke();
// Only with sender
OnCreation.IsNotNullThenInvoke(this);
// With sender and event arguments
OnCreation.IsNotNullThenInvoke(this, e);

And here is the code.

public static class EventExtensionMethods
{
public static void IsNotNullThenInvoke(this EventHandler target)
{
target.IsNotNullThenInvoke(null,EventArgs.Empty);
}
public static void IsNotNullThenInvoke(this EventHandler target, object sender)
{
target.IsNotNullThenInvoke(sender,EventArgs.Empty);
}
public static void IsNotNullThenInvoke(this EventHandler target, 
object sender, EventArgs e)
{
if (target != null)
target.Invoke(sender,e);
}
}

There you have it, a single method that extends events. Less code, makes your code easier to read. Hope this helps.

Note: There is no validation on the arguments being passed to the extension methods, this means you could pass in null arguments. In terms of events, I feel this is ok.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code | Code Review | General

Games of Chance - Slot Machine

by Khalid Abuhakmeh 4. January 2009 22:35

Monster PokerI went to Atlantic City over the holiday season, and I played a bunch of different games from Let It Ride to Black Jack. The one game I was intrigued by the most was the slot machines, not because of the flashing lights but how much they lend themselves to the new technologies Microsoft is putting out. If you haven't stepped into a Casino in a long time, then I suggest you do and just think about the technology that is around you. All the slot machines are networked and now are mostly flashy video games. This got me thinking about WPF and how it would lend itself perfectly to a game like a slot machine. Also technologies like WCF make it easy to network such a game. So I started writing a game engine for a slot machine, I don't know if it is how professional slot machines are written, but I think I have a very good start.

MonstersGotMy.Games.zip (790.43 kb)

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code | Code Review

Merry Christmas, Hanukkah, Kwanza, and Holidays in General

by Khalid Abuhakmeh 24. December 2008 18:00
Well tomorrow is Christmas and I'm excited about the upcoming new year. I have some goals to achieve next year and will hit the ground running as soon as the clock hits 12:00:01 on January 1st. I can't believe it's been five months since I started this blog. I didn't know what it would do for me or how it would help. The reality is, that this blog has made me a better developer and critical thinker. It also makes me appreciate the better parts of development. There have been times where I questioned my love of programming, but the online community always reminds me that there are people just as passionate as me. I am also grateful to the people who actually read my ramblings (even if you don't agree). Thank you reader and friends and have a Happy Holiday.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General | Rants

My BFF - Regular Expression Quick Replace

by Khalid Abuhakmeh 24. December 2008 11:27

Killer NerdRecently I fell into some VB6 code that I had to convert over to C#. At this point, I am convinced that VB stands for Very Bad. Oh the humanity, I have never had to develop anything that was so draining, and I've programmed compilers in the past. It is amazing to see the leaps and bounds in C# .NET as compared to VB6; it is a paradigm shift I'm glad happened. This code just wasn't VB6 code, it was terrible code.

This code was the kind of code that makes you curse the original developer. Why would somebody make a method 3000 lines long? It was like looking into an abyss of never ending if statements. A fellow programmer printed an image of a handgun and slid it on my desk as he said "here's an out." Luckily VS2008 can read VB6 projects, and I was able to convert from VB6 to VB.NET, followed by a VB.NET to C# conversion. It wasn't perfect, but it was a good start. That's when the real fun started.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code | General | Rants | Warnings

Supercharged Browsing

by Khalid Abuhakmeh 24. December 2008 09:08

Grandpa Munster - Creator of the DragulaEver since I started using Firefox, I've fallen in love with extensions. Firefox is the perfect browser for developers because it gives you so much in terms of productivity extensions. You have your standard extensions like Web Developer and FireBug, but there is a clear winner in my opinion; the one extension I use more than any other is Easy DragToGo. Easy DragToGo lets you drag links, images, or even text and open it up in another tab in Firefox. I love using it on social news sites like Digg and DotNetKicks because it lets me pick out the articles I want to read at one time. Once I have selected the stories I want to read, I can close them down one by one after I'm done reading. It is also helpful when someone puts a link on a page that isn't hyperlinked. You can highlight the web address and drag. The extension is smart enough to know it is an address and go there. You can also drag words and the extension will do a google search on it. A note of caution though, it takes some getting used to, so give yourself a little while to adjust. Go supercharge your surfing power with this extension; once you do, the Internet will never be the same.

Grandpa Munster's Dragula
Get it? Easy DragToGo.... Dragula....?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

General | Products

Picking the Perfect Project Name

by Khalid Abuhakmeh 23. December 2008 19:46

Man With The Screaming Brain During the last days of Campus Door (Lehman Brothers), I was involved in a project to aggregate all the systems into a service oriented architecture. It used the latest in .NET technology at the time and I was happy with the developers on my team and our progress, but not so much with anything else. The management was clueless about the direction of the project. They decided to put their cobra clutch grip of death on the project, and named the project without the input of the developers. The name they came up with was "Cloud." Wow, what a terrible name for a project. Every time the developers would get in a room, we would laugh at the absurdity of naming a project Cloud. Soon the project began going down hill, the management wanted the project to BE like a cloud. What the hell does that mean? You could read into it a million ways, soon this generic name became the biggest hurdle for the project. Our clients had expectations of what a cloud was, and we had written a system that wasn't what they expected. As usual, the blame game started and the blame was traded like pokemon cards amongst the managers. As developers, we started calling it something else to remove the stigma of Cloud; and soon the project was back on track (once our management got out of the way). This story has a point, it is critical that you pick a good name for your project. A bad name could spell disaster before you write a single line of code. I will give examples of what are good names and what are bad names (cloud obviously falls into the bad category).This is all my opinion, so don't scream at me for my choices.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Rants

Azure does not mean sloppy

by Khalid Abuhakmeh 22. December 2008 22:16

The FogI am really excited about Windows Azure and the prospect of creating applications with no boundaries: limitless memory, space, and speed. It's exciting to know that millions of people could use my application with each user getting the same great experience. Well millions of users might be a little optimistic, but a developer can dream can't he? Well I was going through the labs included with Azure and although it was exciting to be working with a new technology I felt I was betraying what I had learned through out my carreer. All the examples in the Azure SDK are very tightly coupled to Azure. When you look at the code, it is immediately apparent that it is a cloud application. All I could think is "this is kind of gross." It is not as seamless as Microsoft would want you to think, not straight out of the box anyways. In this post I'll show how I decided to abstract away the RoleManager class in Windows Azure. The RoleManager manages your application role (wow, not very descriptive). Let me try again, it is the configuration of your cloud application (that's better). I'll show you my issue with Azure and then how I decided to tackle it.

AzureExample.zip (609.65 kb) (Must Have Azure SDK installed)

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Code | Code Review | Warnings

ASP.NET MVC Web Unit Test Runner

by Khalid Abuhakmeh 21. December 2008 20:00

Videodrome - long live the new flesh

Question about videodrome: what the hell was that movie about? I liked it, but was left with some questions. Anyways.

 

After my last post about Oxite, I felt that just pointing out the negatives was not overly constructive. Oxite is a great idea and now that Rob Conery is helping the team, I am sure it will move in the right direction. He might have to drop a couple of DDD (Domain Driven Design) elbows on some of that code to get his point across. In an effort to add something to the online community, I decided that an example in ASP.NET MVC would probably be a good thing. What you are about to see is an ASP.NET MVC Unit Test Runner, it is still alpha and is meant purely as an example. There are things that could be improved upon, and features that would make for a more robust application but this is a good start. Enough Jibber Jabber, let's get to the idea and the code.

The Crazy Idea

So why would you want to have unit tests run in a web environment/ web applicatoin? The idea came to me when I was working on a project at work. I said to myself "the unit tests I write are very helpful to me, wouldn't they be equally as helpful to my client?" If my clients application would begin crashing, they would be given a great ability to help me debug the issue (if one should arise). Let's talk through a scenario. Client calls up and says, "Hey my application is acting weird?", I say "OK, can you log into the admin and run the diagnostics (unit tests)?" The client runs the tests and tells me "Hey! three failed; diagnostic tests x,y,z" Perfect, those are the integration tests related to the third party web service. "Sir, call vendor X; thier service is down." This is one scenario, but the idea of unit tests is greatly applicable to many. Excited about the prospect? Well let's look at the code.

WebTestRunner.zip (2.14 mb) (kinda large because of included assemblies)

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Code | Code Review

Oxite Sorta Smells

by Khalid Abuhakmeh 14. December 2008 20:28

Attack of the Killer TomatoesSo Microsoft just released a sample MVC project for all developers to aid in groking ASP.NET MVC. At the same time I am in the efforts of helping my younger brother start a new business, and I am looking for a platform that he can use to create some sort of web presence. So I was really excited to see that Microsoft just released something for developers to sink their teeth into. Oxite is a new blog engine/content management system built on top of ASP.NET MVC. The fact that is is ASP.NET MVC is a definite plus because this lets me consult the services of actual designers. I can put down the pen tool in Photoshop, for now. The designers can be tasked with creating beautiful HTML designs, while I focus on extending Oxite for the needs of my younger brother. Upon further inspection of the product, it seems like an OK start to a project, but some things smell; from a developer's viewpoint and a user viewpoint. I'll first explain the concerning parts from a developer viewpoint, followed by the user viewpoint.

Note : I realize this is alpha, so I am still very excited to see what comes next, but I wouldn't use it as it is right now.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code Review | General

Development Lexicon - Frankenstein Effect

by Khalid Abuhakmeh 14. December 2008 19:27

FrankensteinFrankenstein Effect :

When ever you sit down to start a new project, best intentions are always in mind. Everyone involved is energized to get started and is enthusiastic in what the future holds for the project. The start of the project turns out to be the high point and by then end you are left with a The Hoffsolution that nobody is happy with. I call this progression of events the Frankenstein Effect. When Dr. Frankenstein set out to create a being, he wanted to create something greater than anything in existense. Think David Hasselhoff. As Dr. Frankenstein progressed with his idea, he began comprimising by using the rotting limbs of corpses. By the time he was done, he had created a monster. He wanted nothing to do with his creature and it ended up destroying his life.

The Frankenstein Effect is common when communication breaks down in teams. The breakdown can be blamed on many things: bad management, personal conflict, or varying expertise. Every situation is different, so be careful. You might end up with a project that you want to chase down with a pitch fork, torch, and angry mob.

Use:

New Management : "Hey guys, we are going to try to tackle project-x again. The last attempt was plagued by the Frankenstein effect, so we had to dump it and start from scratch."

Developers : (underbreath) "Thank God..."

Thanks Andrew (this one was his idea).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Lexicon

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

A Little Narcissism

I am a .NET developer mainly focused on Web development and enterprise applications. I strive to keep my skills at their best and always looking to absorb that much more knowledge. I am learning new things like Windows Workflow Foundation, LINQ, Ruby on Rails, WPF, ASP.NET MVC, and anything else thrown at me; I say bring it on!

RecentComments

Comment RSS