<?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>uxebu » blog &#187; browser</title>
	<atom:link href="http://uxebu.com/tag/browser/feed/" rel="self" type="application/rss+xml" />
	<link>http://uxebu.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 14:53:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>HumanApi &#8211; the browser in the real world</title>
		<link>http://uxebu.com/blog/2010/01/25/humanapi-the-browser-in-the-real-world/</link>
		<comments>http://uxebu.com/blog/2010/01/25/humanapi-the-browser-in-the-real-world/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 14:32:06 +0000</pubDate>
		<dc:creator>nonken</dc:creator>
				<category><![CDATA[frontend engineering]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[humanapi]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=922</guid>
		<description><![CDATA[During the Oredev speakers dinner last November, I was having an interesting discussion about the car industry and how Google in one swipe mangled up the turn-to-turn navigation market. During this discussion and other interesting conversations at the following JsConf, it it became more and more clear that we (web developers) should be able to [...]]]></description>
			<content:encoded><![CDATA[<p>During the <a href="http://www.oredev.org" target="_blank">Oredev</a> speakers dinner last November, I was having an interesting discussion about the car industry and how Google in one swipe mangled up the turn-to-turn navigation market. During this discussion and other interesting conversations at the following <a href="http://jsconf.eu">JsConf</a>, it it became more and more clear that we (web developers) should be able to write applications for instance for cars, write applications for phones we can plug into cars, and write those applications using web technologies &#8211; meaning JavaScript, HTML and CSS. </p>
<p><span id="more-922"></span></p>
<p>Since that discussion, the idea developed further and after some time, things started to take shape. </p>
<p>Lets take a look at the first prototype of a web based application (is this the first JavaScript ECG ever?) which reads your heart rate, sends it to the mobile phone via bluetooth and displays it in a native application driven by PhoneGap, meaning &#8211; the actual application is written using JavaScript, HTML(5), CSS.</p>
<div style="text-align: center; margin: 40px; 0">
<object width="500" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8915705&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8915705&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="375"></embed></object>
</div>
<p>Because the quality of the above video isn&#8217;t that good I have recorded a screencast from the iPhone simulator. This video only shows the applications look and feel since the simulator is not connected to the Polar hardware via Bluetooth.</p>
<div style="text-align: center; margin: 40px; 0">
<object width="300" height="514"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8849502&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8849502&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="300" height="514"></embed></object>
</div>
<p><a href="http://humanapi.org/category/videos/">More videos are available here</a></p>
<p>After I got a first prototype running, the thoughts of what this could potentially mean would not stop popping up in my mind &#8211; the consequences for the web-development community are immense and the challenges we as web developers can face are broadened in a way that tons of exciting new things are lying ahead of us.</p>
<p>In this blogpost I will give you a quick outline the features of this prototype and the components I used.</p>
<h2>Setup</h2>
<p>To get the HumanApi ECG running I used following components:</p>
<ul>
<li><a href="http://phonegap.com">PhoneGap</a></li>
<li><a href="http://apple.com/iphone">iPhone</a></li>
<li><a href="http://www.polarusa.com/us-en/products/accessories/T31_coded_Transmitter">Polar T31</a></li>
<li><a href="http://arduino.cc/en/Main/ArduinoBoardBluetooth">Arduino BT</a></li>
<li><a href="http://danjuliodesigns.com/sparkfun/sparkfun.html">HRMI</a></li>
<li><a href="http://code.google.com/p/btstack/">btstack</a></li>
<li>little stuff</li>
</ul>
<p>Lets take a quick look at each of the components:</p>
<h2>PhoneGap</h2>
<p><a href="http://phonegap.com">PhoneGap</a> is one of the really cool projects out there. It not only allows you to deploy JS, HTML and CSS based applications on a range of mobile phones but it also gives you great APIs to access features of the phone. Because the iPhone SDK allows us to evaluate JavaScript from within Objective C it is relatively simple to execute JavaScript calls within the webkit webview. This essentially allows you to communicate with for instance bluetooth. If more widget runtimes would give us possibilities to inject APIs into the runtime (W3C?) and make available in JavaScript we would be able to write very cool apps! (More on that in a different blogpost soon).</p>
<h2>iPhone</h2>
<p>besides the fact that Apple is blocking certain functionality of the phone (bluetooth for instance), it is an amazing device and allows you to do all kinds of stuff (e.g. inject JS into the webkit view). Its performance is very good as well and therefor makes a great prototyping device. To get this HumanApi prototype running I unfortunately had to jailbreak the device. We are slowly reaching a point in time where blocking device functionality will hurt Apple and other manufacturers/operators, they are locking their devices out from an amazing amount of possible application usecases.</p>
<h2>Polar T31</h2>
<p><a href="http://www.polarusa.com/us-en/products/accessories/T31_coded_Transmitter">The Polar T31</a> is a simple heart rate transmitter which you can use to monitor your heart rate when doing sports. This device is perfect for our prototype because we indirectly can send the data to our iPhone.</p>
<h2>Arduino BT</h2>
<p>Because I can not communicate between the iPhone and the Polar T31 directly I had to create a bridge using the <a href="http://arduino.cc/en/Main/ArduinoBoardBluetooth">Arduino BT</a>. Essentially the Arduino receives the heart rate (using the HRMI) from the T31 and sends it to my iPhone via bluetooth.</p>
<h2>HRMI</h2>
<p>The <a href="http://danjuliodesigns.com/sparkfun/sparkfun.html">human heart rate interface</a> is a great little project by Dan Julio, who developed this hardware to receive the heart rate signal from the T31. Furthermore you can easily connect the HRMI to the Arduino BT and therefore send the heart rate to your iPhone via bluetooth.</p>
<h2>btstack</h2>
<p>As I wrote before, Apple does not allow to access the full bluetooth stack on the device &#8211; even though the hardware is available. Luckily <a href="http://code.google.com/p/btstack/">Matthias Ringwald</a> has developed a library for the iPhone which lets you access the different bluetooth profiles &#8211; without his amazing work this HumanApi prototype never would have been able to exist.</p>
<h2>Your own HumanApi</h2>
<p>If you want to develop your own application accessing hardware, feel free to contribute to the HumanApi project. There would be nothing more amazing than seeing for instance the ECG app running on Andriod and other platforms. </p>
<p>A good start are the <a href="http://humanapi.org">articles on humanapi.org</a>, the <a href="http://groups.google.com/group/humanapi">forum</a>, the <a href="http://github.com/nonken/humanapi">GIT repository</a> or these folks on twitter: <a href="http://twitter.com/nonken">@nonken</a>, <a href="http://humanapi.org">@humanapi</a>, <a href="http://twitter.com/uxebu">@uxebu</a>. </p>
<h2>Conclusion</h2>
<p>Essentially we are at a point where we as JavaScript developers could be writing applications we never thought of a few years ago. It is to us and to the industry now to demand that we get better and more access to the devices hardware &#8211; there is no reason why JavaScript developers get &#8220;discriminated&#8221; over native developers in the way how we can access device features</p>
<p><strong>I want to close this article with a short comparison:</strong></p>
<p>Often mobile developers, using web technologies, are compared to native developers on the example of games. &#8220;Ohhh but you can not write amazing 3D games using JavaScript&#8221; &#8211; funnily enough I even hear JavaScript developers trying to &#8220;defend&#8221; themselves agreeing to the above stated fact &#8211; &#8220;Yes we can&#8217;t write games, but phones are getting better so one day we will&#8221;. </p>
<p>We don&#8217;t need to make these kind of comparisons and should start demanding better access to the devices hardware. What stops us from saying &#8220;We don&#8217;t have to develop games, we can write home automation systems, medical applications (<a href="http://twitter.com/#search?q=mhealth">#mhealth</a>), apps for the cars industry and so much more amazing stuff &#8211; and we can do it cross platform! (And WebGL is on its way btw. ;) )&#8221;? </p>
<p>Right now it is not the language which is stopping us. App store policies, manufacturers and operators are stopping us because we have to hack our way into the devices! </p>
<p>Enjoy hacking</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2010/01/25/humanapi-the-browser-in-the-real-world/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS 3 Support in Mobile Runtimes</title>
		<link>http://uxebu.com/blog/2009/11/27/css3-support-in-mobile-runtimes/</link>
		<comments>http://uxebu.com/blog/2009/11/27/css3-support-in-mobile-runtimes/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 21:49:20 +0000</pubDate>
		<dc:creator>David Aurelio</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[frontend engineering]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=663</guid>
		<description><![CDATA[In a recent project a client asked for boxes with rounded corners and filled with a gradient; within an application targeted at smartphones. On mobile devices it is important to keep things simple, for instance to keep the number of DOM nodes low. That rules out using additional elements for the corners. On the other hand, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/box-rounded-corners-gradient.png"><img class="alignright size-full wp-image-732" title="Box with rounded corners and filled with a gradient" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/box-rounded-corners-gradient.png" alt="Box with rounded corners and filled with a gradient" width="224" height="224" /></a>In a recent project a client asked for boxes with rounded corners and filled with a gradient; within an application targeted at smartphones.</p>
<p>On mobile devices it is important to keep things simple, for instance to keep the number of DOM nodes low. That rules out using additional elements for the corners. On the other hand, many mobile devices are featuring recent versions of web rendering engines. Dive into CSS 3.</p>
<p>Modern web development techniques offer a lot of possibilities to render boxes with rounded corners: e.g. border-radius, border-image, or SVG used as background. In this post I’m going to explore the support for them across different devices and runtime environments. <a href="/2009/11/27/css3-support-in-mobile-runtimes/#result-table">You can skip to the results table</a> if all you want is a quick overview.</p>
<p>As stated above, I want to achieve a box with rounded corners and a gradient that reaches from top to bottom, scaling to the height of the box. The example might be simple, but it is representing a common design goal.</p>
<p><span id="more-663"></span></p>
<h4>State of affairs</h4>
<p>As of today, several possibilities exist to develop applications for mobile devices using web technologies. Besides Palms <a href="http://en.wikipedia.org/wiki/WebOS">webOS</a>, <a href="http://phonegap.com/">PhoneGap</a> permits to develop cross-platform applications with JavaScript, HTML, and CSS for the iPhone, Android, Blackberry, Windows Mobile, and Nokia WRT (support for webOS is upcoming). On Nokia devices there are two frameworks to create applications with web technologies: the built-in <a href="http://www.forum.nokia.com/Technology_Topics/Web_Technologies/Web_Runtime/">Nokia Web Runtime Widgets</a> (Nokia WRT) and Opera-based <a href="http://widget.vodafone.com/dev/">Vodafone Apps Manager</a>, which provides a runtime for <a href="http://www.quirksmode.org/blog/archives/2009/04/introduction_to.html">W3C Widgets</a> (heads up! Vodafone Apps Manager is WebKit-based on the Vodafone 360 H1/M1 devices, to complicate development a little bit).</p>
<p>While these runtimes provide the means to build applications using well-known technology to web developers, they also bring well-known problems to the mobile sphere: inconsistencies between rendering engines. Even though most of those runtimes are WebKit-based (with the exception of Vodafone Apps Manager), <a href="http://www.quirksmode.org/blog/archives/2009/10/there_is_no_web.html">there is no [single] Webkit on Mobile</a>, as PPK has pointed out. <a href="http://www.quirksmode.org/webkit.html">His comparison table</a> shows the results of testing for various JavaScript and CSS features.</p>
<p>Freed from the burden of “making things work in IE” we can start using advanced CSS features to build interfaces for mobile applications – but hold on, it’s not as easy as desired. Due to the differences in capabilities of rendering engines and their versions, using CSS 3 features needs a lot of testing.</p>
<h4>Test Setup</h4>
<p>To keep things simple in the beginning, I’ve tested on two devices: a <em>Nokia 5800 XpressMusic</em> and a <em>Nokia N97 </em>(it might have played a role that I had those two at hand when writing the article ;-)</p>
<p><em></em>Both devices support Nokia WRT apps natively and W3C Widgets via Vodafone Apps Manager. <a href="http://static.uxebu.com/~david/css-support-in-mobile-runtimes/">The HTML file</a> consists of boxes with different set of CSS properties. I’ve uploaded the packaged <a href="http://static.uxebu.com/~david/css-support-in-mobile-runtimes/css3.wgz">Nokia WRT Widget</a> and the <a href="http://static.uxebu.com/~david/css-support-in-mobile-runtimes/css3.wgt">W3C Widget</a>, too. You can test them for yourself on your Nokia, if you like.</p>
<p>On the <em>5800,</em> Nokia WRT is based on WebKit build 413 (which correlates roughly to Safari 2.0), the installed Vodafone Apps Manager uses Opera Mobile build 1265. The <em>N97</em> uses Webkit build 525 (introduced with Safari 3) and Opera Mobile build 1360.</p>
<p>Because the two devices show no differences in rendering (with one exception), all screenshots have been taken on the N97 with the exception of one rendering bug found on the 5800. All other rendering differences are existing between runtimes only.</p>
<h4>Test Results</h4>
<h5>Result table</h5>
<p>The result table provides a quick overview about the tested features and platforms. Detailed descriptions of the single tests can be found below.</p>
<table id="result-table" border="0">
<thead>
<tr>
<td></td>
<th scope="row">Nokia WRT</th>
<th scope="row">Vodafone Apps Manager</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">border-radius</th>
<td>yes, but not useful *</td>
<td>no</td>
</tr>
<tr>
<th scope="row">border-image</th>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<th scope="row">CSS gradients</th>
<td>no</td>
<td>no</td>
</tr>
<tr>
<th scope="row">SVG background images</th>
<td>no</td>
<td>yes, with rendering bug **</td>
</tr>
<tr>
<th scope="row">box-shadow</th>
<td>no</td>
<td>no</td>
</tr>
<tr>
<th scope="row">opacity</th>
<td>no</td>
<td>yes</td>
</tr>
<tr>
<th scope="row">CSS transitions</th>
<td>no</td>
<td>no</td>
</tr>
</tbody>
</table>
<p><small>* background overlaps border, blurry border on the N97, circular artifacts on the 5800</small><br />
<small>** SVG backgrounds stop being rendered after the corresponding element is scrolled out of the viewport</small></p>
<h5>Cases 1/2: Simple Box</h5>
<div class="wp-caption aligncenter" style="width: 550px">
<div class="mhx"><a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000002.png"><img class="size-medium wp-image-683 " title="Boxes 1 and 2 on Nokia WRT" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000002-168x300.png" alt="Boxes 1 and 2 on Nokia WRT" width="168" height="300" /></a> <a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000007.png"><img class="size-medium wp-image-688 " title="Boxes 1 and 2 on Vodafone Apps Manager" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000007-168x300.png" alt="Boxes 1 and 2 on Vodafone Apps Manager" width="168" height="300" /></a></div>
<p><p class="wp-caption-text">Boxes 1 and 2 on Nokia WRT/Vodafone Apps Manager</p></div>
<p><em>Case 1</em> simply uses a <code class="codecolorer text mac-classic"><span class="text">border</span></code> and a <code class="codecolorer text mac-classic"><span class="text">background-image</span></code>:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#b0b0b0</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #933;">-15px</span> <span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#4a4a4a</span><span style="color: #00AA00;">;</span></div></td></tr></tbody></table></div>
<p>This renders equally well on both platforms, but is not very similar to what I want to achieve: The background gradient is barely visible, because the image used is fairly high and does not scale with the height of the box.</p>
<p><em>Case 2</em> is a little bonus, as it does not relate to box styling: it tests for support of CSS transitions. By clicking the box, the class “clicked” is added or removed. In rendering engines supporting CSS transition the width of the box will be changed smoothly. Neither Nokia WRT nor Vodafone Apps Manager support them, though.</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.transition</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; transition-property<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; transition-duration<span style="color: #00AA00;">:</span> 250ms<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -webkit-transition-property<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -webkit-transition-duration<span style="color: #00AA00;">:</span> 250ms<span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.transition</span><span style="color: #6666ff;">.clicked</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#0f0</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">270px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h5>Cases 3/4: border-radius and border-image</h5>
<div class="wp-caption aligncenter" style="width: 550px">
<div class="mhx"><a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000003.png"><img class="size-medium wp-image-684" title="Boxes 3 and 4 on Nokia WRT" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000003-168x300.png" alt="Boxes 3 and 4 on Nokia WRT" width="168" height="300" /></a> <a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000008.png"><img class="size-medium wp-image-689" title="Boxes 3 and 4 on Vodafone Apps Manager" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000008-168x300.png" alt="Boxes 3 and 4 on Vodafone Apps Manager" width="168" height="300" /></a> <a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/5800-border-radius.jpg"><img class="size-medium wp-image-697  " title="border-radius on the Nokia 5800 XpressMusic" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/5800-border-radius-300x245.jpg" alt="border-radius on the Nokia 5800 XpressMusic" width="180" height="147" /></a></div>
<p><p class="wp-caption-text">Boxes 3 and 4 on Nokia WRT/Vodafone Apps Manager,border-radius on the Nokia 5800 XpressMusic</p></div>
<p>The <em>third test</em> adds <code class="codecolorer text mac-classic"><span class="text">border-radius</span></code> to the CSS declaration. This comes closer to the styling goal, but is not usable on both platforms: While it’s not rendered at all in the Opera-based Vodafone Apps Manager, the older WebKit engines of the 5800’s Nokia WRT adds circular artifacts to the corner, and the background overlaps the border on the N97. In addition, the border drawing is blurry on the N97 as soon as <code class="codecolorer text mac-classic"><span class="text">border-radius</span></code> is added to the declarations.</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span><br />
-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span><br />
-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span></div></td></tr></tbody></table></div>
<p><em>Case 4</em> uses the same background image, but as <code class="codecolorer text mac-classic"><span class="text">border-image</span></code>. Again, Opera doesn’t support the property, but the WebKit-based Nokia WRT displays the box as intended: Sharp border, rounded corners, gradient from top to bottom. (Note: in contrast to the label on the box, the background property is set to white in this example).</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.border-img</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -webkit-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -moz-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>Interestingly, the WRT application crashes, when the combined offset/border-width syntax (e.g. <code class="codecolorer text mac-classic"><span class="text">-webkit-border-image: url(box.png) 15/15px stretch</span></code>).</p>
<h5>Cases 5/6: Gradients and SVG</h5>
<div class="wp-caption aligncenter" style="width: 550px">
<div class="mhx"><a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000004.png"><img class="size-medium wp-image-685" title="Boxes 5 and 6 on Nokia WRT" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000004-168x300.png" alt="Boxes 5 and 6 on Nokia WRT" width="168" height="300" /></a> <a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000009.png"><img class="size-medium wp-image-690" title="Boxes 5 and 6 on Vodafone Apps Manager" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000009-168x300.png" alt="Boxes 5 and 6 on Vodafone Apps Manager" width="168" height="300" /></a></div>
<p><p class="wp-caption-text">Boxes 5 and 6 on Nokia WRT/Vodafone Apps Manager</p></div>
<p>The <em>fifth box</em> uses a different approach for styling the box: It uses a browser-rendered gradient (<code class="codecolorer text mac-classic"><span class="text">&lt;a href=&quot;http://webkit.org/blog/175/introducing-css-gradients/&quot;&gt;-webkit-gradient&lt;/a&gt;</span></code>) for the background:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span><br />
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> from<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#666661</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> to<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#b0b0b0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> from<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#666661</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> to<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#b0b0b0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></div></td></tr></tbody></table></div>
<p>Support for gradients in WebKit was introduced in april 2008, but is not supported on the Nokias. As expected, it doesn’t work in opera, either.</p>
<p><em>Case 6</em> uses a SVG as background-image which always scales to the available width and height. <a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/">This technique has been described more than two years ago for Opera</a>, and works well in Opera based environments. Even though this example doesn’t make use of CSS 3 , only Opera seems to be able to use SVG graphics as background images as of today. This holds true for browsers with built-in SVG rendering capabilities, too.</p>
<h5>Cases 7/8/9: Cross-Platform Solution and Advanced Features</h5>
<div class="wp-caption aligncenter" style="width: 550px">
<div class="mhx"><a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000005.png"><img class="size-medium wp-image-686" title="Boxes 7 and 8 on Nokia WRT" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000005-168x300.png" alt="Boxes 7 and 8 on Nokia WRT" width="168" height="300" /></a> <a href="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000010.png"><img class="size-medium wp-image-691" title="Boxes 7 and 8 on Vodafone Apps Manager" src="http://hub.uxebu.com:33550/wp-content/uploads/2009/11/screen000010-168x300.png" alt="Boxes 7 and 8 on Vodafone Apps Manager" width="168" height="300" /></a></div>
<p><p class="wp-caption-text">Boxes 7 and 8 on Nokia WRT/Vodafone Apps Manager</p></div>
<p><em>Examples 7 and 8</em> represent the attempt to combine the approaches from boxes #4 and #6: They use an <a href="http://static.uxebu.com/~david/css-support-in-mobile-runtimes/box.svg">SVG</a> <code class="codecolorer text mac-classic"><span class="text">background-image</span></code> and a <a href="http://static.uxebu.com/~david/css-support-in-mobile-runtimes/box.png">pixel graphic</a> as <code class="codecolorer text mac-classic"><span class="text">border-image</span></code>:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.svg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">-15px</span> <span style="color: #933;">-15px</span> <span style="color: #993333;">repeat</span><span style="color: #00AA00;">;</span><br />
border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span><br />
-webkit-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span><br />
-moz-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">box.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">15</span> stretch<span style="color: #00AA00;">;</span></div></td></tr></tbody></table></div>
<p>Because both WebKit and Presto (Opera’s rendering engine) only support <em>one</em> of the approaches, the box renders fine in both engines (also, border images always lay on top background images).</p>
<p>This would be a perfect cross-platform solution, if Vodafone Apps Manager wouldn’t show a nasty bug: The first time boxes with an SVG background are scrolled into the viewport, they are rendered properly. As soon as all boxes using the same SVG are scrolled out of the viewport, and then scrolled in again, the SVG won’t display any longer. I’ve added a video showing this behavior.</p>
<p><object width="500" height="281" data="http://vimeo.com/moogaloop.swf?clip_id=7814078&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7814078&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" /></object></p>
<p><em>Case 8</em> just adds <code class="codecolorer text mac-classic"><span class="text">opacity</span></code> to the boxes, which is only supported in Opera, but slows down scrolling noticeable. <em>Case 9</em> tests for support of <code class="codecolorer text mac-classic"><span class="text">box-shadow</span></code>, which is not supported by any of the runtimes used in this test.</p>
<h4>Conclusion</h4>
<p>In our small test, we actually found a solution that runs in both WebKit and Presto. Sadly, this solution is only viable if the box <strong>isn’t ever scrolled out of the viewport.</strong> The rendering problems affecting the solution can only be found in mobile versions of the rendering engines tested.</p>
<p>That means, support of a certain feature in the desktop version of a browser does not imply bug-free support in mobile versions. Drawing can be fuzzy or faulty. Examples are <code class="codecolorer text mac-classic"><span class="text">border-radius</span></code> in older Nokia WRT releases or the SVG rendering bug in Vodafone Apps Manager.</p>
<p>Despite the fact we don’t have to deal with “legacy rendering engines” on mobile devices, it is not possible to rely on modern features like SVG graphics or CSS 3 yet. Due to many forks of WebKit, and Operas restraint in implementing CSS 3 features, each usage of such features should be <strong>thoroughly tested</strong> across all different target platforms. Write code your device can handle, don’t try to bend the browser.</p>
<p>Another problem are slow rendering speeds on mobile devices. It might be impossible  to use certain features, just because animations and scrolling get choppy, thus killing the snappiness of the user interface.</p>
<h4>The Future</h4>
<p>The newest version of Operas rendering engine, Presto 2.4 is already in beta state for mobile devices with <a href="http://dev.opera.com/articles/view/opera-mobile-10-beta-developers-introduction/">Opera Mobile 10</a> (while the newest desktop version still uses Presto 2.2), and <a href="http://www.opera.com/docs/specs/presto23/">adds support for many CSS 3 features</a> like border-radius, border-image, background-size, and CSS transitions. This will enable us to use all of the techniques that have been shown for WebKit in this post (border images, border radius, and box shadow). Using a combination of background-image, background-size, and border-image could provide a solution that degrades gracefully on older devices.</p>
<p>Also, CPU and rendering power of mobile devices will increase in the next years, providing faster rendering of HTML/CSS with smooth animations.</p>
<p>Thanks to the fact that developers don’t have to account for the market leader, the mobile browser/rendering engine market evolves way faster than the desktop browser market does. I am excited about the possibilities we have today and looking forward to the possibilities we’re going to have after the next releases of browsers an built-in rendering engines.</p>
<h4>To Do</h4>
<p>The plan is to make the tests more complete. One the one hand that means adding tests (e.g. the current test series lacks a test for -webkit-/-o-background-size, which would allow to scale the background image with the size of the box). Another interesting topic is support for CSS transitions.</p>
<p>On the other hand I would like to deploy the tests on as many platforms as possible. The next steps could cover packaging for platforms supported through PhoneGap and webOS.</p>
<p>If you would like to see a certain feature tested, I would appreciate a comment very much. <a href="http://twitter.com/void_0">Follow me on Twitter (void_0)</a> to be kept up-to-date about my random findings in the mobile web dev sphere.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2009/11/27/css3-support-in-mobile-runtimes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Some for-loop considerations</title>
		<link>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/</link>
		<comments>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 14:49:16 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[development tools]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[coding style]]></category>
		<category><![CDATA[for-loop]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=142</guid>
		<description><![CDATA[We have been developing some coding style guide lines to produce better code and make our code easier maintainable and portable. Also thinking about code inspection tools and continuous integration techniques which analyze the code will profit from a well defined and verifyable style. While discussing a rather simple rule I thought this might be [...]]]></description>
			<content:encoded><![CDATA[<p>We have been developing some coding style guide lines to produce better code and make our code easier maintainable and portable. Also thinking about code inspection tools and continuous integration techniques which analyze the code will profit from a well defined and verifyable style.<br />
While discussing a rather simple rule I thought this might be interesting to delve into a bit. You will be surprised how much you can discuss about a simple thing such as a for-loop and that is not only true for JavaScript, I am sure.<br />
<span id="more-142"></span></p>
<p>Well, call me pedantic for even discussing this and seeing this as relevant. But everybody knows that adhering coding styles make programming in a team way more pleasant and it is just way more efficient to just code and not to style! Which includes not having to think about how to style the code, though I realize that a lot of programmers have a problem adapting to coding styles.<br />
We at uxebu basically defined that we are applying the coding guide lines of the project that we possibly contribute stuff back to. This means our JavaScript code applies the <a href="http://www.dojotoolkit.org/developer/StyleGuide">dojo coding style guide</a> and our python stuff (we use internally) applies the <a href="http://docs.djangoproject.com/en/dev/internals/contributing/#coding-style">django coding style guide</a>.</p>
<p>But let&#8217;s look at the for-loop now.</p>
<h2>The default</h2>
<p>The most common usage of a for loop is the following.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Nothing spectacular here. But let&#8217;s take it apart a bit. There are two things that are commonly known that can be optimized.</p>
<ol>
<li>The comparison &#8220;i&lt;nodes.length&#8221; in line 1 evaluates the length of nodes on every iteration, if the nodes array is not modified while looping over it or the change to it is not relevant, this can be optimized.</li>
<li>Also the declaration of the variable &#8220;node&#8221; in line 2 is done multiple times, so this is just a small unnecessary thing to do.</li>
</ol>
<p>So let&#8217;s optimize the things we just found out.</p>
<h2>Version 2</h2>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> node<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Another step on our way was to optimize the variable declarations and reducing their count from three down to one. In some code you can then see the following.</p>
<h2>Version 3</h2>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Actually we have already skipped a tiny step in between, very often you can see multiple var-statements as opposed to the already &#8220;squeezed&#8221; one-liner in line 1 above. The way of writing it as seen here, is reasonable if there are a couple other variables to be declared, you just need one var-statement. This will basically reduce the code size, if your minifier doesn&#8217;t already do that for you. <a href="http://wonko.com/post/try-to-use-one-var-statement-per-scope-in-javascript#comment-4819">As stated here</a> it seems to be specified to be irrelevant to performance. So event the argument under 2. against the first version (see above) is not very strong.<br />
Just a small side-note: the one line var-statement evaluates in declaration order, so something like this will work!</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> x <span style="color: #339933;">=</span> len<span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The &#8220;len&#8221; and also &#8220;x&#8221; variables contain the proper content as you are expecting. The comma-separated var-statement evaluates the assignment expression by expression and steps on to the next assignment. Therefore &#8220;len&#8221; and &#8220;x&#8221; will have the proper values 3 and 2.<br />
But let&#8217;s go back to our for-loop.</p>
<h2>Version 4</h2>
<p>If the var-statement is outside the for-loop and especially if other variables (outside of the scope of the for-loop) are declared there the source code get&#8217;s blury and harder to read. For example:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The first two variable declarations (someVar and anotherVar) have nothing to do with the for-loop context, but the others do, so this blurs the source code and is prone to errors. Also if you separate this source code onto multiple lines like so:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>it is still a possible point of failure. I for example, forgot the comma on line 1 which made this source code</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><br />
&nbsp; &nbsp; node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>still work. But and this is a <strong>big but</strong>, the code get&#8217;s a different meaning now! First, line 1 will work, since the semicolon at the end of the line is not mandatory. And second (if not declared inside this scope before) the variables on line 2 are now defined in global scope. And that can really cause a hard to find bug!<br />
Another good reason for not doing this, is that extending the code may lead to developers adding code in between the var-declaration and the for-loop, for whatever reason. Then the variable declarations for the for-loop &#8220;drift away&#8221; and loose their context even a bit more. And the source code becomes harder to understand.</p>
<p>So we rather put all the variable declarations into the for-loop&#8217;s var-statement. Like so:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// This is outside the for-loop and also looks like it.</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> node<span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we have a pretty compact and well context-focused syntax for declaring variables needed within a for-loop. This code is nicely readable and has no impact on performance, even if in most cases good and maintainable code is worth more than the fastest code, but that&#8217;s a use case based decision! We are taking this as a standard for uxebu code.</p>
<p>What do you think? Let us know if you see potential for optimization.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dragonfly für Opera</title>
		<link>http://uxebu.com/blog/2008/07/01/dragonfly-fur-opera/</link>
		<comments>http://uxebu.com/blog/2008/07/01/dragonfly-fur-opera/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 11:57:38 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[Tumbles]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=20</guid>
		<description><![CDATA[Dragonfly für Opera]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.thinkphp.de/archives/338-Dragonfly-fuer-Opera.html">Dragonfly für Opera</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/07/01/dragonfly-fur-opera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox3 best in memory usage</title>
		<link>http://uxebu.com/blog/2008/06/27/firefox3-best-in-memory-usage/</link>
		<comments>http://uxebu.com/blog/2008/06/27/firefox3-best-in-memory-usage/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 07:02:12 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[Tumbles]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[memory usage]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=16</guid>
		<description><![CDATA[Firefox3 best in memory usage]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetperls.com/Content/Browser-Memory.aspx">Firefox3 best in memory usage</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/06/27/firefox3-best-in-memory-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

