<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Ex nihilo nihil fit &#187; Best practices</title> <atom:link href="http://victorhurdugaci.com/category/best-practices/feed/" rel="self" type="application/rss+xml" /><link>http://victorhurdugaci.com</link> <description>Victor Hurdugaci&#039;s playground</description> <lastBuildDate>Tue, 29 Nov 2011 07:38:40 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <item><title>Tip #6: The importance of the default case</title><link>http://victorhurdugaci.com/tip-6-the-importance-of-the-default-case/</link> <comments>http://victorhurdugaci.com/tip-6-the-importance-of-the-default-case/#comments</comments> <pubDate>Sun, 11 Oct 2009 21:12:31 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Best practices]]></category> <category><![CDATA[Tips]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=1392</guid> <description><![CDATA[It is said that &#8220;is good to catch an exception as soon as possible&#8221;. This is the motto of the post. You never wrote perfect code! Neither do I and probably  no mortal will do this. You must accept it and try to make your code as best as possible. There are many ways to [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">It is said that &#8220;is good to catch an exception as soon as possible&#8221;. This is the motto of the post.</p><p
style="text-align: justify;">You never wrote perfect code! Neither do I and probably  no mortal will do this. You must accept it and try to make your code as best as possible. There are many ways to do this but today will focus the attention on the &#8216;default&#8217; case.</p><p
style="text-align: justify;">How many times you wrote?</p><div
class="wp_codebox"><table><tr
id="p13923"><td
class="code" id="p1392code3"><pre class="pascal" style="font-family:monospace;">select variable
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> ...
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> ...
    ...
    <span style="color: #000000; font-weight: bold;">case</span> n<span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">end</span></pre></td></tr></table></div><p
style="text-align: justify;">I did this a lot of times. Why do we do it? Because we assume we are bullet proof and out code is perfect. One might say that the previous snippet is not wrong but take a closer look. What if <em>variable</em> is not <em>1</em> and not <em>2</em> and &#8230; and not <em>n</em>? What happens?</p><p><span
id="more-1392"></span></p><p
style="text-align: justify;">In most cases unexpected things happen. Let&#8217;s assume that the select statement decides which account to use or maybe something less important like the color of a background in a game. What happens if you skip that code? Probably when you were writing the code you were not expecting any other values :) But be as paranoiac as possible: what if, somehow, in the future the value of <em>variable</em> will not be in the expected set.</p><p
style="text-align: justify;">If no case executes and you don&#8217;t expect this then the error might not be immediately visible. Maybe it will take 2 weeks until someone will complain, maybe an exception will be raise 5.000 lines from select block, you never know when and how other statements are affected.</p><p
style="text-align: justify;">So the solution for this is trivial. Use to <em>default</em> case to treat any unexpected error. The previous statement will become:</p><div
class="wp_codebox"><table><tr
id="p13924"><td
class="code" id="p1392code4"><pre class="pascal" style="font-family:monospace;">select variable
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> ...
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> ...
    ...
    <span style="color: #000000; font-weight: bold;">case</span> n<span style="color: #339933;">:</span> ...
    <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">CATCH</span> THE ERROR SOMEHOW
