Latest Publications

Code You Should Not Be Writing – Part 6

I want to bring in the new year with this code that doesn’t seem all very harmful, but could be written in a more elegant way. I just hope this will educate people on some of the new functional additions to C#.

public List<int> GetListOfIntegers()
{
    List<int> list = new List<int>();
    for(int i = 0; i < 24; i++)
    {
        list.Add(i);
    }
    return list;
}

At its very core essence, this is simply creating a list of numbers from 0 to 23. However, try to find out the various possibilities of mistakes one can make with this code. I’ll leave it as an exercise of the reader to figure out all the possibilities of mistakes in this code. (side note: In fact, there was an error made in the original code. Yes, it looks simple, yet error-prone.)

Here’s a simpler and elegant way to do something like the above.

public List<int> GetListOfIntegers()
{
    Enumerable.Range(0, 24).ToList();
}

One of the interesting things with Enumerable.Range is it returns an IEnumerable. This effectively generates the numbers lazily. However in this example, in order not to change the signature of the method, ToList() is called to generate the numbers instantly, instead of lazily.

With ranges, you can create various interesting sets of numbers with Linq in a more functional way. I hope this week’s “Code You Should Not Be Writing” helps someone out there.

Change your Windows 7 ISO to any Edition

If you don’t already know, all editions of Windows 7 discs ships with the same content. The only difference is determined by a configuration file which decides which edition your Windows 7 disc or ISO is. Knowing that, there is a tool out there to change your edition to any edition, or make it a universal ISO.

The Windows 7 ISO Image Edition Switcher is a set of small binary patches (and a tool to apply these patches) that will convert an official Windows 7 ISO disc image into an official Windows 7 ISO disc image of another edition.

The ei.cfg Removal Utility is a simple tool that will remove the ei.cfg from any Windows 7 ISO disc image, thereby converting the image into a “universal disc” that will prompt the user to select an edition during setup.

For those system admins, this will be great for you. For those who tend to lose their disc or ISOs, you can now grab a friend’s copy and change the disc to the edition you want. But remember, this does not mean your CD key will work for any edition.

Source: win7utils – Windows 7 ISO Disc Image Utilities

Diagramming and Collaboration Online Tool

When I saw this tool, I thought to myself, “This is what Visio is like on the web, except better.” Cacoo is a an online diagramming tool much like what Visio offers to you, except it has better looking stencils. With the added benefit of being online, it allows you to collaborate between multiple people in real time!

Not only can it just draw simple diagrams like flowcharts, network diagrams, office layout diagrams, UML diagrams, but what I like is the freehand wireframe stencils! Check out my horrible looking UI I drew from the stencils in just a few minutes.

Test Freehand Diagram

Awesome isn’t it? Or maybe something more advanced.

Watch their video tour below.

Cacoo – Real-time Collaborative Diagramming & Design from Nulab Inc. on Vimeo.

What’s more, basic features are free! Try it out now at Cacoo.com.

Happy New Year 2010

Well it is the new year and a lot of things have happened to me in the past 1 year. Looking back at what I’ve done, I think it is wise to say there were good and bad times. Looking forward to 2010, there are a few things I do want to achieve. Here are my resolutions.

  1. Help build up the Microsoft developer community.
  2. Grow and inculcate the spirit of HackerspaceSG.
  3. Create dialogues and win-win situations between groups of people.
  4. Study and learn new things.
  5. Lose weight… LOTS OF IT.

That’s it. Yes, I’m a boring person.

So what is your new year resolution?

Code You Should Not Be Writing – Part 5

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! :)

C9 Lectures: Functional Programming Fundamentals

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

Creating Beautiful Code with Functional Languages

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#.

HackerspaceSG: Events of Week 53 (Dec 28 – Jan 3)

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.

Merry Christmas 2009

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!

DigressCast Episode 9 by Tech65

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