The Pragmatic Programmer

Tulisan iseng kalo ada waktu.
See also: Other Geeks@INDC

August 2007 - Posts

Win32 Nostalgia

I was a C++ and Delphi programmer when I was in a college and on my first job. Because of job market reason, I had to switched to RAD tools like VB and C#. Now, I have forgotten many of Windows API stuff like WM_QUIT, PostQuitMessage, etc.

Starting from now, I will revisit my journey on learning Win32 programming with pure Windows API with goals to create an object-oriented Win32 GUI framework.

Stay tune!

Share this post: | | | |
Goyangan Dini Hari

Kemaren malam, Rabu 9 Agustus 2007, gw baru beli beberapa buku di Gramedia Matraman. Pulang ke rumah, gw asyik baca majalah Marketing yang gw beli beberapa hari yang lalu. Saking asyiknya, gw sampe ga sadar waktu udah menunjukkan pukul 00:00, gw belum sholat Isya, jadi gw wudhu. Sehabis wudhu, sekitar jam 00:12 dini hari, iseng-iseng gw buka salah satu buku yang gw beli.

 

Baru baca bagian kata pengantar:

Eh, tiba-tiba, gw denger pintu kamar gw bergerak-gerak dan berbunyi agak keras. Kaget juga! Dan gak lama kemudian, meja komputer gw bergoyang-goyang dan gw juga merasakan goyangan yang cukup keras. Ini pasti gempa!!! Khawatir terjadi musibah seperti di Surabaya beberapa waktu lalu, gw bangunin nyokap. Alhamdulillah, gempanya berakhir dan gak sampe meningkat menjadi musibah nasional.

Ini merupakan gempa ke-2 terbesar yang pernah gw rasain, mungkin ke-2 terbesar di Jakarta, karena dulu sekitar tahun 1996, Jakarta juga pernah diguncang gempa. Saat itu gw lagi di toko buku Gramedia Citraland, di lantai paling atas. Gw lagi jongkok, sambil baca buku dan tiba-tiba gw merasakan kepala gw agak pusing dan badan gw bergoyang-goyang. Gw masih belum sadar. Enggak lama, gw nengok ke belakang....Ternyata orang-orang lagi pada berlarian, panik :)

Hmm...Kebetulan atau gimana yah? Apakah gempa dini hari ini disebabkan oleh kedahsyatan buku yang gw baca? ;-)

Untuk yang udah married mungkin lagi 'digoyang' yang lain, tapi buat bujangan kayak gw, kok malah digoyang bumi :-P.

Share this post: | | | |
How to Write Your Own Code Generator - Part I

If you are a business application developer and you're writing you're application using entity paradigm that is you are using object/class to represents your database tables then I am absolutely sure that you had been writing this type of code many times:

public class Person
{
private string _name;
public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
private DateTime _dateOfBirth;
public DateTime DateOfBirth
    {
        get { return _dateOfBirth; }
        set { _dateOfBirth = value; }
    }
// etc..
}

Unless you have written your own code generator or any other third party tools to automatically generate the code for you based on your database design then this article is for you.

In this Part I, I will only cover the theory not the implementation. I hope the reader will understand how to make one and write their own implementation but I'll wrote the implementation in the Part II.

The Theory
OK, here is the theory:

All you have to do is just find a way to read all the tables (including the views if you wish) contains in the database that you want to generate the code. Create a class to handle the code generation for a table. You have to map the sql data type with the equivalent .Net data type. Generate the code for each tables by passing it to your table class generator.

So, what you have to do is:
1. Find a way to read all the tables. There are many ways to solve this.
2. Create a class which responsible to generate the code for a table. If you do this, you have divide your problem into a smaller problem and it will be easier for you to conquer the problem.
3. Map the sql data type to .Net equivalents. This is up to you but you can find the reference table in MSDN.

Conclusion
OK, that's it. There is a third party scripting tools like CodeSmith that already handled the point 1 but you have to learn how to use it first :). Like I said I'll just covered the theory for now and its up to you to implement it. If you have any questions, you can put it on the comments box.

Share this post: | | | |