<?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>Code Away &#187; code</title>
	<atom:link href="http://blog.spathare.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.spathare.com</link>
	<description>Software development, thoughts and rants (of course)</description>
	<lastBuildDate>Tue, 16 Feb 2010 11:33:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Keystroke savers</title>
		<link>http://blog.spathare.com/2009/07/keystroke-savers/</link>
		<comments>http://blog.spathare.com/2009/07/keystroke-savers/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:14:05 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plumbing]]></category>
		<category><![CDATA[ROR]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=169</guid>
		<description><![CDATA[A peek at creating the Django Admin interface for any model has floored me completely. I did make a feeble attempt to create something similar for this in Java way back in 2005, but it is quite a daunting task. The integration offered by Django and RoR really makes one feel that not using these [...]]]></description>
			<content:encoded><![CDATA[<p>A peek at creating the Django Admin interface for any model has floored me completely. I did make a feeble attempt to create something similar for this in Java way back in 2005, but it is quite a daunting task.</p>
<p>The integration offered by Django and RoR really makes one feel that not using these frameworks is just the thing why software developers are in demand today. Hire fifteen to do a job in php which two could do using Django.</p>
<p>Some may say these facilities are just keystroke-savers. Agreed. The important question is why do you not want to save those keystrokes <img src='http://blog.spathare.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . A common application development (without the right kind of framework) spends a significant amount of time (I&#8217;d hazard a guess of more than 25%) doing plumbing work. Lets take a Java example for an &#8220;edit&#8221; screen, which shows the user already stored data, and allows him to make changes:</p>
<ul>
<li>Take data from repository, probably as a generic List
<ul>
<li>Oh yeah, connect to the DB first, and run a DB Statement in a try-catch block, right within your business logic</li>
</ul>
</li>
<li>Populate a data bean with all the data. All manually. If the DB cursor contains 25 columns, have a object with 25 attributes, 25 getters, 25 setters and populate all attributes one by one.</li>
<li>Send the data bean to the view</li>
<li>In the view, have hard-coded UI components for each attribute of the data bean to be displayed. For any related queries to be executed, hard code page links which will fetch those.</li>
<li>On event of user clicking OK, program a set of validations to ensure user has not entered bad values. Most of these are not business validations, but checks to ensure no bad characters are present in the input.</li>
<li>Populate user entered values obtained through form into a data bean</li>
<li>Code a SQL Update script which will take each value from the data bean and update the backend</li>
<li>commit (don&#8217;t forget that!)</li>
<li>Rinse-and-repeat for all related queries</li>
</ul>
<p>Any framework support (struts, spring, hibernate) is a keystroke saver in addition to being responsible for formalizing (a subset of) the programming for the application. Django and RoR simply take the integration between MVC to the next level. I had mailed a friend a few months ago about what Rails has:</p>
<p>1. <strong>Integration with AJAX: </strong>You see whether the type of request from the client (browser) is ajax or plain HTTP. You use those conditions to provide a specific response. In case it is an ajax request, you can play directly with elements rendered in the browser (e.g. Put text &#8220;Saved Successfully&#8221; in the information bar and blink it once). This integration, and resulting 5 lines of code is far faster than anything we would do by ourselves. (client side use ajax-specific library functions to send request, then check XML returned and perform activities in browser using javascript again). This integration is thanks to use of inbuilt prototype and scriptaculous libraries</p>
<p>2. <strong>Test Integration:</strong> I know that if a nice <strong>high-level </strong>test framework didn&#8217;t exist already, we would never get serious about writing real automated tests. It would always be like &#8220;lets develop this cool feature now that we have time&#8230; we&#8217;ll check out tests later&#8221;. Fortunately, tests are easy to write, and we can start small. (full page tests and all can be written later). We can also write Model level tests for ensuring relationships etc. N e a t.</p>
<p>3. <strong>MVC Integration: </strong>Neat MVC code, easy to write. Controllers and views nicely integrated. All variables declared in controller are directly available to views. Which should have always been the case, but in other barebones J2EE/php, you need to pass a data object explicitly, because MVC is not mandated.</p>
<p>4. <strong>Fixtures:</strong> Stuff to fill your &#8220;Test&#8221; database with data. Easy to write YAML (byebye XML). This will auto-run when you run tests, so your test database is ready with required data. If you don&#8217;t know yet, <span class="il">Rails</span> will auto-create dev, test, prod databases for easy demarcation. <span class="il">Rails</span> will also auto-clone the dev database schema to test database prior to loading fixtures.</p>
<p>The learning curve is a bit high, and I <em>am </em>spending a lot more time understanding the components in comparison to J2EE. Yet, given the benefits, I think it is well worth the effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/07/keystroke-savers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with Lego Mindstorms</title>
		<link>http://blog.spathare.com/2009/02/working-with-lego-mindstorms/</link>
		<comments>http://blog.spathare.com/2009/02/working-with-lego-mindstorms/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 04:08:20 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lego]]></category>
		<category><![CDATA[LeJOS]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[Mindstorms]]></category>
		<category><![CDATA[nqc]]></category>
		<category><![CDATA[RCX]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=129</guid>
		<description><![CDATA[Since I wrote about my stint with Lego Mindstorms and blocked Java I/O calls in my last post, I thought I might as well go ahead and note some more of the gotchas I encountered while working with Mindstorms kit. Although the Mindstorms RCX has pretty good capability, the programming interface bundled alongwith it is [...]]]></description>
			<content:encoded><![CDATA[<p>Since I wrote about my stint with Lego Mindstorms and blocked Java I/O calls in my last post, I thought I might as well go ahead and note some more of the gotchas I encountered while working with Mindstorms kit.</p>
<p>Although the Mindstorms RCX has pretty good capability, the programming interface bundled alongwith it is for kids. For any program spanning more than two cases of flow control, we need a real programming language.</p>
<p>The two languages I used were NQC (having almost C syntax, and named Not Quite C) and LeJOS (Le Java OS), based on Java 1.2.</p>
<p>NQC has inbuilt support for functions as well as multithreaded modules, but quite frankly the threading was not upto the mark. With two threads competing with each other for execution time, sometimes there would be several seconds where one of the threads waited for execution. LeJOS, on the other hand, worked beautifully with multithreading.</p>
<p>NQC also has a rather limited memory available for processing in comparison to LeJOS, which is quite surprising considering Java VM of LeJOS occupied around half of the memory. Yet, I was able to form large data structures in LeJOS while arrays of as small as 30 integers started giving trouble in NQC.</p>
<p>LeJOS has its set of troubles as well. The VM installation is actually a one time thing, but with the amount of testing you perform on the bot, batteries get changed, RCX units change and thus you find yourself running LeJOS installation a dozen times, which is quite a miserable thing to waste one&#8217;s time on. In addition to that, we have the great blocked I/O problem for Infrared Sensor which we discussed in our last post.</p>
<p>Limited memory and processing capacity puts stringent limits on nested methods, garbage collection and size of data structures. As I discussed earlier, a workaround to blocked I/O calls involved creating two separate threads. In my case, I had to keep both threads running infinitely. Having the child thread exit after receiving the data and having the parent thread spawn a new child when necessary worked for a while, but then the program would hang, presumably because there were too many threads getting created and the garbage collection may not have been able to cope up.</p>
<p>All in all, its fun working on the RCX, as long as the program is tuned to minimum resource usage, which goes for any micro platform. If you have experienced any more glitches or gotchas, please feel free to post comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/02/working-with-lego-mindstorms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with blocked I/O calls</title>
		<link>http://blog.spathare.com/2009/02/working-with-blocked-io/</link>
		<comments>http://blog.spathare.com/2009/02/working-with-blocked-io/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 03:37:22 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lego]]></category>
		<category><![CDATA[LeJOS]]></category>
		<category><![CDATA[Mindstorms]]></category>
		<category><![CDATA[RCX]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=124</guid>
		<description><![CDATA[Some time ago, I happened to work with Lego Mindstorms. Rather than learn yet another programming notation for Mindstorms, I preferred to use LeJOS. However, LeJOS was based on Java 1.2, which had blocked I/O calls. This means that an I/O write was not completed until a corresponding I/O read was executed at the receiver. [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I happened to work with Lego Mindstorms. Rather than learn yet another programming notation for Mindstorms, I preferred to use <a href="http://lejos.sourceforge.net/" target="_blank">LeJOS</a>.</p>
<p>However, LeJOS was based on Java 1.2, which had blocked I/O calls. This means that an I/O write was not completed until a corresponding I/O read was executed at the receiver. Similarly, an I/O read was not executed till someone wrote to the buffer.</p>
<p>How is this different from unblocked I/O? In the latter scenario, we poll the buffer status like this:</p>
<pre><code>while(true) {
  sbuf = inputStream.read(byteArr);
  if (sbuf != null) {
    //code to process byteArr
  }
  //other processing to be done
}</code></pre>
<p>In case of blocked I/O, the program waits for <code>inputStream.read</code> to get executed, till a point that the input buffer actually contains some data. Of course, this makes the check <code>sbuf != null </code> worthless, but more important is the fact that the &#8220;Other processing&#8221; we&#8217;d like to do never gets done until the input buffer is populated. Why is this important? Because in most cases we want to process a lot more than a single data stream. For example, in my LeJOS program, I was handling inputs from touch sensors, a light sensor and an Infrared sensor.</p>
<p>(A bit about my LeJOS program: I was trying a basic car driving program which could understand walls with touch sensors, car driving in front using light sensor and vehicle coming head-on using infrared sensor.  Although my Infrared sensor could be accessed using the usual I/O calls, it meant blocking up all the processing till someone actually sent me a signal.)</p>
<p>The easy way out of blocked I/O is multi-threading. The parent class polls the buffer data held in the child class (where both classes are threads and run independently). If there is valid data, we read and respawn the child class. Else we continue (in an infinite loop) with other processing and return later to check data. The child class is the one which stays blocked, but that thread is dedicated to receiving data only. Our program execution continues safely.</p>
<p>For those interested, LeJOS code for basic car driving (with inputs from sensors) with Lego Mindstorms RCX kit is available <a href="http://blog.spathare.com/wp-content/uploads/2009/02/cardrivemini.java">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/02/working-with-blocked-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The evergreen Tables v/s CSS debate</title>
		<link>http://blog.spathare.com/2009/02/the-evergreen-tables-vs-css-debate/</link>
		<comments>http://blog.spathare.com/2009/02/the-evergreen-tables-vs-css-debate/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 05:00:58 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[consistency]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[unsability]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=105</guid>
		<description><![CDATA[Beautiful post on removing CSS layout and going back to the good ol&#8217; table tag. The comments are good as well, if you can locate them among the thousand-odd rants. Actually the beauty of the post lies in the author not trying to be in preach-mode. It&#8217;s just a &#8220;screw it all I&#8217;m goin&#8217; home&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://iamelgringo.blogspot.com/2009/02/tables-vs-css-css-trolls-begone.html" target="_blank">Beautiful post</a> on removing CSS layout and going back to the good ol&#8217; table tag. The comments are good as well, if you can locate them among the thousand-odd rants.</p>
<p>Actually the beauty of the post lies in the author not trying to be in preach-mode. It&#8217;s just a &#8220;screw it all I&#8217;m goin&#8217; home&#8221; treatment handed out to <code>display:block; float:left;</code> layout, which has irked some gentlemen of the CSS church. For these kind-hearted people, the author takes some time out to coin a term CSS-Trolls. And could you believe it, the very same association of people replied on this post with complete disgust, on how terrible the advice is, and how the author ought to die of shame. Well, some comments were actually written by well-mannered folks, who put their point and signed off with a bow.</p>
<p>But let&#8217;s not talk on people. Let&#8217;s talk on the point in question. Tables or CSS?</p>
<p>Well it really doesn&#8217;t have to be an exclusive decision. CSS does provide a lot in terms of</p>
<ul>
<li>Flexibility in presentation</li>
<li>Easy alterations in future</li>
<li>Accessibility for visually impaired</li>
<li>Pixel-level control of all objects</li>
</ul>
<p>and other goodies. I&#8217;m a CSS fan ever since I built my first CSS-enabled website 3 years ago and realized how much I sucked in web design before.</p>
<p>Yet, CSS, with all its control on page components, remains a browser-based implementation. Wait, even tables are in the same league! Yes, but tables give you one assurance: If you want &#8220;Y&#8221; in the left cell and &#8220;Z&#8221; in the right, that&#8217;s how you are going to get it. No side effects with anything: pages resized, font sizes increased, browsers changed, you try it. It may look ugly, sucky design, but &#8220;Z&#8221; remains to the right of &#8220;Y&#8221;.</p>
<p>This one single feature of <strong>consistent </strong>placement gets screwed up when you try to use CSS. I sat with my friend once to get a layout with 3 columns, with a horizontal bar at the bottom of all three columns. Quite a number of times, the bar appeared on the right of the columns, sometimes behind the columns. It took us a good one hour to get things sorted out, after adding a multitude of attributes for the last column and for the horizontal bar. I can surmise that whatever attributes we used would produce at least some side effects in one of the browsers.</p>
<p>You can well say that I am not as good of a CSS coder as I think. Well, that&#8217;s the whole problem. The layout worked perfectly in one browser and it wouldn&#8217;t on others. Why does my knowledge on markup have to involve inconsistencies rendered by design specs of different browsers?</p>
<p>Lets take another example. A friend working in a UI framework team discussed an issue with me one day: The div appeared two pixels to the right of the desired location on FireFox, while it rendered at the perfect spot for IE. Now that&#8217;s an amazing problem, where the (heavy) component is derived from 5 other smaller units. Turned out to be a difference of rendering a border between FF and IE.</p>
<p>Coming out of bedtime stories, we have situations where &#8220;the boss wants the code complete by evening&#8221;. It is useless to sit and gaze at the beauty of CSS at times like these. Just get yourself some nice tables <strong>where necessary</strong>, use CSS <strong>where easy </strong>and roll it out, as <a href="http://www.teamlalala.com/blog/2009/02/05/15-of-the-top-20-websites-use-tables-for-layout/" target="_blank">many have preferred</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/02/the-evergreen-tables-vs-css-debate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>On automated prefetch</title>
		<link>http://blog.spathare.com/2009/02/on-automated-prefetch/</link>
		<comments>http://blog.spathare.com/2009/02/on-automated-prefetch/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 09:07:26 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[accelerator]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=86</guid>
		<description><![CDATA[Yesterday I happened to read a good bit of discussion which happened way back in 2005 on behavior of Google&#8217;s Web Accelerator and the trauma caused to websites. Although coming a little late to the party (3 years later), my post on Best Practices for GET and POST HTTP commands does answer some big questions [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I happened to read a <a href="http://www.37signals.com/svn/archives2/google_web_accelerator_hey_not_so_fast_an_alert_for_web_app_designers.php" target="_blank">good bit of discussion</a> which happened way back in 2005 on behavior of <a href="http://webaccelerator.google.com/" target="_blank">Google&#8217;s Web Accelerator</a> and the trauma caused to websites. Although coming a little late to the party (3 years later), my post on <a href="http://blog.spathare.com/2008/06/best-practices-for-using-http-get-and-post/" target="_blank">Best Practices for GET and POST HTTP</a> commands does answer some big questions which kept occurring in the discussion.</p>
<p>At first, a little introduction to the havoc wreaked by WebAccelerator: It sits with your browser, and &#8220;clicks&#8221; links intelligently on the page you have visited. This ensures that your next click opens the new page instantly. However, &#8220;intelligent&#8221; behavior started to trouble web applications where links happened to update/delete records in Admin Consoles.</p>
<p>Although the bigger question raised was regarding <a href="http://www.37signals.com/svn/archives2/gwa_shines_light_on_google_privacy_concerns.php" target="_blank">privacy concerns</a> (Google indexes pages prefetched by WebAccelerator, which includes pages unreachable by its crawlers), lets keep that out for a moment and revisit the issues faced by web developers. As Web Accelerator is no longer active, you may wonder why we need to recap history. The reason is, you never know what plugin the users of your app have installed on their browsers. Yesterday, it was Google. Tomorrow, it may be something smaller, having auto-installed with another package, and no one will have an idea that your pages are being prefetched.</p>
<p>As always, information websites with links sprinkled around do not need to bother about prefetch. Its the websites with user authentication required that mostly fell prey to this activity.</p>
<p>I&#8217;ve not tried GWA, and there are comments stating that GWA doesn&#8217;t do a lot of things which have been alleged. However, our work here is not to discuss merits of Web Accelerators and their conformance to standards. All we want to do is strengthen our own website. So lets take a look at some problems faced, and graceful solutions or workarounds opined.</p>
<p>1. <strong>&#8220;Logout&#8221; link prefetched once the user logged in:</strong> This threw the user out before he did any other activity. Quite irritating. The &#8220;Best Practices&#8221; supporters came out in strong defense of Google here. Why would developers keep Logout as a link (GET) and not a POST, they asked. Except that Logout is really an idempotent operation! A user can logout once or ten times, and it is always the same result, in almost all cases. Our little tweak to the Best Practices helps in deciding that POST is better for Logout.</p>
<blockquote><p>A safer deal is to have form method as GET when the application state does not change at all</p></blockquote>
<p>2. <strong>&#8220;Delete&#8221; links prefetched in Admin consoles: </strong>Well, this is pretty straightforward. You cannot have &#8220;Delete&#8221; as a GET operation. But here&#8217;s where we get out of utopia. In the real world, navigation and look and feel of the application is largely decided by the UI team, and the developer has little say in the matter. If the designers feel that links alongside 10 items feel &#8220;cool&#8221; and buttons don&#8217;t, well, you need to keep a link. The workaround here is to have <code>a href = "#"</code> and code a form submit on the <code>onclick</code> event of the link.</p>
<p>3. <strong>Links which involved heavy database operations</strong>: &#8230;and thus increased server load were prefetched. A way out here is to limit the number of &#8220;heavy&#8221; operations performed by a user per minute. This seems like a fair balance between a hack to redirect to 403 and a puritan approach of removing links altogether, making pages accessible only through Javascript or POST operations.</p>
<p>4. <strong>Links which retrieved data but also imposed exclusive locks on the data:</strong> The first user to come along could end up locking quite a bit of system data, thanks to prefetch operation. However, isn&#8217;t a lock on data change of application state? The change needn&#8217;t be in a database operation. Any change of state should require (scream) POST.</p>
<p>Well, that&#8217;s quite an interesting list of 4 points with repeated <em>gyaan</em> which has, no doubt, also been written  before by others. But, as long as reading this post helps at least one developer, I&#8217;m happy. Benefited developer, please post a comment so that I stay vindicated <img src='http://blog.spathare.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/02/on-automated-prefetch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript alert: Why block everything?</title>
		<link>http://blog.spathare.com/2009/01/javascript-alert-why-block-everything/</link>
		<comments>http://blog.spathare.com/2009/01/javascript-alert-why-block-everything/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 05:57:24 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[modal]]></category>
		<category><![CDATA[tabs]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=66</guid>
		<description><![CDATA[While posting about usability of alert, I was chatting with a friend who saw it not just as a minor nuisance, but a greater threat. Since alerts interfere in user activity in other tabs, we have a basic case of client side DoS, he said. After thinking about it, I&#8217;m inclined to agree. Older browsers [...]]]></description>
			<content:encoded><![CDATA[<p>While posting about usability of alert, I was chatting with a friend who saw it not just as a minor nuisance, but a greater threat. Since alerts interfere in user activity in other tabs, we have a basic case of client side DoS, he said.</p>
<p>After thinking about it, I&#8217;m inclined to agree.</p>
<p>Older browsers didn&#8217;t have this problem: they were not multi-tabbed. And window switching is certainly not disabled by any modal pop-ups.</p>
<p>Browsers evolved, tabs arrived. Today I have 15 tabs opened in my browser. And then say someone sends me a nicely obfuscated script which simplifies to this:</p>
<p><code>javascript:eval("for(i=0;i&lt;554;i++) alert(123)");</code></p>
<p>Works nicely in FireFox. Stops me from accessing other tabs altogether till I succumb to the pressure 554 times (and I might not even know the actual figure if its jumbled code)</p>
<p>And lets not forget that this error can be caused <em>without </em>malicious intent. Say some webpage gives out two or three alert messages in a loop, and the loop counter goes haywire because of a corner case which wasn&#8217;t tested. It still is a block on all activity in the browser, whether the user likes it or not.</p>
<p>I&#8217;m not saying this is some awesome loophole in browser security. But it certainly is more than an irritant if I&#8217;ve paid by credit card in another tab, and the site is waiting for me to perform the next step.</p>
<p>The graceful solution for this is to have dialog boxes modal with respect to <em>their own tab</em>. This satisfies all legacy requirements of an alert as well. Currently, browsers have just provided a knife to play with.</p>
<p><strong>Update: </strong>This problem has been <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=59314" target="_blank">reported in Mozilla as a bug</a>, verified as a FireFox DoS as early as November 2000.</p>
<blockquote><p>I think this is really a common problem for web-developers. I&#8217;ve fallen into this trap several times myself (accidentally created an infite loop around my debugging alert()). But instead of aborting all scripts, I&#8217;d like to have something similar to the &#8220;A script on this page is causing Mozilla to run slow&#8221; message with the option to abort the script.</p></blockquote>
<p>Another user writes:</p>
<blockquote><p>The page in the URL (don&#8217;t open it unless you know what you&#8217;re doing!) &#8220;locks&#8221; the user in an endless stream of JavaScript alerts. There is no way out; closing the popup just opens a new one; UI is unresponsive in *any* place except the popup; you can&#8217;t cancel the loading of the page (or do something like ESC to stop the script) since the UI is blocked by the popup. The perfect anti-Mozilla DoS.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/01/javascript-alert-why-block-everything/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Usability: Javascript alert() function</title>
		<link>http://blog.spathare.com/2009/01/usability-javascript-alert-function/</link>
		<comments>http://blog.spathare.com/2009/01/usability-javascript-alert-function/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 05:05:12 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[unobtrusive]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=61</guid>
		<description><![CDATA[Traditionally, the most convenient way for web developers to buzz the user with a message has been the javascript alert() pop-up. It is convenient to code and ensures that the user doesn&#8217;t miss the message (no way to go back to the page till the user clicks OK or whatever prompts you&#8217;ve coaxed in) Today [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally, the most convenient way for web developers to buzz the user with a message has been the javascript alert() pop-up. It is convenient to code and ensures that the user doesn&#8217;t miss the message (no way to go back to the page till the user clicks OK or whatever prompts you&#8217;ve coaxed in)</p>
<p><img title="Javascript alert" src="http://blog.spathare.com/wp-content/uploads/2009/01/alert.jpg" alt="Javascript alert" width="415" height="393" /></p>
<p>Today this very pop-up is a major hassle for users, just because in multi-tabbed interfaces, the user cannot switch between tabs when an alert is displayed to him. So you have an irritated user who wants to urgently book a flight in the next page, but is stuck on your tab because you have provided some text for him to understand and press OK.</p>
<p>This is still ok when the alert is shown on the press of a button. There is a higher probability of the user being still focussed on your page. But alerts on page load, notifying &#8220;Successfully performed operation&#8221; are nothing but rot.</p>
<p>To grab user attention <em>while user is on your page</em>, a far more elegant way is the use of div based message boxes. This keeps the user interface consistent with the remaining website and also grants user space for some other (possibly precious) activity. The new CSS opacity attributes also let you gray-out the page background whilst displaying your error &#8212; pretty neat.</p>
<p>While you are proceeding towards unobtrusive interfaces like a good kid, why not also give a thought to what ought to be the messages warranting a pop-up? <a href="http://www.oracle.com/technology/products/adf/index.html" target="_blank">Oracle ADF</a>, which we use for development, has 3 levels of messages:</p>
<ul>
<li><strong>Info, Warning:</strong> Display at the top of the page with appropriate icon</li>
<li><strong>Error:</strong> Display as a div based pop-up to the user, gray out the remaining page, ensuring the user cannot perform any activity till he selects an option to handle or acknowledge the error.</li>
</ul>
<p>The good part is that the behavior of messages is built into the framework. So if tomorrow a usability test suggests that warning messages better be shown as a popup so the user doesn&#8217;t miss them, there&#8217;s a 3 line change in the framework to enable this. Clean, easy, cool. That&#8217;s the way we want it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2009/01/usability-javascript-alert-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The best of CSS3&#8230; together</title>
		<link>http://blog.spathare.com/2008/11/the-best-of-css3-together/</link>
		<comments>http://blog.spathare.com/2008/11/the-best-of-css3-together/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 13:53:03 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[rounded corner]]></category>
		<category><![CDATA[shadow]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=46</guid>
		<description><![CDATA[Opacity, Shadow and Rounded-corner control over rendered objects make CSS3 exciting stuff. Imagine creating a beautiful website with all these features, without using an image editing program! (ok, throw in @font-face and you have the font of your choice on the webpage as well. That&#8217;s it. Image editing is out) Its safe to assume that [...]]]></description>
			<content:encoded><![CDATA[<p>Opacity, Shadow and Rounded-corner control over rendered objects make CSS3 exciting stuff. Imagine creating a beautiful website with all these features, without using an image editing program! (ok, throw in @font-face and you have the font of your choice on the webpage as well. That&#8217;s it. Image editing is out)</p>
<p>Its safe to assume that not all developers will be using these features for mainstream websites unless our very dear IE supports them. So we still have time to see these beauties in action. But we have a lot of gray area for what happens when these are used together. The implementations are still juggling with these questions.</p>
<p>For example, what happens when opacity of a box is 50% and a drop-shadow attribute is used for the box? Or, what happens when a shadow drops on a box which is having less opacity? Should the shadow have rounded corners for a box with rounded corners? How should a shadow with bigger fade (black to transparent area) render on a shadow with smaller fade?</p>
<p>These are just some tricky &#8220;beginner&#8221; questions with no straight answers. Fortunately the community is pretty enthusiastic about rendering these effects with markup. Lot of such issues and fundamentals <a href="http://www.css3.info/css-drop-shadows/" target="_blank">have been discussed</a>.</p>
<p>In an image editor you can manipulate the effect rendered depending on which operation you perform first. This is not really clear for CSS, and with browser implementations which can vary, it might be a bit of a hassle for us to have consistent cross-browser CSS3 markup ready to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2008/11/the-best-of-css3-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Byte and Char differences in Java</title>
		<link>http://blog.spathare.com/2008/07/byte-and-char-differences-in-java/</link>
		<comments>http://blog.spathare.com/2008/07/byte-and-char-differences-in-java/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 05:20:18 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[streams]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=24</guid>
		<description><![CDATA[For I/O newbies in Java, the big question comes is which of the methods are to be used for I/O read/write. Anyway, unlike some other languages, Java insists on using the &#8220;explicit&#8221; way of coding: Code for Python (Write to file) f=open('scratch','wb') for i in xrange(1000000): f.write(str(i)) f.close() Code for Java (Write to file) File [...]]]></description>
			<content:encoded><![CDATA[<p>For I/O newbies in Java, the big question comes is which of the methods are to be used for I/O read/write. Anyway, unlike some other languages, Java insists on using the &#8220;explicit&#8221; way of coding:</p>
<blockquote><p><strong>Code for Python (Write to file)</strong><br />
<code><br />
f=open('scratch','wb')<br />
for i in xrange(1000000):<br />
f.write(str(i))<br />
f.close()</code></p>
<p><strong>Code for Java (Write to file)</strong></p>
<p><code>File f = new File("scratch");<br />
PrintWriter ps = new PrintWriter(new OutputStreamWriter<br />
(new FileOutputStream(f)));<br />
for (int i = 0; i &lt; 1000000; i++) {<br />
ps.print(String.valueOf(i));<br />
}<br />
ps.close();</code></p></blockquote>
<p>Discounting the mandatory include statements for java.io, class name, try catch block for any and all I/O operations, we are still left with around 4 classes to be used for 1 write operation to a file.</p>
<p>So the question newbie posts in a forum is: I am writing to a file, but I&#8217;m not sure whether I should use BufferedOutputStream or BufferedWriter</p>
<p>The reply generally holds this: If you are inserting chars, use a Writer, else use the Stream</p>
<p>This is fairly accurate, but for a slightly deeper understanding let us break down the modules</p>
<p><img class="alignnone size-full wp-image-34" title="writer_when" src="http://blog.spathare.com/wp-content/uploads/2008/09/writer_when.jpg" alt="When to use Writer object" width="400" height="640" /></p>
<p>Streams transfer bytes. Period.</p>
<p>So when you want to transfer <strong>any</strong> binary data, you use streams. You open the file, wrap it with FileInputStream, take out the data and process it. When you save it back, you make use of the FileOutputStream. <a href="http://www.telecom.ntua.gr/HTML.Tutorials/java/io/overview.html" target="_blank">Similar classes</a> to be used for transferring though other streams.</p>
<p>In case you would like to use some text-friendly methods for your ascii text, you need chars or a char[] array. To get this, you convert bytes to chars while reading (and similarly chars to bytes while writing), with a simple wrapper, which happens to be InputStreamReader for reading and OutputStreamWriter for writing.</p>
<p>To have data formatting conversion done by Java, wrap the Writer objects in a PrintWriter</p>
<p>To increase performance, you wrap the objects in a buffer. Java uses internally allocated memory space to provide efficient read/write operations. The working of the buffer is transparent to the programmer, except for few methods like flush()</p>
<p>(Any) OutputStream =&gt; (wrap in) BufferedOutputStream</p>
<p>(Any) InputStream =&gt; (wrap in) BufferedInputStream</p>
<p>(Any) Writer =&gt; (wrap in) BufferedWriter</p>
<p>(Any) Reader =&gt; (wrap in) BufferedReader</p>
<p>The Buffer classes also provide some friendly methods: readLine() in BufferedReader and write(String, int, int) in BufferedWriter. These are more of a convenience which can be coded anyway in 2-3 lines. In case your app can&#8217;t afford to wait for the buffer to get full before transmitting or receiving data, it is always better to avoid using Buffers than to use and flush() them throughout your program.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2008/07/byte-and-char-differences-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best practices for using HTTP GET and POST</title>
		<link>http://blog.spathare.com/2008/06/best-practices-for-using-http-get-and-post/</link>
		<comments>http://blog.spathare.com/2008/06/best-practices-for-using-http-get-and-post/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 20:36:19 +0000</pubDate>
		<dc:creator>Swapnil Pathare</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://blog.spathare.com/?p=23</guid>
		<description><![CDATA[Everyone who builds even the tiniest webapps has used a form submit. This involves (even if one uses flash, or any other front-end) use of http GET or http POST method to get the information from browser back to the server, where one can writhe and wrestle with it all one wants. The big question [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone who builds even the tiniest webapps has used a form submit. This involves (even if one uses flash, or any other front-end) use of http GET or http POST method to get the information from browser back to the server, where one can writhe and wrestle with it all one wants.</p>
<p>The big question often happens to be which method to use. The basic wisdom you get from the guy in the next cubicle (or <a href="http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/iisbook/c06_the_difference_between_get_and_post.mspx?mfr=true" target="_blank">from Microsoft</a>) is</p>
<blockquote><p>The GET method[...] appends name/value pairs to the URL. Unfortunately, the length of a URL is limited, so this method only works if there are only a few parameters. The URL could be truncated if the form uses a large number of parameters, or if the parameters contain large amounts of data.</p>
<p>Also, parameters passed on the URL are visible in the address field of the browser. Not the best place for a password to be displayed.</p></blockquote>
<p>As always, there are some more things one ought to know as a responsible developer to get this distinction correct. Firstly the definition as per the <a href="http://www.w3.org/MarkUp/html-spec/html-spec_toc.html" target="_blank">HTML specification</a> (which is extremely useful)</p>
<blockquote>
<p style="margin: 0pt;">If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the world), then the form method should be <code>GET</code>. Many database searches have no visible side-effects and make ideal applications of query forms.</p>
<p style="margin: 0pt;">
<p style="margin: 0pt;">If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be <code>POST</code>.</p>
</blockquote>
<p>The keyword &#8220;idempotent&#8221; says a lot. If the state of your application does not change with the number of times a request is sent with a parameter (set salary of X as 10,000 bucks) then the operation is idempotent.</p>
<p>A safer deal is to have form method as GET when the application state does not change at all (search for text in a file or database).</p>
<p>We will look at other practical differences between the two methods which further influence our choice (some of them are already covered by Microsoft. Yay!)</p>
<p>I attempt a tabular distinction below. Lets hope it is clear enough.</p>
<table style="font-size: inherit" border="1" cellspacing="0" cellpadding="5" width="90%">
<tbody>
<tr>
<th width="50%">Http GET</th>
<th width="50%">Http POST</th>
</tr>
<tr>
<td style="font-size: inherit">Encodes form parameters into URL(example:</p>
<p>http://mysite.com/mypg?key1=val1&amp;key2=val2)</td>
<td style="font-size: inherit">Sends form fields to server without encoding them in URL</td>
</tr>
<tr>
<td style="font-size: inherit">Has <a href="http://jacobfogg.blogspot.com/2008/03/upper-limits-of-query-string.html" target="_blank">limited width</a><br />
FF2 : 8182 bytes<br />
Safari 2 : 8184 bytes<br />
IE7 : 2057 bytes</td>
<td style="font-size: inherit">No upper limit for transfer</td>
</tr>
<tr>
<td style="font-size: inherit">Can enable encoding of form only as <code>application/x-www-form-urlencoded</code>. No binary data / files can be sent</td>
<td style="font-size: inherit">Can encode form values as <code>multipart/form-data</code> or <code>application/x-www-form-urlencoded.</code> The former encoding enables users to transfer files to server.</td>
</tr>
<tr>
<td style="font-size: inherit">Page targeted can be bookmarked, since bookmark just remembers the complete URL</td>
<td style="font-size: inherit">A big NO for bookmark, since the page is influenced by some parameters sent specifically by POST method.**</td>
</tr>
<tr>
<td style="font-size: inherit">Values in hidden and password fields will be shown in the address bar of browser, as a result of everything being appended in URL</td>
<td style="font-size: inherit">That&#8217;s not gonna happen here</td>
</tr>
<tr>
<td style="font-size: inherit">Sending non-ASCII characters isn&#8217;t quite reliable</td>
<td style="font-size: inherit">All character sets are safely sent where proper encoding is used</td>
</tr>
</tbody>
</table>
<p>Some more detail on this with additional perspective is available <a href="http://www.w3.org/2001/tag/doc/whenToUseGet.html" target="_blank">here</a> and <a href="http://www.cs.tut.fi/~jkorpela/forms/methods.html#exc" target="_blank">here</a>. Some perspective from grandmother&#8217;s viewpoint is available <a href="http://graysmatter.codivation.com/MyGrandmotherAndTheDifferenceBetweenHTTPGETAndHTTPPOST.aspx" target="_blank">here</a> <img src='http://blog.spathare.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<hr />** Unless the page is rendered independent of transferred parameters, which for all practical apps is not the case</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spathare.com/2008/06/best-practices-for-using-http-get-and-post/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

