Chris McGrath’s Blog

Just another Developer’s Blog

Archive for April 2009

How I’m learning python.

leave a comment »

As object-orientated programmers we like to think that we can pick up a new o-o language and run with it. And this is mostly true. However this can lead us to play with a language for 10 minutes with no direction and proclaim ourselves experts in the langauge. This I have a problem with. Such an exercise just handles very simple situations and doesn’t let us get familar with the quirks and features that makes a language unique.

The only way to do this is by playing around with a language but to have direction – to have a problem to solve. For python I’ve found a great domain to play in – XBMC plugins. I’ve mentioned XBMC before but one great thing about it is its support for plugins through python.

So what type of plugin should you make? Well the obvious one – a plugin to grab videos off sites and play them in XBMC. Why? well because there a heaps of examples to play around with yet a lot of sites are unique enough to not make it simply a copy and paste job.

I’ve decided to make one to view videos from the ABC Australia website – http://www.abc.net.au/tv/. I’ll post updates on how the progress goes.

Written by Chris McGrath

April 30, 2009 at 5:52 pm

Posted in Blog

Tagged with ,

Don’t reuse the class name in a property name.

leave a comment »

Seriously this is something that always annoys me. It make the code…

  • Less readable – I can’t see how anyone can argue person.PersonName reads nicer than person.Name.
  • Less consistent – unless you put the class name in front of every property.
  • Harder to search – Best Example is on WinForm’s Form. So many times It has taken me forever to find the Form’s Border Style. Why? Because I look under B and they called it FormBorderStyle.

The biggest offenders seem to be ID properties. I think it’s because in a database the standard seems to be to call IDs ‘PersonID’ or ‘EmployeeID’ and that’s fine – just don’t blindly copy it across to the object definition.

Written by Chris McGrath

April 28, 2009 at 5:32 pm

Posted in Blog

Tagged with ,

The Best Comments Encounted in Source Code

leave a comment »

Yesterday I came across this thread on Stack Overflow – http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered.

It’s a fun thread to read which will make most developers laugh out loud (litterally, not make them type “lol”). There is one comment in the thread which is quite insightful…

It speaks volume about our profession that when asked about the “best comment”, we all answer with the worst comments we can find

More importantly I think it speaks volumes about the art of commenting itself.

Now when we were originally taught how to code our teachers told us we should comment EVERYTHING. They almost expected us to write comments like this one from the thread…

return 1; # returns 1

which is useless, in fact it’s counter-productive. Not only does it take extra time you’re filling your code with junk making it harder to read.

It is also redundant, which means the comment may not always reflect what the code does. Again from the thread…

/**
 * Always returns true.
 */
public boolean isAvailable() {
    return false;
}

So comments can also be misleading.

So why are we taught like this? This isn’t just a problem with secondary school subjects. I was recently helping a friend with a university assignment (about a second year subject) and in the marking sheet gives a fair few marks for “masses of comments.” Ignoring the horrible terminology (it also had to “cite literary sources” for web design ideas and when I had this lecture for a subject he said our code should “read like a book”), it tells me they do it because it’s easy. Every third line is a comment? Good, Full marks, instead of actually seeing if the comments add anything.

So what’s the solution? Don’t use comments to define your code – use your Unit Tests. Not only do they show what the method is expected to do but you can check to see if the code follows the test. Most of the time if you need to write a comment, what you really need is to refactor your code to make it explain itself.

But do comments have a use? Yes. They should be used to explain not what it does but why it does it – why one algorithm was chosen over another.

Written by Chris McGrath

April 27, 2009 at 6:43 pm

Posted in Blog

Tagged with

Can we stop using the term “Next-Gen”?

leave a comment »

Why are people still refering to Xbox 360, PS3 and Wii as “Next Gen”? Each console has been out for over 2 years.

And it’s not just the consoles which use this term, Apple are saying their computers have “Next-generation Intel processor”.

Let’s get back to basics and refer to “Next-Gen” for stuff that has not come out. If it is out, it’s current gen. If “current” isn’t exciting enough for your advertisements use “new” or “latest”.

Written by Chris McGrath

April 21, 2009 at 4:16 pm

Posted in Blog

Tagged with ,

dotNet Tip: Path.Combine

leave a comment »

A long time ago when I was new to the dotNet framework I was doing a fair bit of File IO. The thing that annoyed me most was checking if a path ended with a slash before appending something to the end. I then found out about

System.IO.Path.Combine(path1, path2);

I’m just doing a bit of IO at the moment and I’m so glad I remembered this. It turns

string path = WindowsDir;
if (!path.EndsWith(‘\\’)) path += “\\”;
path += “Help”;

To simply

string path = Path.Combine(WindowsDir, “Help”);

Written by Chris McGrath

April 20, 2009 at 6:20 pm

Posted in Blog

Tagged with ,

CSLA .NET for Silverlight video series

leave a comment »

Rocky Lhotka has just release the first of his training videos for CSLA.NET for silverlight. You can currently buy all the videos (including the ones still to be released) for $200. After this offer is up it will be $300 so I’d take advantage of the offer.

http://store.lhotka.net/desktopmodules/catalookstore/ProductDetails.aspx?ProductID=6

Written by Chris McGrath

April 20, 2009 at 2:39 pm

Posted in Blog

Tagged with ,

Prison Break

leave a comment »

Just finished rewatching the first season of Prison Break. What a great season it is.

The following seasons had quite a variance in quality. I thought season 2 started out strong and was as good as the first season. But about halfway through it lost direction and the rest of the season was the worst episodes of the show. Season 3 and 4 (so far) are interesting but require you to accept some pretty ridiculous  things.

But back to season 1. One thing about the first season is it easily the most graphic. This instantly means it’s not for everyone. I was wondering how popular it would be because of this, but most people were able to handle it and made it the success it was.

One thing I really noticed this time was how the portay the death penality. Some people might look at it in a simple light of, “what if the man is innocent?” but it goes so far beyond that. It shows it as the humiliation, creulty and barbarism of it. It goes as far as showing how it hurts and humiliates their loved ones. In fact it shows that they are the ones that get hurt the most. In this case the man is innocent, but what it shows makes you think that even the guilty don’t deserve it and the families definately don’t.

To clarify, I have always been against the death penalty and am proud to live in a country without it.

I am glad Prison Break is ending soon. Although I still find it quite enjoyable I think the show has suffered from trying to keep it going. During the first season I thought it was only going to be one season. This would have given the show what a lot of shows don’t have – direction. Stories are best told when they have a start and an end and everything in between moves you in the direction of the end. I think this is why 24 is such a great show – It continues to move the plot forward but when the day ends the threat is over and all important story lines are finished. Yet it has reason to bring the characters back for another story.

For Prison Break to do this would involve cutting back story lines that couldn’t be finished within the first season. And that’s pretty much the conspiracy. See if they broke the conspiracy and brought they people responsable to justice, there would be no need to break out of prison. So I think the conspiracy should have been shown as an unknown force and enough shown to prove that Lincoln was innocent and it wasn’t worth trying to take them down. The season would then just be the prison break and end with them escaped in Mexico.

Written by Chris McGrath

April 19, 2009 at 9:07 pm

Posted in Blog

Tagged with