Be A Lazy Programmer! Use Your IDE to Debug Code

Back in the day when i used to debug my code just to inspect what actually the value of variables were, i did it in manual way. Actually that was… what a shame, and if you do too you should know that there is a better way to do that.

Debugging

Manual way means you write a code to show the value of variable into console or any other interfaces which you as developer can check that value whether it is as you expected or not. Don’t get me wrong, i’m not talking about unit test here.

Visual Studio Debug

Last night i was working on upload image functionality of a web application build on top ASP.NET MVC framework. Like typical of any image form upload , i wrote validation to make sure the image being uploaded by user is only accept jpg,jpeg and png extension. So i wrote this code

All seems good. I tried to choose zip file to be uploaded and of course the application will complain.
1. upload non image

2. not valid

After that i uploaded jpg image but same thing happened, system still complaining. Any idea how this happened?

It happened because the if condition is always true. I began to remember that return value of Path.GetExtension(param) is something with this format “.ExtensionName” so if i choose jpg image that code will return “.jpg” not just “jpg” without dot.

To make sure what is return value of Path.GetExtension(param) i did code debugging. Visual Studio and other modern IDE have this kind of feature.

3. mark for debug

4. debugging

And yap.. the return value is with dot (.). So i changed the if condition to be like this and everything was good 🙂

Facebook Comments
 

Agung Setiawan

Agung Setiawan adalah software engineer di BukaLapak.com, penulis sekaligus pecinta sastra, dan pembaca buku

 
Halo, perkenalkan saya Agung Setiawan.
Saya Software Engineer di BukaLapak.
Simak pemikian saya soal dunia Software Engineering via Twitter di @agungsetiawanmu dan facebook
Blog ini saya update seminggu sekali jadi sering-sering saja mampir
Mau belajar Vim bareng saya?
Belajar ngoding dari nol menggunakan PHP

Leave a Reply

Your email address will not be published. Required fields are marked *