Showing posts with label Computer. Show all posts
Showing posts with label Computer. Show all posts

Debugging Hardware Problem

Today, I boot the PC. The boot process goes smoothly until the windows trying to load. Suddenly a blue screen appear and the computer restarted.

If you ever have a pc for 3 years or more, you may experience similar situation as well. PC unable to boot, sudden restart in middle of work, or something like that may happen due to hardware failure.

An experienced one already know that hardware problem can be happened in many parts of hardware, such as CPU, RAM, hard disk, VGA, motherboard, power supply, etc. Similar with software debugging, finding a part of hardware which is the root cause can be a trouble. I find the debugging hardware problem is similar with one in software.

During the booting after my PC restarted, I try to run the windows in safe mode. Strangely, it can run well. Some common applications such as office and browser can be run normally, with the minus of good display and network support due to safe mode.

Normally, you cannot even able to boot at all when the CPU or RAM get any trouble. From this point, I believe that the RAM and CPU is still in good shape, eliminating two error possibilities. Troubled power supply normally cannot affort to boot the system too and not causing blue screen error. So, we get another parts eliminated, leaving both motherboard and VGA alone.

Both parts become the "possible root cause" which cause the error. From this forward, I begin to test the "possible root cause" to be proven. This step is meant to prove whether the possibility is actually the real root cause.

Luckily, my possibility is being strengthened by windows error message in safe mode, showing bcc code 116. After simple searching in Google (thanks Google), I can easily found some article mentioning bcc code 116 related to video graphic error. Now only one thing to prove: whether the system will boot up without using the graphic card.

So I start to reach device manager, disabled the display adapter, and begin restarting the PC. The result is, viola! The system successfully loaded. The application runs well, the browser connected to the internet, and nothing has problem except a poor - low resolution display. And a little lag because the rendering are not being done in graphic card anymore.

The suspect left to motherboard or VGA, which I haven't found the cause yet. That is because I do not has spare change for it. But the bigger suspect is VGA, because it is older than the motherboard.

Conclusion

Finding the cause of hardware error is very similar with debugging software. It is started by finding the possible root cause, proving the possibility, and then fixing the problem. Experience and knowledge also help in both cases, to speeding the discovery of possible root causes. And for both cases also, you need to know how the system behave / working, or you will need additional time to find how the system work.

Interface Programming: Entity Wrapper to Handle Dynamic Source Object

Background

During working with legacy code, I have found that many people used DataTable/DataSet instead of strongly typed objects. They are using some code like
string id = row["id"].ToString();
instead of
string id = request.Id;

It is becoming a maintenance hell because of several reasons:
  • I do not know the data type from database, so I need to debug into database procedure
  • I do not know whether the data is nullable or not, again I need to debug into database
  • When I need to change the data type, I need to search for every implementation, change it and make sure it does not break 
And last but not least, if I want to make enhancements or modifications, I have been faced with 2 options:
  • Keep  the same programming style, using the DataTable, with the risk that you add another more maintenance hell object
  • Refactor it, with the risk of breaking is higher
I want to use Dependency Injection (DI) for my further development. Lack of strongly typed entities are of course prevent me from using DI. So I need to change the DataTable to strongly typed object before using the DI implementation.

Design, don't Code Yet

 Why - Risk at Development

As a programmer, sometimes I doubt whether I should wasting time to think and design about the application that I will develop or not. As a single programmer-architect, there are some self-defined projects where I usually start by code first or by design first. Logically, they should have produced the same result, thinking that the developer and the architect is the same person. Practically, I'm surprised that the project started with code first is tend to have more risk and more likely to be stopped than the one by design-first.

So, logic does not apply here? Yes it is. The reason is basically that the developer is human. and they will likely get bored because of several reasons:
  • The project does not has exact requirement and scope
  • The project does not has exact release strategy
  • The project is most likely isn't needed by the user

The project does not has exact requirement and scope

Once, I have tried to create a so-called "ideal-best" application. The application should be able to handle many kind of business process. That application will be free of bug, easily extendable and has good architecture foundation. And the application can work as both transaction handling or event high level management reporting tools.