<span style="color: #000000; font-weight: bold;">end</span></pre></td></tr></table></div><p
style="text-align: justify;">The way you treat the exceptional case is up to you: abort the operation, crash the application, add a line to a log file, start the fire alarm, &#8230;</p><p
style="text-align: justify;">Just remember: <strong>your code is not perfect and other is even less so! </strong>Don&#8217;t expect correctness if you request it.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/tip-6-the-importance-of-the-default-case/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Software Craftsmanship</title><link>http://victorhurdugaci.com/software-craftsmastership/</link> <comments>http://victorhurdugaci.com/software-craftsmastership/#comments</comments> <pubDate>Sat, 18 Jul 2009 21:37:26 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Best practices]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[Manifesto]]></category> <category><![CDATA[Passion]]></category> <category><![CDATA[Project]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Software Craftsmanship]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=1207</guid> <description><![CDATA[Writing code and creating working software is not hard but writing quality code and creating valuable software is. The software craftsmanship manifesto values: Not only working software, but also well-crafted software. Not only responding to change, but also steadily adding value. Not only individuals and interactions, but also a community of professionals. Not only customer [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">Writing code and creating working software is not hard but writing quality code and creating valuable software is.</p><p
style="text-align: justify;">The <a
href="http://manifesto.softwarecraftsmanship.org/" target="_blank">software craftsmanship manifesto</a> values:</p><blockquote
style="text-align: justify;"><p>Not only working software, but also <big>well-crafted software</big>.<br
/> Not only responding to change, but also <big>steadily adding value</big>.<br
/> Not only individuals and interactions, but also <big>a community of professionals</big>.<br
/> Not only customer collaboration, but also <big>productive partnerships</big>.</p><p>That is, in pursuit of the items on the left we have found the items on the right to be indispensable.</p></blockquote><p
style="text-align: justify;">One can hardly doubt that the principles from then manifesto can be satisfied in other way than through passion. Of course, not all individuals involved in the process of software creation do their job with passion and dedication. Some do their job just because they need money or because they have some other interest and they really don&#8217;t care about the final product. They create software because they have to and usually is bad software.</p><p
style="text-align: justify;">Bad software is not software that does not work! Bad software, from my developer point of view, is software that was created chaotic. The project, from the beginning or from another point in the project&#8217;s timeline, was not governed by some rules and tenets. The individual involved in the project did not adhere to some standards and everyone was doing anything just to make a piece of working software.</p><p
style="text-align: justify;">This kind of projects are like pipes with rubber tape. You add more and more rubber tape (bad code/ideas, hacks) where you find a crack and in the end you will be over whelmed by the mess you created. Also, the fixing cost (refactoring) will be enormous.</p><p
style="text-align: justify;"><span
id="more-1207"></span></p><p
style="text-align: justify;">In order to create quality software (both from the developer&#8217;s and end-user&#8217;s point of view) the team must create a set of good and realistic guidelines that must be used by every member. The guidelines can include various things like design patterns, coding standards, document writing standards, communication methods and models, meetings standards, etc. These guidelines must not be all brainstormed in the early stage of the project &#8211; they need to be created before the moment of the first occurrence of the item they refer and should be possible to change them later, if needed, in exchange of better ones.</p><p
style="text-align: justify;">Well crafted software and guidelines are not, on their own, the key to success.  Another characteristic of the team members, that was mentioned before, is passion. Unfortunately, this cannot be imposed &#8211; you either care or don&#8217;t; no one, except the individual himself, can change this. One must want and be able to suggest improvements of the process.If you care about what you&#8217;re doing then you are capable of suggesting improvements. Passion leads to ideas, ideas lead to change.</p><p
style="text-align: justify;">Good ideas should be valued and bad ones should be thrown away but only after careful analysis and explanation. No idea must be considered bad or good if coming from a specific team member. This means that experienced team members can have good and bad ideas and novice members can also have good and bad ideas &#8211; members should be equally treated.</p><p
style="text-align: justify;">Not even standards and passion are not enough for creating good software. If people are individualists and tend to care only about what they are doing it will end up with some good pieces but not connected or poorly connected. Individuals must care about others, must communicate, establish good relations and form communities. These communities must be able help members to find solutions and members should be able to improve the community.</p><p
style="text-align: justify;">Instead of conclusion, will step back a little and say more about passion. As long as you are not passionate about what you are doing, you cannot get good results. Also, you can&#8217;t be proud of what you are doing. This is a vicious circle: passion leads to pride, pride leads to passion; the opposite is also true. So I will end with what Aristotle said &#8220;Pleasure in the job puts perfection in the work&#8221;.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/software-craftsmastership/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ATM Interface [Bad Practice]</title><link>http://victorhurdugaci.com/atm-interface-bad-practice/</link> <comments>http://victorhurdugaci.com/atm-interface-bad-practice/#comments</comments> <pubDate>Sat, 04 Oct 2008 13:41:38 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Best practices]]></category> <category><![CDATA[Funny]]></category> <category><![CDATA[ATM]]></category> <category><![CDATA[GUI]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=258</guid> <description><![CDATA[Today I had one of the most funny and annoying ATM experiences. First, let me describe the ATM: a big screen with 4 buttons on the left side and 4 on the right side. The numeric keyboard(digits, Enter, Cancel and Backspace buttons) is placed on the right side on some angle so you can type [...]]]></description> <content:encoded><![CDATA[<p>Today I had one of the most funny and annoying ATM experiences.</p><p>First, let me describe the ATM: a big screen with 4 buttons on the left side and 4 on the right side. The numeric keyboard(digits, Enter, Cancel and Backspace buttons) is placed on the right side on some angle so you can type easy.</p><p>I inserted the card and I was asked for the PIN code. Well&#8230; one of the digits was not really working. I pressed the button so hard that eventually I get two asterisks &#8211; this means I&#8217;ve typed a digit twice. [<em>Ups!</em>] The backspace or cancel buttons were not working and, on the screen, there was just one option: &#8220;Confirm PIN&#8221;&#8230; Without any other alternative I pressed the &#8220;Confirm&#8221; button and surprise: I got the screen where you choose the amount of money you want to withdraw [<em>Wow, this is a mind reading ATM - he definitely read the PIN from my brain :) </em>]. Forgot to mention, the Confirm button is not on the numeric keyboard, it is on the right side of the screen &#8211; pretty intuitive.</p><p>Now let&#8217;s choose the sum&#8230; Well the sum contains the digit that&#8217;s not working&#8230; Pressed it again hard and got two digits [<em> Déjà vu</em>? ]. The backspace button as not working and the only option from the screen was &#8220;Cancel&#8221;. So I have to move from the numeric keyboard to the screen side buttons. [<em> It deleted the whole number I've typed. I just want to delete one digit... Annoying! </em>]. After a few tries I&#8217;ve managed to enter the sum and pressed OK &#8211; again this was a screen side button.</p><p>Now this is the funny part: I get the receipt but no money. [ <em>Wow! </em>] On it there was a message &#8220;Invalid PIN&#8221; [ <em>You must be kidding. You asked me about the sum I want to withdraw and made me enter a number almost impossible to type just to inform me that the PIN - which I have entered previously - is wrong?? Damn</em> ].</p><p>All I wanted was to take the card and leave from that stupid ATM. Guess what? The card cannot be taken out of the machine until you enter the correct PIN&#8230; So I got back to the PIN screen. Being extremly carreful I&#8217;ve managed to enter the PIN &#8211; I repeat myself: there was no cancel button and if you enter a wrong PIN 3 times the card will be blocked &#8211; and the sum I want.</p><p>What more can I say?</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/atm-interface-bad-practice/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Find misplaced comments and quotation marks</title><link>http://victorhurdugaci.com/find-misplaced-comments-and-quotation-marks/</link> <comments>http://victorhurdugaci.com/find-misplaced-comments-and-quotation-marks/#comments</comments> <pubDate>Mon, 29 Sep 2008 12:12:40 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Best practices]]></category> <category><![CDATA[Coding practice]]></category> <category><![CDATA[Comments]]></category> <category><![CDATA[Debugging]]></category> <category><![CDATA[String literals]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=229</guid> <description><![CDATA[Many programming text editors automatically format comments, string literals, and other syntactical elements. In more primitive environments, a misplaced comment or quotation mark can trip up the compiler. To find the extra comment or quotation mark, insert the following sequence intro your code in C, C++, C# or Java. /*"/**/ This code phrase will terminate [...]]]></description> <content:encoded><![CDATA[<p>Many programming text editors automatically format comments, string literals, and other syntactical elements. In more primitive environments, a misplaced comment or quotation mark can trip up the compiler. To find the extra comment or quotation mark, insert the following sequence intro your code in C, C++, C# or Java.</p><pre>/*"/**/</pre><p>This code phrase will terminate either a comment or string, which is useful in narrowing the space in which the unterminated comment or string is hidden.</p><div
class="wp_codebox"><table><tr
id="p2297"><td
class="code" id="p229code7"><pre class="c" style="font-family:monospace;">obj<span style="color: #339933;">-&gt;</span>text <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Hello world;
// Some other code
delete obj;</span></pre></td></tr></table></div><p>This code will raise an error because you forgot a quotation mark after &#8220;world&#8221;. Placing the /*&#8221;/**/ after that line will close the string literal.</p><div
class="wp_codebox"><table><tr
id="p2298"><td
class="code" id="p229code8"><pre class="c" style="font-family:monospace;">obj<span style="color: #339933;">-&gt;</span>text <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Hello world;
// Some other code
delete obj; /*&quot;</span><span style="color: #808080; font-style: italic;">/**/</span></pre></td></tr></table></div><p>The selected text is now a string literal and you won&#8217;t get any compilation error. You have limited the search space for the error.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/find-misplaced-comments-and-quotation-marks/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
