This is my last post of the year, and I hope to make it special by giving you a piece of code that just amazes me. Staying within the whole “new year” feel, this code is for validating a date.

string strMessage = string.Empty;
int index = 0;
bool IsInputValid = true;

string strDate = TextBox_Date.Text; // TextBox_Date is just a textbox to get the date from.
DateTime date;
if (strDate.Length == 10)
{
    int year = Int32.Parse(strDate.Substring(6, 4));
    if ((year > 1900) && (year < 3000))
    {
        string strMonth = strDate.Substring(3, 2);
        string strDay = strDate.Substring(0, 2);
        date = Convert.ToDateTime(strMonth + "-" + strDay + "-" + strDate.Substring(6, 4));
    }
    else
    {
        index++;
        strMessage += index + ". Date format(dd/mm/yyyy) is not correct.<br/>";
        IsInputValid = false;
    }
}
else
{
    index++;
    strMessage += index + ". Date format(dd/mm/yyyy) is not correct.<br/>";
    IsInputValid = false;
}

Remember the code you saw in Part 2 about the try-catch, using exceptions to do your data validation? Yes, that code surrounds this code. Imagine the double whammy I got when I saw this code, and the satisfaction of deleting it all.

I don’t know if you realise this, but do you have to take time to actually try to figure out what this developer is trying to do? As in understanding the code? How long do you take to figure out this code and what it is doing, and how flawed it is?

I hope you enjoy this edition of Code You Should Not Be Writing. Till next year, I have more to share! :)

 

Finally, all 13 chapters are done. Now I can compile them into 1 big post with all the videos. I highly recommend every developer to watch these videos even though you’ll not be writing Functional code.

Edit: I totally forgot to link back all the chapters. Click on the links on each chapter for the original page and details to download the videos.

Chapter 1

Get Microsoft Silverlight

Chapter 2

Get Microsoft Silverlight

Chapter 3

Get Microsoft Silverlight

Chapter 4

Get Microsoft Silverlight

Chapter 5

Get Microsoft Silverlight

Chapter 6

Get Microsoft Silverlight

Chapter 7

Get Microsoft Silverlight

Chapter 8

Get Microsoft Silverlight

Chapter 9

Get Microsoft Silverlight

Chapter 10

Get Microsoft Silverlight

Chapter 11

Get Microsoft Silverlight

Chapter 12

Get Microsoft Silverlight

Chapter 13

Get Microsoft Silverlight

Play
 

I encourage everyone who is still sitting on the fence about whether to learn a functional language to read this Beautiful Code – The Manifesto article written by Lau B. Jensen.

To summarize, his point of writing beautiful code essentially avoids a lot of the pitfalls you get from Imperative languages.

Beautiful Code is…

  • Concise – Free from both obvious and hidden ceremony
  • Expressive – Compartmental in its architecture, showing intent
  • Safe – Being explicit about state and time, defaulting to immutability

Of course, functional languages do all that. Therefore, functional languages create beautiful code. Trust me, you want to learn a functional language.

Try Haskell for size and read this book Real World Haskell which is a fantastic book to learn Haskell.

Or learn F# for those in the Microsoft space. I highly recommend Chris Smith‘s Programming F# book to learn F#.

 

I hope everyone had a great holidays last week. This week we don’t have any events except our usual hack time as usual on Mondays.

Hackerspace Hack Time
Mon, Dec 28 6:00 pm Tue, Dec 28 12:00 am

Our regular scheduled reserved time for our members to get anything done is back on Monday again. We currently have the following projects being worked on – Security Access System, Sucktionator, Water Rocket, Stop Motion Animation, and many other miscellaneous projects currently worked on by our members. So come join in and hack on any of your projects!

=====

Since there isn’t anything much to report, I’ll like to take this chance to write about how the events process is like.

As of this writing, this is the process of getting an event or a meetup into hackerspacesg. It will evolve over time as the place grows.

  1. Check the calendar at http://www.hackerspace.sg/calendar to see if the date and time of your event is available.
  2. Send an email to events AT hackerspace DOT sg with the date and time and details of your event. Any additional details will be much appreciated.
  3. Indicate whether if your event is open to public, or private. Indicate whether your event is free, or there’s an entrance fee.
  4. If any answers are the latter (private or paid), then there will be a need to discuss rental fees before approving. If both answers are the former (public and free), then it will go ahead to the approval process.
  5. The events coordinator for hackerspacesg will evaluate the event and gather more information if required in order to build a supporting case to host the event.
  6. The event will then be posted on both calendar and the google groups for our members to object. Silence means consent. Monitor this thread in case there are any objections.
  7. After a few days (a week maximum), if there are no objections, the event is approved. If there are, the event will be rejected based on the reasons discussed and you will be informed.

Here are some guidelines to help convince people at hackerspacesg not to object to your event. These guidelines do not indicate that the event will be approved even though it fulfils all these points, but it will help greatly.

  • The event is community focused (e.g. user groups).
  • The event is about learning, sharing, thinking out of the box, creativity, etc.
  • The event is in-line with what hackerspacesg is all about.

It might seem like a tedious process, but do not worry because the events coordinator will be doing most of the work.

 

I’m taking a short break from blogging today, but I’ll like to wish you a Merry Christmas 2009. I hope you have a great time!

 

Finally, it is out just in time for Christmas. This episode we talk about our geek gear gadgets Christmas wishes.

I hope everyone have a great holiday.

DigressCast Episode 9: Christmas Wish

 

This is a special Christmas Eve “Code You Should Not Be Writing” post that I think is special enough to flip over your chair.

This is a common mistake C# developers make, which is forgiveable. You should use string.IsNullOrEmpty() method instead, which was introduced only in .NET Framework 2.0. It is understandable that most developers haven’t gotten up to speed yet.

string duration;
// ... some code assignment for duration
if (duration == string.Empty || duration == null)
{
    // ... some error handling code
}

But this just blew my mind. Can anyone guess why this is so very wrong?

string finalTitle;
// ... some code assignment for finalTitle
if (finalTitle == string.Empty == null)
{
    // ... some error handling code
}

Yes. You should never write code like this. Heaven’s me, this is valid code! The condition is just WRONG.

Merry Christmas everyone, and I hope you like this edition of “Code You Should Not Be Writing”.

 

This is my Christmas gift exchange for DK’s Christmas Party yesterday, and it so happens that DK was lucky (or unlucky) enough to get it. Watch this video, and laugh. Laugh real hard. :)

Video by Farinelli.

 

2 weeks ago during our recording, we met up and basically dumped all our gadgets we carried on that day. Be it regularly, or review units, or whatever we had on hand at that moment. Here’s a photo of what we Tech65 own, or review. Can you guess who owns which gadget, and which gadget are review units?

DSC07625

DSC07626

DSC07627

There are 3 laptops missing from the table. 1 Macbook Pro, 1 HP Mini 1000, and Samsung N410.

 

Finished my presentation on “What’s new with .NET Framework 4.0″ last Saturday at CTU 2009v2. I hope everyone enjoyed the talk. Here are the slides and demo available for you.

CTU2009v2 – What’s new with NET Framework 4.zip

© 2009 - 2011 JustinLee.sg Suffusion theme by Sayontan Sinha
Stop SOPA!

SOPA breaks our internet freedom!
Any site can be shut down whether or not we've done anything wrong.

Stop SOPA!