It sounds like a good plan at the beginning, however with such a big regards I need to drop the development because I got bored during developing it. It has no exact scope, no exact plan about what I must develop, what I must validate, how is the process after doing this and that, etc. The scope is growing and growing each day I think about the application, and the development cannot follow the planning growth. You have not target to accomplish, and caused you to loss interest in the development.

The project does not has exact release strategy

 What I mean about the term of release strategy here is a strategy about how to deliver the application. It consist of release date, the audience and the platform target. It may has more details than that such as how to replace the current running application without breaking, or how to not breaking other applications which is dependent to it; but it's regarding what kind of application that want to be delivered.

Having no release date deadline (target) can affect the development scope, since you will think like "I have unlimited time to develop this" or "I can add this and that feature before delivering the application, since the release date isn't being decided". 

Lack of audience target can also affect the scope, because you will try to create an application that can be used by any level of management (transaction level or event advanced-level ad-hoc reporting).

Lack of platform target can demoralize your development. You will be haunted by thoughts such as "will it works well in firefox, chrome, or IE?" or "will it works in other-windows operating system?". Thoughts like that will drag your development, because you will be bugged by how you will check them each time you make a modification. Don't be bugged by it!

The project is most likely isn't needed by the user

Any project needed by the user should has estimated release date. In terms of user, the faster the deliver date, the better. Sometimes you may think that this kind of application/enhancement will not be needed by the user. It can be because you can do manipulation to the database directly. This kind of thought can demoralize the development, since you don't know exactly how your application can give good benefits to the user. Don't develop any kind of application which won't be needed. Or if it will, don't ever think that the workaround (direct manipulation) can be the replacement of the application.

Conclusion

Always design your application first before do code. No matter how skillful programmer you are, the risk of not having the application designed beforehand is high. It can makes your effort go waste, and you got nothing from it, except wondering why this is happening. If you cannot do the design, as someone who is good at it. Asking experts in each field, for example accountant during finance application design or a headmaster during education application design. It can give you clear vision about what kind of application you want to develop, and the functionality.

Separation of Model in Design Pattern

