Buat Apa Yang Kau Buat
Tiba satu ketika,
Kau mahu berhenti,
Buat apa yang kau buat.
Dan tulis puisi sepanjang hari.
Kau mahu tulis pasal bunga,
Yang mekar di pagi April,
Basah dan biru dijirus embun.
Kau mahu tulis pasal bukit,
Yang memukau pandangan mata,
Segar dan hijau diliput lalang.
Kau mahu tulis pasal bulan,
Yang mengambang sejengkal di ufuk,
Suram dan merah seperti darah.
Kau mahu tulis pasal burung,
Yang meredah gerimis petang,
Ramai dan hitam mencemar langit.
Tapi kau sedar,
Antara tulang-temulangmu,
Tiada sekerat yang punya seni.
Lalu kau pun sambung,
Buat apa yang kau buat.
Random Awesomeness 2008-02-19
Take a look at this, columnName is a bit data type, 1 or 0.
SELECT SUBSTRING('YesNo', 4 - 3 * columnName, 3) as YesNo
FROM TableName
Neat huh? Although I prefer to collect real data from database and do formatting in the client code, this is a sweet hack nevertheless. Got it from this blog entry.
— UPDATE —
This is (somewhat) the equivalent in C#.
Console.WriteLine("YesNo".Substring(3 - 3 * Convert.ToInt16(boolValue),
2 + Convert.ToInt16(boolValue)));
Or… You can just do this instead :P
Console.WriteLine(boolValue ? "Yes" : "No");
C# Cascading Constructors
I got this question, on whether the default constructor is being called when you instantiate an object using another of its constructor.
Using automatically implemented properties in C# 3.5, I find myself frequently needing to override the default constructor to instantiate default instances to member properties, such as for the TaskItems in this sample code below.
class Workman
{
public string Name { get; set; }
public string StaffNo { get; set; }
public List<string> TaskItems { get; private set; }
// Default constructor
public Workman()
{
TaskItems = new List<string>();
}
// 2nd constructor
public Workman(StaffProfile profile) : this()
{
this.Name = profile.Name;
this.StaffNo = profile.StaffNo;
}
}
After some simple test, I found that the default constructor is not being called if I instantiate the object using the second constructor,
var man = new Workman(staffProfile);
Unless if you supply this() for the second constructor. It works like base() when you want to call specific parent constructor in an inherited class.
Furthermore, you can call other constructor, not just the default. Let’s say you have a third constructor,
// 3rd constructor
public Workman(string name, string staffNo) : this()
{
this.Name = name;
this.StaffNo = staffNo;
}
You can change the original second constructor to this,
// 2nd constructor
public Workman(StaffProfile profile) : this(profile.Name, profile.StaffNo)
{
}
MSBuild Missing Reference Error
I am exploring easier ways to compile our codes by using MSBuild which can compile solutions through command line without launching the heavy Visual Studio. I tried it in this one solution of ours, it failed with some missing reference error, where as compiling in Visual Studio is successful. I heard that Visual Studio is also using MSBuild underneath, so it’s kind of weird.
The problem is caused by “implicit reference” (not sure if it’s a standard phrase), found at MSDN forum.
That is, project A invokes a method that’s defined in project B and project B invokes a method that’s defined in project C. And while project A has an explicit reference to project B, and project B has an explicit reference to project C, there is no explicit reference from project A to project C.
Visual Studio appears to resolve the implicit reference of A=>C, but MSBUILD doesn’t.
I solved the problem by manually adding a reference from project A to project C (although if another developer later uses the “remove un-needed references” feature, that reference will disappear from project A).
Now, I can just navigate to the project folder in my command prompt, svn update if necessary, and type msbuild.
Poster .NET Framework 3.5
Korang boleh download .NET Framework 3.5 Namespace poster kat sini (jumpa via ScottGu’s blog). Poster ni mengandungi senarai semua class yang ada dalam .NET Framework 3.5.
Antara yang menarik perhatian aku, dari ASP.NET, ada namespace System.Web.ApplicationServices yang mengandungi class AuthenticationService, ProfileService, dan RoleService.
Aku selama ni memang tak berapa gemar nak gunakan MembershipProvider sebab susah nak configure. Aku lebih suka pada configuration menggunakan Dependency Injection (aku guna Castle Windsor) berbanding menggunakan web.config. Adakah aku boleh gunakan benda-benda ni bersama DI?
Ada juga System.Web.UI.WebControls.ListView. Mungkin ia menggantikan DataList, seperti mana GridView menggantikan DataGrid?
Selain itu dari bahagian Fundementals, ada System.Collection.Generic.HashSet<T>. Apa benda ni agaknya? Ada juga namespace System.Runtime.Serialization.Json. Bagus juga, ada alternative lain untuk human-readable serialization selain XML.
Tak lupa the whole new LINQ stuff. Ini mesti tengok punyah.
I’ll be definitely checking out those stuff later.
Real Programmer’s Editor
xkcd is the absolute source for amazing nerd comic. Today’s strip is a about real programmer’s text editor. You can see the comic here, or read the transcript that I have time-wastingly re-typed below.
nano? Real programmers useemacs.Hey. Real programmers use
vim.Well, real programmers use
ed.No, real programmers use
cat.Real programmers use a magnetized needle and a steady hand.
Excuse me, but real programmers use butterflies.
They open their hands and let the delicate wings flap once.
The disturbance ripples outward, changing the flow of the eddy currents in the upper atmosphere.
These cause momentary pockets of higher-pressure air to form, which act as lenses that deflect incoming cosmic rays, focusing them to strike the drive platter and flip the desired bit.Nice. ‘course, there’s an
emacscommand to do that.Oh yeah! Good ‘ol
C-x M-c M-butterfly…Dammit,
emacs.

