Posts filed under 'C#'

History Log Is a Must!

Coba anda lihat coding di bawah ini :

C#:
  1. #region Summary
  2. // CREATE DATE :
  3. // PURPOSE :
  4. // VERSION :
  5. #endregion Summary
  6. #region History
  7. // LEGENDS :
  8. //   + --> Create
  9. //   - --> Delete
  10. //   * --> Modify
  11. // ---------------------------------------------------------------------
  12. // DATE          |  VERSION  |  STATUS  |  NAME            |  DESC
  13. // ---------------------------------------------------------------------
  14. #endregion History
  15. #region Imports
  16. using System;
  17. #endregion Imports
  18.  
  19. namespace projects
  20. {
  21. ...
  22. }

Dulu ... pencatatan history dalam pembuatan program hampir tidak pernah gw lakukan. Tapi sekarang gw mulai melakukannya ... caranya ya seperti anda lihat pada coding di atas, ada 2 region penting yang kudu gw implementasikan pada tiap file coding ( .cs[1] ) yang gw buat, yaitu : Sumary dan History.

Yang perlu anda cermati adalah region History. Region ini sangat membantu gw maupun rekan se-team gw yang membacanya (just incase gwnya gak bisa masuk kerja :p ). Setiap kali ada perubahan pada coding file tersebut, gw harus menambahkan detail historynya pada region tersebut. Fungsinya ya tentunya gak lain gak bukan untuk mentrack progress apa saja yang pernah gw lakukan.

Proses ini memang sangat membantu gw dalam mendevelop file coding, kadang coding lama (misal : method/property) gw masukin juga di History Region Comment :)). Soalnya lebih gampang ngetrack kalo coding kita yang baru ternyata tidak sesuai dengan yang kita harapkan dan perubahannya itu sendiri kita dapat mengerti alurnya darimana kemana (maklum ... kalo coding udah ditinggal 2 hari aja ... pasti lupa maksudnya apa), nah dengan melihat kembali ke history yang gw catet ... walhasil 80% gw bisa inget kembali maksud tuh coding gw apa :)).

Kendalanya ... seringkali gw lupa ataupun males dalam pengimplementasiannya ... yang ada abis ngoding dan melakukan perubahan ... trus teken tombol save ... compile ... shutdown deh :p

Anda sendiri bagaimana?

Linknotes
  1. .cs - Microsoft Visual C# extension class filename

4 comments November 27th, 2006

Interface “Lelaki Buaya Darat”

Hari ini gw mo sharing tentang Interface, mudah2an berguna ^-^. Interface kurang lebih adalah suatu reference type yang berisikan hanya abstract members seperti Method, Event, Properties dan Indexer yang tidak mempunyai implementasi (kurang lebih seperti itu ^-^)

Coba kita lihat bentuk dan pemakaian interface berikut ini :



C#:
  1. public interface ILelaki
  2. {
  3. void Makan();
  4. void Kerja();
  5. void Tidur();
  6. void Ngomong();
  7. }

Nah tadi kan disebutkan kalo interface itu tidak mempunyai implementasi, sekarang kita lihat bagaimana interface diatas diimplementasikan pada suatu class :



C#:
  1. public class LelakiPadaUmumnya : ILelaki
  2. {
  3. ///
  4. /// override method yang ada di interface
  5. ///
  6. public void Makan()
  7. {
  8. // Do something
  9. }
  10. ///
  11. /// override method yang ada di interface
  12. ///
  13. public void Kerja()
  14. {
  15. // Do something
  16. }
  17. ///
  18. /// override method yang ada di interface
  19. ///
  20. public void Tidur()
  21. {
  22. // Do something
  23. }
  24. ///
  25. /// override method yang ada di interface
  26. ///
  27. public void Ngomong()
  28. {
  29. // Say : MAU KU-ANTAR PULANG
  30. }
  31. /// METHOD BARU
  32. ///
  33. public void NyariIstri()
  34. {
  35. // Do something
  36. }
  37. }

