<?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>Ankit Jain &#187; Coding Guidelines</title>
	<atom:link href="http://ankitjain.info/ankit/category/coding-guidelines/feed/" rel="self" type="application/rss+xml" />
	<link>http://ankitjain.info/ankit</link>
	<description>» It’s all about Ankit and Web! «</description>
	<lastBuildDate>Thu, 02 Jun 2011 16:54:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Singleton Toast</title>
		<link>http://ankitjain.info/ankit/2011/05/19/android-best-practice-toast/</link>
		<comments>http://ankitjain.info/ankit/2011/05/19/android-best-practice-toast/#comments</comments>
		<pubDate>Thu, 19 May 2011 12:32:07 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Coding Guidelines]]></category>
		<category><![CDATA[Programming/Code]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/?p=413</guid>
		<description><![CDATA[On Android you may have experienced delayed toasts or overlapping toasts. This causes the toasts being displayed with irrelevant context/activity (e.g. user may have pressed backed, or previous toast is still overriding new one, or when too many toasts are displayed on screen). Consider the code below. It defines a single function for toast, that [...]]]></description>
			<content:encoded><![CDATA[<p>On Android you may have experienced delayed toasts or overlapping toasts. This causes the toasts being displayed with irrelevant context/activity (e.g. user may have pressed backed, or previous toast is still overriding new one, or when too many toasts are displayed on screen).</p>
<p>Consider the code below. It defines a single function for toast, that makes use of context object of Application. The class <code>MyApplication</code> needs to be declared in manifest.xml. The main advantage of such design is </p>
<ul>
<li>reduced footprint for activity&#8217;s context object.</li>
<li>at any moment only one toast remains on screen</li>
<li>reusing single toast object, rather than creating for each show.</li>
</ul>
<p><code>
<pre>

public class MyApplication extends Application {

	private static Resources resources;
	private static Context context;

	private static Toast toast;

	/**
	 * Called when the application is starting, before any other application
	 * objects have been created. Implementations should be as quick as possible
	 * (for example using lazy initialization of state) since the time spent in
	 * this function directly impacts the performance of starting the first
	 * activity, service, or receiver in a process. If you override this method,
	 * be sure to call super.onCreate().
	 * */
	@Override
	public void onCreate() {
		super.onCreate();
		Log.i("MyApplication", "Starting app...");
		MyApplication.resources = getResources();
		MyApplication.context = getApplicationContext();

		MyApplication.toast = Toast.makeText(MyApplication.context, "", Toast.LENGTH_SHORT);
	}

	/** Returns the global resources object. */
	public static Resources getResourcesObject() {
		return MyApplication.resources;
	}

	/** Returns the global context object. */
	public static Context getContextObject() {
		return MyApplication.context;
	}

	public static void toast(String message)
	{
		MyApplication.toast(message, Toast.LENGTH_SHORT);
	}

	public static void toast(String message, int duration)
	{
		MyApplication.toast.cancel();
		MyApplication.toast.setText(message);
		MyApplication.toast.setDuration(duration);
		MyApplication.toast.show();
	}

}</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2011/05/19/android-best-practice-toast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handicapped Software</title>
		<link>http://ankitjain.info/ankit/2009/07/25/software-disability-user-expectation/</link>
		<comments>http://ankitjain.info/ankit/2009/07/25/software-disability-user-expectation/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 08:44:37 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Coding Guidelines]]></category>
		<category><![CDATA[Programming/Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/?p=334</guid>
		<description><![CDATA[[ This post is about software's disability to meet users' expectations. I know you have developed lots of software/applications over your career! Have you ever evaluated them on disability index? No, then read on. "You" = refers to our typical "software engineer" ] Ever heard someone saying &#8220;this software sucks&#8221;&#8230; I love such moments. It [...]]]></description>
			<content:encoded><![CDATA[<p><small>[ This post is about software's disability to meet users' expectations. I know you have developed lots of software/applications over your career! Have you ever evaluated them on disability index? No, then read on. "You" = refers to our typical "software engineer" ]</small></p>
<p>Ever heard someone saying &#8220;this software sucks&#8221;&#8230; I love such moments. It makes me laugh, not for the user,  but for the poor developer! Users are innocent, they are not concerned about technical details. A software is there to make life simpler and hide complications of a task. It&#8217;s your responsibility to make it intuitive and meet users expectation on first impression, rather showing unnecessary (modal) alert boxes or irrelevant (technical) details. You don&#8217;t need to be a Usability Engineer. Just, </p>
<ul>
<li> stand on users&#8217; shoe and think what is annoying</li>
<li> don&#8217;t take negative feedback as an attack on you and your beliefs.<br />
Rather it&#8217;s a feedback on your understanding about <em>how much you understand your users</em>. In short never reject/resist on feedback. </li>
</ul>
<p><a href="http://www.codinghorror.com/blog/archives/001289.html" target="_blank" >Nobody hates software more than software developers</a> and nobody distrust software more than software developers. Scott Berkun has written a good post about <a target="_blank" href="http://www.scottberkun.com/essays/46-why-software-sucks/">why software sucks</a>. ( I have heard software engineers saying that they don&#8217;t trust online money transactions.  Heck !! Do you need President to meet you and ensure? ) </p>
<p>Here is what I think you should target as first step:</p>
<ul>
<li>Any tasks that you think user should perform by reading Help/Documentation, MUST be automated.</li>
<li>Even an single unnecessary alert box annoys. Features should be available with less no of clicks. Still this is very subjective matter to discuss. A simple guidelines is &#8211; only system errors or exceptions should raise alert-box, tiny information should be modal-less dialogs (or like balloon pop-up).</li>
<li>users never read entire screen. Default values chosen or default selection of check-boxes makes big difference in a long run.<br />
E.g. while filling an online form a default selection of check-box &#8220;subscribe me for spam mails&#8221;. Who does read entire form before clicking submit? None. But it affects your reputation in long run.</li>
<li>Never hesitate in picking a useful (cool, awesome, sexy, astonishing, amazing! ) feature from competitive software. Ask a simple question &#8211; Does it add value to your product? You won&#8217;t like this argument, but this is truth. The success of Web is a tiny &#8216;view source&#8217; feature. Well, this is a fast moving industry where we learn from other, we improve over time. You never blame the world for borrowing <a href="http://en.wikipedia.org/wiki/Tabbed_browsing">tabbed browsing</a> from Opera (originally by NetCaptor). It&#8217;s a matter of accessibility, and understanding what your users like and what they dislike is a key to success.</li>
<li>Don&#8217;t recruit incompetent programmers, because a <a href="http://www.sigsoft.org/SEN/parnas.html" target="_blank">incompetent programmer creates two new jobs a year</a>.  If you have a few already, either trains them or fire them. (Sorry pals)</li>
</ul>
<p>- ankit<br />
( and finally, this is a 100th post on this blog. Happy Blogging! )</p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2009/07/25/software-disability-user-expectation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unreachable code Error or Warning?</title>
		<link>http://ankitjain.info/ankit/2009/07/08/java-unreachable-error-why/</link>
		<comments>http://ankitjain.info/ankit/2009/07/08/java-unreachable-error-why/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 04:14:13 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Coding Guidelines]]></category>
		<category><![CDATA[Programming/Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/?p=330</guid>
		<description><![CDATA[In Java, unreachable code is treated as compilation error. What do you think? Isn&#8217;t making it warning would have made developers&#8217; life simpler? Of course you can write &#8211; if( true ) &#160;&#160;&#160;return; What if you could simply write return. This helps in testing a function quickly. As a good programming practice we always remove [...]]]></description>
			<content:encoded><![CDATA[<p>In Java, unreachable code is treated as compilation error. What do you think? Isn&#8217;t making it warning would have made developers&#8217; life simpler?</p>
<p>Of course you can write &#8211; </p>
<blockquote><p><code>if( true )<br />
&nbsp;&nbsp;&nbsp;return;<br />
</code> </p></blockquote>
<p>What if you could simply write return. This helps in testing a function quickly. As a good programming practice we always remove all warnings from code, and such unconditional return statements can be rectified later.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2009/07/08/java-unreachable-error-why/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Eating Exceptions&#8230; eeehhhh!</title>
		<link>http://ankitjain.info/ankit/2008/04/24/csharp-eat-exception-try/</link>
		<comments>http://ankitjain.info/ankit/2008/04/24/csharp-eat-exception-try/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 08:03:19 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Coding Guidelines]]></category>
		<category><![CDATA[Programming/Code]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[exception]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/2008/04/24/csharp-eat-exception-try</guid>
		<description><![CDATA[Following are few points you need to take care when you decide to eat an exception. These are very much specific to C# language. a. Limit the code block. Attempt to wrap one or two statements within try. b. If an exception is eaten, log details to some logging mechanism. In short never write empty [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoListParagraphCxSpMiddle">Following are few points you need to take care when you decide to eat an exception. These are very much specific to C# language.</p>
<p style="margin-left: 1in; text-indent: -0.25in" class="MsoListParagraphCxSpMiddle">a.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal">       </span>Limit the code block. Attempt  to wrap one or two statements within <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">try</span>.</p>
<p style="margin-left: 1in; text-indent: -0.25in" class="MsoListParagraphCxSpMiddle">b.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal">      </span>If an exception is eaten, log  details to some logging mechanism. In short never write empty catch <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">catch</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'">(</span><span style="color: #2b91af">Exception</span>) {}.</p>
<p style="margin-left: 1in; text-indent: -0.25in" class="MsoListParagraphCxSpMiddle">c.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal">       </span>Never eat exception that  indicates some bad behavior of code execution like &#8211; <span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">ArgumentNullException</span>,</p>
<p style="margin-left: 1in" class="MsoListParagraphCxSpMiddle"><span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">NullReferenceException</span>,</p>
<p style="margin-left: 1in" class="MsoListParagraphCxSpMiddle"><span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">ArgumentNullException</span>,</p>
<p style="margin-left: 1in" class="MsoListParagraphCxSpMiddle"><span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">InvalidCastException</span>,</p>
<p style="margin-left: 1in" class="MsoListParagraphCxSpMiddle"><span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">InvalidOperationException</span>,</p>
<p style="margin-left: 1in" class="MsoListParagraphCxSpMiddle"><span style="font-size: 10pt; color: #2b91af; line-height: 115%; font-family: 'Courier New'">AccessViolationException</span>,  etc;</p>
<p style="margin-left: 1in; text-indent: -0.25in" class="MsoListParagraphCxSpMiddle">d.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal">      </span>There is <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa664760(VS.71).aspx">a big  difference between</a> <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">throw</span>  and <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">throw  </span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'">exeception</span> statements.  <a target="_blank" href="http://www.winterdom.com/weblog/PermaLink,guid,154.aspx">This is in  terms of resetting stack trace which the later does.</a> If you are writing a  framework or want to hide your internal implementation use <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">throw  </span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'">exception</span>,  otherwise use <span style="font-size: 10pt; color: blue; line-height: 115%; font-family: 'Courier New'">throw</span> only.</p>
<p>- Ankit</p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2008/04/24/csharp-eat-exception-try/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

