Monthly Archives: January 2010

Delving into C#

This year I’ve decided to really get into C#. My .NET experience is shall at best so aiming to rectify, I picked up C# in Depth and commenced skimming!

Now, I’ve made my fair share of M$ snide asides, but I’m having a hard time coming to gripes with C#. Everything I run into either “just works” or exceeds my expectations. And the cool features are in fact, quite cool! Color me impressed!

Noob!

Noob!


For fun I rewrote a few of my Project Euler Solutions to buff up on the syntax. After I got the semi-colons and brackets all figured out, I moved on to something a little bigger.

I wanted a simple program to run and benchmark my solutions, so I wouldn’t have to do as much leg work every time I converted a problem. I figured this would be a simple enough thing to do, and it would provide a good foundation for a future gui application and beginning unit testing.

I wanted to share some particulars that I thought were pretty cool, you can grab the code I’m talking about from the google code repository, and follow along…or something.

Generics, Delegates and Lambdas
Generic Collections provide a data structure that I can access and use just like an array, but also provides methods for dealing with delegates.

Delegates are very similar to closures, blocks, procs, and lambdas like I’ve worked with in other languages, so the transition was smooth. The lambda syntax was particularly reminiscent of pythonic list comprehensions.

Thanks to delegates, I can turn this:

var matchingTypes = new List<Type>();
foreach(t in CurrentTypes) {
	if(t.IsSubclassOf(parentType) {
		matchingTypes.Add(t);
	}
}
return matchingTypes;

Into this:

return CurrentTypes.FindAll(
	delegate(Type t)
	{
		return t.IsSubclassOf(parentType);
	}
);

And finally, via lambda, to this!

return CurrentTypes.FindAll(
	t => t.IsSubclassOf(parentType)
);

Not too shabby, eh?

Reflection
Most of my programming has been in ColdFusion, JavaScript and Ruby. There’s been a little bit of this and a little bit of that peppered in there, particually C and Java while I was at UCF, but for the most part I’ve enjoyed working with dynamic and/or interpreted languages. Meta-programming is common in these types of languages, but I was surprised and impressed to read up on reflection. In this case, reflection allows me to dynamically detect and run my problems, which makes it easier (and cleaner) for me to add new solutions.

Here’s a simplified “ClassMaster” class I use to wrap my reflection calls for listing and creating classes, so you can see what I’m on about:

class ClassMaster
{
	private Assembly CurrentAssembly { get; set; }
	private List<Type> CurrentTypes { get; set; }

	public ClassMaster()
	{
		CurrentAssembly = Assembly.GetExecutingAssembly();
		CurrentTypes = new List<Type>(CurrentAssembly.GetTypes());
	}

	// should probably take arguments to pass thru...somehow
	public Object CreateClass(Type classType)
	{
		return CurrentAssembly.CreateInstance(classType.FullName);
	}

	public List<Type> getTypesByParentClass(Type parentType)
	{
		return CurrentTypes.FindAll(
			t => t.IsSubclassOf(parentType)
		);
	}
}

That’s it for now. I’ll be looking into LINQ and unit testing in the next couple weeks, and then I’m on to the gui. ASP, SilverLight, and WPF here I come!

Here are those links again:
Release
Latest Version

2010 New Years Resolutions

I didn’t make much headway with my formal resolutions last year.

  • I went to a few user group meetings at the beginning, but I trailed off rather quickly.
  • I didn’t contribute ANYTHING to open-source.
  • I didn’t complete any money making projects.
  • And aside from playing around with a few GreaseMonkey scripts I didn’t write any plugins.

However, I did manage to do a few other things in 2009:

And I saved the best for last…

Sara!

Sara!

2009 was the year that I met and engaged the love of my life, Sara!

In short, 2009: Best year ever!

Now, on to this year’s resolutions!

Blog More!

Blog More!


Blog More!
I’ve always done a lot of programming outside of work, but I’ve found that blogging incentivizes me to actually (somewhat and sometimes) finish what I start. I’m much more likely to finish something when I plan on, or start to blog about it and I feel that the extra little nudge can make a big difference.

Unfortunately, I have half a dozen unfinished Flex projects to NOT show for my lack of blogging this year, but I hope to get back on track in 2010.

C#!

C#!

C#!
In addition to my 9-5 ColdFusion and JavaScript programming, the last couple years I’ve spent most of my free time in Ruby and ActionScript. This year I wanted to get more into general, gui type programming. It’s been a long time since I wrote a windows application, and my time spent with the Flex compiler has got me feeling nostalgic for a more structured language and programming environment.

I’ve spent a little bit of time over the holidays on a few C# projects, and I’m loving it and I’m looking forward to really diving into C# this year!

Attend User Group Meetings!

Attend User Group Meetings!

Attend User Group Meetings!
I say this every year, but there are a few active user groups in Orlando that I really like, that I should be attending more frequently and consistently.

Here’s a list, for link-love’s sake:

  1. ADOGO
  2. OJUG
  3. ONETUG
  4. ORUG

I figure I should be able to, no excuse, make at least one a month. AT LEAST!

Work Out!

Work Out!


Work Out!
This is another resolution that I make every year. I didn’t lose any weight in 2009, in fact I gained 5lbs. However I’m lifting a lot more weight now, and I feel healthier so I guess I’m doing something right. I plan on continuing this through 2010.

So that’s it for tonight folks, I’m off to bed.

Happy New Year!