Mulai ada bayangan? ... coba anda perhatikan, method2 yang sudah dideklarasikan pada interface ILelaki dioverride kembali pada class LelakiPadaUmumnya, tapi .... tentunya dengan implementasi didalamnya.

Sebagai catatan : "Class yang mengimplementasikan suatu interface harus mengimplementasikan semua anggota dari interface tersebut"

Sekarang coba kita lihat class dibawah ini :



C#:
  1. public class LelakiBuayaDarat : ILelaki
  2. {
  3. ///
  4. /// override method yang ada di interface
  5. ///
  6. public void Makan()
  7. {
  8. // Do something
  9. }
  10. ///
  11. /// override method yang ada di interface
  12. ///
  13. public void Kerja()
  14. {
  15. // Do something
  16. }
  17. ///
  18. /// override method yang ada di interface
  19. ///
  20. public void Tidur()
  21. {
  22. // Do something
  23. }
  24. ///
  25. /// override method yang ada di interface
  26. ///
  27. public void Ngomong()
  28. {
  29. // Say : CHECK-IN YUK
  30. }
  31. ///
  32. /// METHOD BARU (lelaki buaya darat, busyet!!! aku tertipu lagi ... ^-^)
  33. ///
  34. public void NyariCewek()
  35. {
  36. // Do something
  37. }
  38. }

Mulai ada gambaran ..??? ^-^
Mungkin sekarang anda bertanya-tanya bagaimana cara pengaplikasiannya? Coba kita lihat contoh dibawah ini :



C#:
  1. public class DuniaLelaki
  2. {
  3. private ILelaki lelaki;
  4.  
  5. public void UcapkanSesuatuSetelahKencanPertama(ILelaki interfaceLelaki)
  6. {
  7. lelaki = interfaceLelaki;
  8. lelaki.Ngomong();
  9. }
  10.  
  11. public DuniaLelaki()
  12. {
  13. LelakiPadaUmumnya lelakiPadaUmumnya = new LelakiPadaUmumnya();
  14. UcapkanSesuatuSetelahKencanPertama(lelakiPadaUmumnya);
  15.  
  16. LelakiBuayaDarat lelakiBuayaDarat = new LelakiBuayaDarat();
  17. UcapkanSesuatuSetelahKencanPertama(lelakiBuayaDarat);
  18. }
  19. }

Bagaimana? paham ^-^?
Mudah2 coding gw lebih memberi penjelasan daripada kata2 ;)

2 comments July 27th, 2006

C# Coding Standard

Just recently ago ... me and my colleaques had a little training with Agus Kurniawan (AK), one of Microsoft MVP, about Object Oriented Programming (OOP) in DotNET. It's mostly about fundamental concept how to program and work in Object Oriented kinda way.

One of AKs topic was "Coding Standard in C#". He said : "... every team has to have a standard, in this case coding standard ..." -- something like that ^-^.

I thought I had a good programming standard ... I thought we had a good programming standard!!!. Then again ... we're not :(. I admit it ... since I know how to write a code, actually, I know there's a standard, but ... even if I do, my coding standard kinda fuzzy hahaha :). I stick with one standard ... and all of a sudden BANG!!! one step backward to neanderthal programming :).

Not very consistent of me he10x. But comes to think of it ... we really do need a good standard, why??? ... to make one same perspective that's why!!.

Let's imagine this ... you have a crush on some nice girl who really adores a romantic kinda guy (which is me :)), you couldn't possibly say that you love her with "Response.Write("I LOVE YOU")" would you? :).

Okay ... back to coding standard. In C# coding standard there are lots of terminologies and definitions, two of them are Camel Case and Pascal Case.

Camel Case
A word with the first letter lowercase, and the first letter of each subsequent word-part capitalized.
Example : customerName

Pascal Case
A word with the first letter capitalized, and the first letter of each subsequent word-part capitalized.
Example : CustomerName

These two terminolgy are generaly used in C# programming, Microsoft too implements these two. Take a look at this example :

C# Coding Standard example

Thanks to AK, He really brightening things up. Hey AK have you received our new company Coding Standard Policy yet?!? :)

If you wanna know more about C# coding standard ... click here

2 comments July 14th, 2006