Before talking about model, you can read about what is the "model" thing in MVC design pattern explanation. The simple explanation about model (my interpretation, don't use it in exams) is something which represent the structure of data, and possess the logic to get and/or modify the data.

Usually, model's logic can be integrated with the controller (or view model), and the structure itself can be represented using data sets (for database, or xml documents for xml). So in most cases, developers really can ignore model and integrated it with the controller itself. So why is it needed to separate the model?

If we said about small application, it will be okay to ignore model, and integrate it with the controller at all. But what if we talk about large applications? It will be hell if we use data sets or xml documents itself. A slight change with the data structure, and you must search for every controller which used that data. Yeah I already said every controller, and if the application has so many controller, it will be a pain.

Not only that, in additional model can hold some logic that bound to data, so every controller used the data can have same behavior of the logic. Let's say that a request has some mechanics like discounts or so. Instead of put the logic in controller or database, we can put it in model. So in summary, I will say that the model is quite a handy tool for data management.

The Popular MVC Design Pattern

If you need reason(s) why the desin pattern are needed in software programming, you can read mw previous post.

Honestly, at the first time I learnt this design pattern, I find it was a bit confusing. Moreover, I find it useless to separate model with the controller, even I can immediaetly find the importance to separate the view an controller. However after try to create a php project using codeigniter framework, I find the requirement are somewhat important.

Before talking further about MVC, let me tell you the basis of MVC. The view, to be simple are the user interface. It is related to everything what user sees, what user input, what user choose and logics of the UI to communicate with controller (in this case, form tag and ajax call are considered a view.

Controller on the contrary, receiving input from view, processing it with logics (if else, loop, mathematical logics, etc), getting the data from model, sending the data to model, and even choose what view will be displayed after all the process done.

Model is the object that you use in controller. Model which data will be displayed in view, which hold the logic to modify the data in storage (can be database, xml, pure text files, encoded file, etc), getting the data from storage, and hold the structure of data.

From that explanation, we can see that it is obvious to separate view with controller, in order to separate business logic with UI logic. But why is it needed for model to be separated with the controller, instead just handle the model (get and modify the data) in controller? We can get the explanation in this post.

Design Pattern, How Important is it

Design pattern is usually be used in software application programming. There are some design pattern which is used widely by enterprise, or insividual programmer. But how important is this design pattern 'thing'?

The main purpose of design pattern is to separate the application interface (UI) with the business logic. Why is it needed to do such thing?

In my latest job, there was a project which need to be handed over to me. The project are using Asp.Net webform. The structure of the project are using event-driven structure, as the basis of Asp.Net webform design.

The business logic (lets say that as the logic to submit a request, validate the form or updating the request) are being done in code behind of aspx.cs form. To be worse, the business logic sometimes handled in asmx webservice and being triggered by jquery ajax, making it harder for me to decrypt it.

Well, the pain did not stop there. The design are making it harder to be modified. A little modification can cause errors in other places, and more effort are needed to unify the change in other places as well. This is, are contrary with principal of object oriented, which is encapsulation and reuseability.

So how can a design pattern be used to solve these usually founded problems? I will try to describe it in my future posts.

C# Stored Procedures vs Linq

Dalam dot net programming, banyak cara bagi developer untuk melakukan hubungan dengan database dan mengaksesnya. Secara umum ada 2 cara yang umum digunakan yaitu menggunakan DataSet+SqlDataAdapter atau Linq.

Secara garis besar, kita dapat menggambarkan keuntungan Linq dibanding data adapter:
  • object oriented, sehingga tipe data yang diakses sudah terkonversi menjadi data type dot net. Hal ini membuat penggunaan tipe data yang lebih aman
  • Linq memiliki query optimizer sendiri sehingga query dasar yang digunakan developer sudah diimprove secara otomatis
  • relasi table dapat dilakukan secara obect-oriented sehingga lebih mudah digunakan saat development
Namun di samping itu Linq memiliki kelemahan yang cukup signifikan. Berikut adalah keunggulan stored procedure dibanding dengan Linq:
  • struktur objek Linq sangat bergantung pada struktur database, sehingga perubahan sekecil apapun akan memerlukan penangan dari sisi applikasi atau applikasi berpotensi break. Sementara mengubah stored procedures tidak memerlukan perubahaan dari sisi applikasi.
  • sulit untuk menelusuri query-query yang digunakan (terutama yang kompleks). Tujuan dari penelusuran tersebut seperti saat debugging atau indexing
  • stored procedures dapat digunakan untuk query yang simple hingga yang query kompleks seperti summarize atau pagination

C# Winforms vs WPF

Banyak sekali modul-modul applikasi yang dapat dibangun dan dipergunakan dengan menggunakan .Net C# Winforms. Winforms sendiri juga sudah merupakan framework yang bagus, sudah full-oop, event-driven dan stable. Namun mengapa Windows memutuskan untuk mengeluarkan framework yang lain, yaitu WPF, sebagai framework desktop lain di samping winforms? Berikut adalah perbedaan antara WPF dan Winforms.
  • Winforms sangat mendukung architecture pattern MVC (model-view-controller), sementara WPF lebih mendukung menggunakan architecture pattern MVVM (model-view-viewmodel)
  • Dalam arsitekturnya, Winforms adalah event-driven sementara WPF lebih mendukung binding
  • Component (control) dalam WPF lebih customizable dibanding Winforms
  • Struktur penulisan WPF adalah hampir sama dengan Silverlight, modul mirip flash yang dapat di-run dari browser
  • Winforms menggunakan Windows API dalam men-render UI sementara WPF menggunakan directX sehingga lebih lightweight (less resource)
  • Konstruksi UI winforms seluruhnya menggunakan codebehind, sementara WPF menggunakan XAML (walaupun dapat juga dilakukan dari codebehind)
  • Pada WPF terdapat control "Style", yang dapat di-reuseable sehingga user tidak perlu membuat usercontrol sendiri untuk me-style kan controlnya. 
Kesimpulannya, WPF lebih mendukung data binding, style-customizable dan lightweight UI render. Namun apabila user baru mempelajari programming, lebih disarankan untuk dimulai dengan Winforms, karena lebih mudah dipelajari daripada WPF.

C# Public Property vs Public Attribute

Well, setelah cukup lama bermain dengan C#, ada beberapa hal yang terkesan 'lucu' dalam pembelajaran. Hal tersebut adalah property vs attribute.
Dalam mendeklarasi class di C#, ada beberapa cara untuk merepresentasikan attribut, di antaranya adalah:
  • Public attribute, yaitu dengan mendeklarasi attribute dengan access modifier public, sehingga mudah dapat digunakan oleh class lain
  • Property, yaitu mendeklarasi public attribute dengan accessor get; dan/atau set;
  • Function getter setter, cara ini digunakan umum oleh java
Sekilas, public attribute dan property tidak banyak berbeda, terkecuali get/set accessor yang dapat di-inject oleh potongan syntax. Namun ternyata setelah banyak menggunakan dua hal ini, ada perbedaan yang cukup jelas, yaitu public attribute tidak akan tampil untuk data yang di-binding, baik itu WPF binding, winform binding ataupun Asp.Net binding. Karenanya, biasakan untuk menggunakan property dan bukan public attribute.

Try / Catch, The Double-edged Sword

Try/catch, untuk mayoritas programmer (terutama java) pasti tidak asing lagi dengan syntax tersebut. Syntax tersebut memiliki kemampuan yang hebat dan sangat membantu dalam melakukan pengembangan.

Namun, penggunaan try/catch yang tidak hati-hati dan sembarangan dapat membuat celah dalam sistem. Salah satu celah yang paling umum adalah tidak adanya error message (isi catch kosong). Celah tersebut membuat debugging menjadi susah karena exception tidak menghasilkan error box.

Jadi, apa saja yang harus diperhatikan dalam penggunaan try/catch? Berikut adalah beberapa hal yang sepengalaman saya harus diperhatikan:

1. Penanganan Exception dalam catch.
Object Exception memiliki property Message yang membawa pesan error yang terjadi. Salah satu penanganan exception yang paling mudah adalah menggunakan MessageBox (desktop app) atau Response.Write (asp). Penanganan lebih 'advanced' dapat berupa refresh data, kalkulasi autonomous, dan lainnya sesuai dengan tujuan.

2. Object Exception memiliki turunan
Object Exception memiliki turunan sesuai dengan error yang ada. Misalnya seperti FormatException pada .Net yang dihasilkan dari penggunaan format yang berbeda (misalnya ada karakter ketika parsing ke int, umumnya terjadi ketika parse). Ada juga NullReferenceException dimana program berusaha mendapatkan dan memproses variable yang bernilai null. Penanganan yang berbeda untuk tiap-tiap jenis Exception yang berbeda dapat membantu mempercepat development.

3. Pastikan tidak ada proses bersangkutan yang berjalan setelah ada Exception. Ingat, proses tetap berjalan setelah try/catch.
Misalkan anda memiliki int angka yang didapat dari parsing tbox1.Text. Anda men-'trap' proses parsing tersebut ke dalam try/catch. Kemudian angka tersebut akan digunakan untuk memasukkan data ke dalam database. Proses input data tersebut akan tetap berjalan walaupun ada Exception tanpa penanganan.

Proses yang salah:

int angka=0;
try{
  angka = int.Parse(tbox1.Text);
}
catch(Exception e){
  //show message here
}
//insert process, nilai angka adalah 0


Salah satu cara untuk menghindarinya:

int angka=0;
try{
  angka = int.Parse(tbox1.Text);
  //insert process
}
catch(Exception e){
  //show message here
}

CUtility.Forms.CTextBoxCurrency

Digunakan untuk menggantikan TextBox asal .Net yang digunakan untuk menangani input currency. Merupakan extended dari CTextBoxNominal.

cTextBoxCurrency.CurrencyPre
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan sebelum text.

cTextBoxCurrency.CurrencyPost
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan setelah text.

CTextBoxCurrency cTextBoxCurrency = new CTextBoxCurrency();
cTextBoxCurrency.CurrencyPre = "Rp. "; // hasilnya Rp. 0
cTextBoxCurrency.CurrencyPre = "";
cTextBoxCurrency.CurrencyPost = " US$"; // hasilnya 0 US$


Keyword: (C# custom textbox, C# textbox currency, C# textbox uang)

CUtility.Forms.CTextBox

Digunakan untuk menggantikan TextBox asal .Net dengan kustomisasi lebih banyak dan mudah.

cTextBox.InputMode
Menentukan karakter apa saja yang dapat diinput oleh user. Terdiri dari alpha, numeric, specialchar dan space. Dapat dikombinasikan dengan keyword '|' .
CTextBox cTextBox = new CTextBox();
cTextBox.InputMode = InputMode.Alpha | InputMode.Numeric | InputMode.Space;


cTextBox.AllowedSpecialChar
Menentukan karakter apa saja di luar [a-zA-Z][0-9] dan spasi yang dapat diinput.
CTextBox cTextBox = new CTextBox();
cTextBox.InputMode = InputMode.SpecialChar;
cTextBox.AllowedSpecialChar = "[],.\\/\":;" ; 

CUtility.Forms.CTextBoxNominal

Digunakan untuk pengganti TextBox bawaan .Net. Dikhususkan untuk menampung data nominal (angka).

cTextBoxNominal.AllowDecimal
Menentukan apakah boleh memasukkan nilai decimal (dengan karakter titik)

cTextBox.Nominal.AllowMinus
Menentukan apakah boleh memasukkan inputan minus (dengan karakter -)

cTextBoxNominal.TextToInt
Mengambil isi textbox yang telah diparse ke int. Jangan pergunakan ini untuk AllowDecimal = true. Fungsinya sama dengan int.Parse(cTextBoxNominal.Text).

cTextBoxNominal.TextToFloat
Mengambil isi textbox yang telah diparse ke float. Fungsinya sama dengan float.Parse(cTextBoxNominal.Text).

cTextBoxNominal.TextToDouble
Mengambil isi textbox yang telah diparse ke double. Fungsinya sama dengan double.Parse(cTextBoxNominal.Text).

Contoh:

CTextBoxNominal cTextBoxNominal = new CTextBoxNominal;
cTextBoxNominal.AllowDecimal = false;
cTextBoxNominal.AllowMinus = true;
int angka = cTextBoxNominal.TextToInt;

cTextBoxNominal.AllowDecimal = true;
float angka = cTextBoxNominal.TextToFloat;
double angka = cTextBoxNOminal.TextToDouble;


CUtility ver 1.0.1.1

Release kedua dari CUtility dengan beberapa perubahan:

CUtility ver 1.0.1.1 dapat diperoleh di sini.

CUtility.Print.Automated

Pengembangan dari CUtility.Print, dan digunakan untuk melakukan fungsi print yang lebih baik. Keunggulan CUtility.Print.Automated dibanding CUtility.Print adalah:

  • Modular Support - fungsi print dapat dipisah-pisah menjadi bagian-bagian untuk mempermudah modifikasi
  • Precalculated Height - fungsi print menghitung terlebih dulu tinggi dari objek yang akan dicetak, dan secara otomatis memindahkan ke halaman baru apabila dibutuhkan
  • Groupable - perintah-perintah cetak dapat dikelompokkan secara hirarki untuk mempermudah modifikasi dan mendukung fungsi modular lebih lanjut
Contoh penggunaan CUtility.Print.Automated dapat didownload di sini.

Keyword: (C# print, C# print document, C# print table, C# print auto new page)

CUtility.Print

Digunakan untuk menghasilkan tampilan cetakan yang lebih baik. Dilengkapi dengan fungsi-fungsi yang praktis dan mudah digunakan seperti Write, WriteLine, WriteCenter, DrawHorizontalLine, dsb.
Keunggulan dari CUtility.Print adalah:

  • Memiliki fungsi-fungsi cetak yang mudah digunakan dan umum, seperti Write, WriteLine, WriteCenter
  • Memiliki track cursor position sehingga pengaturan kursor cetak lebih mudah
  • Mengingat font, brush dan pen yang digunakan dalam mencetak
  • Mendukung pencetakan table

Contoh hasil menggunakan CUtility.Print:



Fungsi-fungsi CUtility.Print dikembangkan lebih jauh ke dalam namespace CUtility.Print.Automated.

Keyword: (C# print, C# print document, C# print table, C# print utility)

CUtility.Forms.CToolTip

Digunakan untuk menampilkan ToolTip dengan kustomisasi yang lebih dari ToolTip bawaan .Net.

cToolTip.Panel
Set panel yang akan digunakan untuk tampilan.
cToolTip.Panel = new Panel(); // mengeset tampilan tooltip seperti new panel biasa cToolTip.Panel = this.panelInfo; // mengeset tampilan tooltip sesuai dengan panelInfo yang ada dalam class

cToolTip.SetToolTip(Control control, string caption)
Mengeset Control yang akan mendapatkan ToolTip.
cToolTip.SetToolTip(label1, "A"); // mengeset object label1 agar mendapat tooltip. String yang dimasukkan tidak boleh kosong, namun tidak berpengaruh apa-apa.

CUtility.IOUtil

Digunakan untuk beberapa keperluan seperti path pada filename.

CUtility.IOUtil.RelativeFilePath(string filename)
Digunakan untuk mendapatkan path relatif dari filename (tidak memiliki label drive, dll). Berdasarkan pada application domain.

IOUtil.RelativeFilePath("C:\data\word.doc"); //return word.doc

CUtility.IOUtil.AbsoluteFilePath(string filename, string location)
Digunakan untuk mendapatkan path absolut dari filename berdasarkan pada application domain.

IOUtil.AbsoluteFilePath("word.doc", "data"); //return C:\application\data\word.doc

CUtility.IOUtil.MD5Hash(string word)
Digunakan untuk mendapatkan enkripsi md5.

IOUtil.MD5Hash("Hello World"); //return encrypted "Hello World" word

CUtility.IOUtil.IsDesignMode()
Digunakan untuk mengetahui design mode / running mode.

CUtility.IOUtil.IsDesignMode(); //return true if in design mode

CUtility.IOUtil.MeasureString(string text, Font font)
Digunakan sebagai static function untuk menggantikan Graphics.MeasureString.


CUtility.IOUtil.MeasureString("A", new Font("Times new roman", 12)); //return size dari A

CUtility.Validator

Digunakan untuk mengecek isi karakter atau angka.

CUtility.Validator.IsNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi angka.

CUtility.Validator.IsNum("123456"); //return true
CUtility.Validator.IsNum("A123456"); //return false


CUtility.Validator.IsAlpha
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet.

CUtility.Validator.IsAplha("ABCabc"); //return true
CUtility.Validator.IsAlpha("ABC1"); //return false


CUtility.Validator.IsAlNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet atau angka.

CUtility.Validator.IsAlNum("ABC123"); //return true
CUtility.Validator.IsAlNum("ABC123,."); //return false


CUtility Documentation

Daftar-daftar dari dokumentasi CUtility:

CUtility.Validator: http://serlock-works.blogspot.com/2012/02/cutilityvalidator.html
CUtility.IOUtil: http://serlock-works.blogspot.com/2012/02/cutilityioutil.html

CUtility.Forms Namespace
CUtility.Forms.CToolTip: http://serlock-works.blogspot.com/2012/02/cutilityformsctooltip.html
CUtility.Forms.CTextBox: http://serlock-works.blogspot.com/2012/03/cutilityformsctextbox.html
CUtility.Forms.CTextBoxNominal: http://serlock-works.blogspot.com/2012/03/cutilityformsctextboxnominal.html
CUtility.Forms.CTextBoxCurrency: http://serlock-works.blogspot.com/2012/03/cutilityformsctextboxcurrency.html