<?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>PC Pro blog &#187; javascript</title>
	<atom:link href="http://www.pcpro.co.uk/blogs/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pcpro.co.uk/blogs</link>
	<description>Blogging in the real world</description>
	<lastBuildDate>Wed, 08 Feb 2012 16:54:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Displaying a location marker on a Google Map</title>
		<link>http://www.pcpro.co.uk/blogs/2010/12/23/displaying-a-location-marker-on-a-google-map/</link>
		<comments>http://www.pcpro.co.uk/blogs/2010/12/23/displaying-a-location-marker-on-a-google-map/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 12:54:54 +0000</pubDate>
		<dc:creator>Ian Devlin</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Real World Computing]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=29482</guid>
		<description><![CDATA[
One of the most popular features on websites today is a marker pinpointing a location on Google Maps. It&#8217;s incredibly easy to add such a map to a website and I&#8217;m going to show you how.
I said it was easy, and with the recent release of version 3 of the Google Maps JavaScript API, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/12/google-map.jpg" alt="Google Map" /></p>
<p>One of the most popular features on websites today is a marker pinpointing a location on Google Maps. It&#8217;s incredibly easy to add such a map to a website and I&#8217;m going to show you how.</p>
<p>I said it was easy, and with the recent release of version 3 of the Google Maps JavaScript API, it&#8217;s become even easier. With the previous version of this API, you had to register your map to receive an API key, but that&#8217;s now no longer necessary.</p>
<p>Naturally Google provide <a href="http://code.google.com/apis/maps/documentation/javascript/basics.html" target="_new">a comprehensive guide to the Maps API</a>, but I will run through the basics here.</p>
<p><span id="more-29482"></span></p>
<p><strong>Setting up the Map</strong></p>
<p>First of all you need to include the map API in your web page. This is done by adding the following line in the <code>&lt;head&gt;</code> element of your code:</p>
<pre><code>&lt;script
type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"&gt;
&lt;/script&gt;</code></pre>
<p>You may notice the sensor parameter, which is set to false. This is a required parameter and should be set to &#8220;true&#8221; if the application used to determine the user&#8217;s location has a sensor device (e.g. a GPS locator). That&#8217;s not the case here, so we set it to false as shown.</p>
<p>Naturally, we need to define a map to display, but before we do that we need three things: somewhere on the web page to actually place the map, a default position to use as the map&#8217;s centre, and then some options to define the type of map that we require.</p>
<p>Setting up somewhere on the web page to place the map is a simple case of defining a div with a unique id, and some inline styling. So we have:</p>
<pre><code>&lt;div id="map" style="width:600px;
height:600px; margin-top:10px;"&gt;&lt;/div&gt;</code></pre>
<p>And that&#8217;s all we need.</p>
<p>To define a default position we need a latitude and longitude. There are plenty of websites out there that will convert addresses or places into coordinates for you, and I will centre this particular example on the <em>PC Pro </em>offices at latitude 51.515252 and longitude -0.189852. From these values a Google map position is defined by using the following:</p>
<pre><code>var latlngPos = new google.maps.LatLng(51.515252, -0.189852);</code></pre>
<p>We then set up the map options as follows:</p>
<pre><code>var myOptions = {
   zoom: 10,
   center: latlngPos,
   mapTypeId: google.maps.MapTypeId.ROADMAP
};</code></pre>
<p>Where <code>zoom</code> (naturally) indicates the zoom level of the map (you may want to play about with these to get the value that you want), <code>center</code> is set to the latitude/longitude position that we defined, and <code>mapTypeId</code> is set to the type of map that we wish to display initially. The map types are defined by the Google Maps API and are:</p>
<ul>
<li>MapTypeId.ROADMAP displays the default road map view</li>
<li>MapTypeId.SATELLITE displays Google Earth satellite images</li>
<li>MapTypeId.HYBRID displays a mixture of normal and satellite views</li>
<li>MapTypeId.TERRAIN displays a physical map based on terrain information</li>
</ul>
<p>Note: this simply defines the initial map type to display, the user can change it via a dropdown list that appears on the map itself. You can read more about the different map types over at <a href="http://code.google.com/apis/maps/documentation/javascript/maptypes.html" target="_new">Google</a> should you want to know more.</p>
<p>With these things done, we can now initialise our map as follows:</p>
<pre><code>var map = new google.maps.Map(document.getElementById("map"), myOptions);</code></pre>
<p>This will now cause the map to appear on your web page, contained within the map div (the map itself stays within the boundaries of the div&#8217;s dimensions).</p>
<p><strong>Marking the Location</strong></p>
<p>With the map set up, we can now go about defining the marker on the map that we want displayed. Once again we need to define a position for the Google map using latitude and longitude. I&#8217;m using the same values as above, as I want to place a marker on the <em>PC Pro</em> offices (it&#8217;ll help the staff when they stumble back from their Christmas party).</p>
<pre><code>var markerPos = new google.maps.LatLng(51.515252, -0.189852);</code></pre>
<p>Adding a marker to this location is as simple as:</p>
<pre><code>var marker = new google.maps.Marker({
   position: markerPos,
   map: map,
   title: "PC Pro Offices"
});</code></pre>
<p>(where map is the id of the map div)</p>
<p>As usual I have a <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/12/google-maps-simple-example.html">simple example</a> so that you can see it in action. (Note: this example also uses some jQuery)</p>
<p><strong>Going further</strong></p>
<p>The Google Map API is very powerful and you can go much further than I have shown here, such as adding pop-up information windows on the map marker.</p>
<p>You can even use the API to convert addresses into latitude/longitude positions and display them on the map. I have included a <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/12/google-maps-advanced-example.html">more advanced example</a> should you want to take a look at it. It&#8217;s pretty straightforward and I&#8217;ve commented the code in order to make it clearer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2010/12/23/displaying-a-location-marker-on-a-google-map/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to store website data with HTML5</title>
		<link>http://www.pcpro.co.uk/blogs/2010/09/27/data-storage-with-html5/</link>
		<comments>http://www.pcpro.co.uk/blogs/2010/09/27/data-storage-with-html5/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 11:02:47 +0000</pubDate>
		<dc:creator>Ian Devlin</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[data storage]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[localStorage]]></category>
		<category><![CDATA[sessionStorage]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=25108</guid>
		<description><![CDATA[
Throughout your web browsing careers I&#8217;m sure you&#8217;ve come across the notion of cookies, pieces of text stored by the browser to be retrieved and used at a later date. These vary from simply remembering your name to welcome you personally next time you visit, to more complicated storage of authentication and shopping-cart contents.
Cookies generally [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/html5-storage.jpg" alt="html5 storage" width="462" height="300" /></p>
<p>Throughout your web browsing careers I&#8217;m sure you&#8217;ve come across the notion of cookies, pieces of text stored by the browser to be retrieved and used at a later date. These vary from simply remembering your name to welcome you personally next time you visit, to more complicated storage of authentication and shopping-cart contents.</p>
<p>Cookies generally work well but can be fiddly to implement, as they are set to be deleted by default once the browser is closed. If a website owner needs the data to be stored for a longer period, a cookie can be given an expiry date. Again this isn&#8217;t as clean as it could be: how far into the future do you set the date, for example? And what happens when a user flushes out their cookies?</p>
<p>HTML5 attempts to clean this up with the introduction of web storage.</p>
<p><span id="more-25108"></span></p>
<p><strong>Web Storage</strong></p>
<p>Web storage comes in two different types, <code>sessionStorage</code> and <code>localStorage</code>. As might be deduced from the names, <code>sessionStorage</code> is for storing data that&#8217;s required for a particular session only, and <code>localStorage</code> is for data that&#8217;s to remain indefinitely.</p>
<blockquote><p>Web storage correctly separates session data from long term data</p></blockquote>
<p>This does away with the need for expiry dates, and instantly makes it clearer which data is for when and for how long. It also makes it incredibly easy to implement.</p>
<p><strong>The API</strong></p>
<p>As both types are so similiar, they share the same API, which contains the following items and functions:</p>
<pre><code>// The number of items being stored
long length;

// To retrieve the item 'key' from storage
getItem(key);

// To set the item 'key' in storage with 'value'
setItem(key, value);

// To remove the item from storage
removeItem(key);

// To clear the entire storage
clear();</code></pre>
<p>It&#8217;s all quite simple and straightforward to use.</p>
<p><strong>Saying Hello</strong></p>
<p>Let&#8217;s say you wanted to store a user&#8217;s name to welcome them back later. Assuming the existence of a simple HTML5 page consisting of one input field called <code>name</code> and a link that calls the function <code>saveName()</code> it would be defined as follows:</p>
<pre><code>function saveName() {
   var name = document.getElementById('name').value;
   localStorage.setItem('username', name);
}</code></pre>
<p><code> </code></p>
<p>Each time this page loads, call a new function <code>sayHello()</code> which is defined as:</p>
<pre><code>function sayHello() {
   var userName = localStorage.getItem('username');
   if (userName != null) alert("Hello " + userName + " and welcome back!");
}</code></pre>
<p><code> </code></p>
<p>This will check for the existence of a username in <code>localStorage</code>, and if it&#8217;s there, will welcome the user.</p>
<p><em>Note that <code>localStorage</code> is used here rather than <code>sessionStorage</code> as we want the name to be displayed next time the user visits the page again, during which time they may have closed the browser, which would clear anything in <code>sessionStorage</code>.</em></p>
<p>You can see this working for yourself in this very simple <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/say-hello.html">&#8220;say hello&#8221; example</a>. Enter a name, click &#8217;save&#8217;, and reload the page.</p>
<p>If you enter a different name in the input field and click &#8217;save&#8217;, the existing value will be overwritten. We could also remove the item by calling <code>localStorage.removeItem('name');</code> which would remove that item only. The entire <code>localStorage</code> could be cleared by calling <code>localStorage.clear();</code></p>
<p><strong>Session storage</strong></p>
<p><code>sessionStorage</code> works in the exact same way, except that the data will be automatically cleared once the brower is closed.</p>
<p>You can also store multiple data items in web storage attached to the one key, but you will need to use a JavaScript object and something such as JSON which helps to &#8220;stringify&#8221; the stored data, thus facilitating its storage.</p>
<p><strong>Browser Support</strong></p>
<p>If you&#8217;re used to reading about Internet Explorer&#8217;s current inability to support any HTML5 feature, you&#8217;re in for a surprise here. Web storage is actually supported by IE8 as well as all the major browsers:</p>
<ul>
<li>Firefox 3.5+</li>
<li>Safari 4.0+</li>
<li>Chrome 4.0+</li>
<li>Opera 10.5+</li>
<li>Internet Explorer 8.0+</li>
<li>iPhone 2.0+</li>
<li>Android 2.0+</li>
</ul>
<p>So basically, you can start using it now!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2010/09/27/data-storage-with-html5/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Adding your Twitter feed to your website with jQuery</title>
		<link>http://www.pcpro.co.uk/blogs/2010/09/13/adding-your-twitter-feed-to-your-website-with-jquery/</link>
		<comments>http://www.pcpro.co.uk/blogs/2010/09/13/adding-your-twitter-feed-to-your-website-with-jquery/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 10:44:11 +0000</pubDate>
		<dc:creator>Ian Devlin</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=24427</guid>
		<description><![CDATA[
If you or your company has a Twitter account, chances are you&#8217;d like to promote it and display your latest tweets from your website. Since many websites &#8211; both personal and increasingly business &#8211; are built on blogging software such as WordPress, this is usually achieved via a plugin, of which there are many out [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-large wp-image-24547" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/PC-Pro-Twitter-page--462x346.jpg" alt="PC Pro Twitter page" width="462" height="346" /></p>
<p>If you or your company has a Twitter account, chances are you&#8217;d like to promote it and display your latest tweets from your website. Since many websites &#8211; both personal and increasingly business &#8211; are built on blogging software such as WordPress, this is usually achieved via a plugin, of which there are many out there.</p>
<p>But what if you simply want to add your live Twitter feed to a &#8220;normal&#8221; web page? <a title="Twitter widgets" href="http://twitter.com/goodies/widgets" target="_blank">Twitter itself provides a number of HTML widgets</a>, but in this article I&#8217;ll show you how easy it is to achieve with a little bit of JavaScript, CSS, and jQuery.</p>
<p><span id="more-24427"></span></p>
<p>In case you haven&#8217;t come across it before:</p>
<p><strong>What is jQuery?</strong></p>
<p><a href="http://jquery.com/" target="_new">jQuery</a> is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. It&#8217;s very powerful and makes life a whole lot easier when writing JavaScript. To include jQuery in your webpage, simply add the following within the <code>&lt;head&gt;</code> tags:</p>
<p><code>&lt;script type="text/javascript" src="http://jqueryjs.google<br />
code.com/files/jquery-1.3.2.min.js"&gt;&lt;/script&gt;</code></p>
<p>This uses the version that is hosted on Google Code, which saves you having to download the file.</p>
<p><strong>Twitter API</strong></p>
<p>Twitter itself provides a complicated API to allow access to all sorts of things. A lot of this complication arises around authentication, and necessarily so, but thankfully to simply retrieve a stream of tweets, authentication isn&#8217;t required (as long as the user in question hasn&#8217;t hidden their tweets).</p>
<p>First of all the API provides many different ways to obtain a <a href="http://dev.twitter.com/doc/get/statuses/" target="_new">user&#8217;s statuses</a>. I won&#8217;t go into any of them other than the one that I favour, and this is the one that I&#8217;ll talk about here: <a href="http://dev.twitter.com/doc/get/statuses/user_timeline" target="_new">user_timeline</a>.</p>
<p><strong>user_timeline</strong></p>
<p>This returns a number of the most recent statuses posted by the user. It can return the data in different formats: XML, JSON, RSS and Atom. I favour  <a href="http://www.json.org/" target="_new">JSON</a>, a lightweight data-interchange format, so this is the one that I will talk about.</p>
<p>You can use a number of parameters, and a full list of what they can do can be found on the Twitter API description for <a href="http://dev.twitter.com/doc/get/statuses/user_timeline" target="_new">user_timeline</a>. For now, I will only use a few relevant ones.</p>
<p><strong>Give me the Tweets!</strong></p>
<p>To retrieve the data for a particular Twitter account (I will use <a href="http://twitter.com/pcpro" target="_new">pcpro</a> in this example here) you call the following:</p>
<p><code>$.getJSON("http://twitter.com/statuses/user_timeline.json?<br />
screen_name=pc_pro&amp;count=10&amp;callback=?",<br />
function(tweetdata) {<br />
   // do some stuff here<br />
});</code></p>
<p>This will return the last 10 tweets from the pc_pro account in JSON format in the <code>tweetdata</code> variable. By default, retweeted tweets are not included in this feed, but to include them, add the <code>&amp;include_rts=1</code> parameter above, and they will be returned.</p>
<p>Of course we now have to make sense of this data, parse it and actually do something with it.</p>
<p>On our HTML page, define a <code>&lt;ul&gt;</code> and give it the id <code>tweet-list</code>. This is where we will hold our tweets. The above code is then extended to do the following:</p>
<p><code>$.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name=pc_pro&amp;count=1O&amp;callback=?", function(tweetdata) {<br />
   var tl = $("#tweet-list");<br />
   $.each(tweetdata, function(i,tweet) {<br />
      tl.append("&lt;li&gt;“" + tweet.text + "”– " + tweet.created_at + "&lt;/li&gt;");<br />
   });<br />
});</code></p>
<p>Some explanations: <code>var tl = $("#tweet-list");</code> grabs a reference to the <code>&lt;ul&gt;</code> element that we created above. We need this as we will add each tweet to it.</p>
<p><code>$.each(tweetdata, function(i,tweet) {...</code> is the start of a jQuery loop, in this case iterating through each item in <code>tweetdata</code> and storing it temporarily in <code>tweet</code>. The following line then adds the tweet within an <code>&lt;li&gt;</code> item.  The actual text of the tweet is contained within the <code>text</code> data member, and here we put double quotes around it, and the time it was created is contained within the <code>created_at</code> data member.</p>
<p>This will now display the last 10 tweets in list format on the relevant HTML page.</p>
<p>However, if there are links contained in the tweet, they won&#8217;t be clickable, and the created date is a bit long and not like the Twitter standard timelines such as &#8220;about a minute ago&#8221; or &#8220;two hours ago&#8221;. We can fix this with the following two functions <code>urlToLink();</code> which we call on <code>tweet.text</code>:</p>
<p><code>function urlToLink(text) {<br />
   var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&amp;@#\/%?=~_|!:,.;]*[-A-Z0-9+&amp;@#\/%=~_|])/ig;<br />
   return text.replace(exp,"&lt;a href='$1'&gt;$1&lt;/a&gt;");<br />
}</code></p>
<p>and <code>relTime();</code> which we call on <code>tweet.created_at</code>:</p>
<p><code>function relTime(time_value) {<br />
   time_value = time_value.replace(/(\+[0-9]{4}\s)/ig,"");<br />
   var parsed_date = Date.parse(time_value);<br />
   var relative_to = (arguments.length &gt; 1) ? arguments[1] : new Date();<br />
   var timeago = parseInt((relative_to.getTime() - parsed_date) / 1000);<br />
   if (timeago &lt; 60) return 'less than a minute ago';<br />
   else if(timeago &lt; 120) return 'about a minute ago';<br />
   else if(timeago &lt; (45*60)) return (parseInt(timeago / 60)).toString() + ' minutes ago';<br />
   else if(timeago &lt; (90*60)) return 'about an hour ago';<br />
   else if(timeago &lt; (24*60*60)) return 'about ' + (parseInt(timeago / 3600)).toString() + ' hours ago';<br />
   else if(timeago &lt; (48*60*60)) return '1 day ago';<br />
   else return (parseInt(timeago / 86400)).toString() + ' days ago';<br />
}</code></p>
<p>So we need to change the above line to the following:</p>
<p><code>tl.append("&lt;li&gt;“" + urlToLink(tweet.text) + "”– " + relTime(tweet.created_at) + "&lt;/li&gt;");</code></p>
<p>This will be called when the HTML page is loaded (or you can load it some other time, it&#8217;s up to you of course) and this is done using jQuery by inserting the code within:</p>
<p><code>$(document).ready(function() {<br />
   // code here<br />
});</code></p>
<p>which basically calls the code when the entire DOM has been loaded.</p>
<p><strong>End Result</strong></p>
<p>I have put together an <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/twitter-api-test3.html">example</a> using all the code above, so you can see all this together and working for yourself. Plus you can <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/twitter-api-test3-view.html">view the code</a> to see how it&#8217;s done. It&#8217;s all commented too, probably overly so, in case you get stuck.</p>
<p>You can of course also style the list and its contents with CSS, but I&#8217;ll leave that as an exercise for the reader.</p>
<p><strong>*Update*</strong></p>
<p>One of the comments below asked about retrieving the latest statuses from a specific account&#8217;s list. I&#8217;ve created a quick example that <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/twitter-api-list-test2.html">retrieves and displays the latest updates</a> from PC Pro&#8217;s &#8217;staff&#8217; Twitter list. You can of course <a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/twitter-api-list-test-view2-view.html">view</a> the source code.</p>
<p>The main difference is the URL in included in the <code>&amp;.getJSON()</code> call which should be:</p>
<p><code>http://api.twitter.com/1/<strong>account-name</strong>/lists/<strong>list-name</strong>/statuses.json?callback=?</code></p>
<p>where <code>account-name</code> is the name of the account, in this case <code>pc_pro</code>, and <code>list-name</code> is the name of the list, in this case <code>staff</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2010/09/13/adding-your-twitter-feed-to-your-website-with-jquery/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Google App Inventor: is drag and drop a flop?</title>
		<link>http://www.pcpro.co.uk/blogs/2010/09/07/googles-app-inventor/</link>
		<comments>http://www.pcpro.co.uk/blogs/2010/09/07/googles-app-inventor/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 16:09:17 +0000</pubDate>
		<dc:creator>Darien Graham-Smith</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[App Inventor]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=23998</guid>
		<description><![CDATA[
Confession time: I have never learnt to program in Java. Swoon, gasp.
It&#8217;s not that I haven&#8217;t wanted to. In particular, I’ve always loved the idea of creating my own mobile phone apps; but I&#8217;ve never seemed to find the time. So I was excited to discover at the weekend that Google has finally given me [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/BlockEdFull.png"><img class="aligncenter size-full wp-image-24013" title="BlockEdThumb" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/BlockEdThumb.png" alt="BlockEdThumb" width="462" height="337" /></a></p>
<p>Confession time: I have never learnt to program in Java. Swoon, gasp.</p>
<p>It&#8217;s not that I haven&#8217;t wanted to. In particular, I’ve always loved the idea of creating my own mobile phone apps; but I&#8217;ve never seemed to find the time. So I was excited to discover at the weekend that Google has finally given me access to App Inventor — a visual development environment that lets you create Android applications via a drag-and-drop interface, with no Java skills required. <span id="more-23998"></span></p>
<p>It certainly does simplify the process. The first sample application – which puts up a picture of a cat that miaows when you prod it – is embarrassingly easy to assemble. In the design stage, you simply drag a button onto your workspace (representing the phone screen), import the cat picture, assign the picture to the button and import the sound. Create a click event that plays the sound, and the job’s done.</p>
<p>So yes, the workflow is similar to Microsoft Visual Studio — not that there’s anything wrong with that. But there’s one big difference: in VB.NET, setting up an event handler for the button involves getting to grips with some daunting syntax, along the lines of: <tt>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click</tt></p>
<p><a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks1.png"><img class="alignright size-full wp-image-24001" title="Blocks1" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks1.png" alt="Blocks1" width="201" height="97" /></a>In App Inventor you assemble an event handler by simply snapping colour-coded, jigsaw-piece-shaped “blocks” together. In fact, all “code” is constructed by combining blocks within the Java-based Blocks Editor. As Google freely acknowledges, it’s a system that owes a heavy debt to MIT’s Scratch project, an educational programming system which we&#8217;ve already produced a tutorial for in our <a href="http://www.pcpro.co.uk/features/351556/free-computing-lessons-for-kids">Free Computing Lessons for Kids</a> feature.</p>
<p><strong>Childishly simple?</strong></p>
<p>Does this indicate that App Inventor is similarly intended for kids? Yes and no. Google has said that App Inventor was designed from &#8220;an educational  perspective&#8221;, and tested in &#8220;classrooms across the United States&#8221;, which sounds like a pretty clear hint. But then Google&#8217;s Mark Friedman has also described it as a broader tool, for &#8220;programmers and non-programmers, professionals and students&#8221; alike. Certainly it can support constructions as sophisticated as anything you&#8217;ll find in more grown-up languages:</p>
<p><a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks2.png"><img class="aligncenter size-full wp-image-24004" title="Blocks2" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks2.png" alt="Blocks2" width="462" height="232" /></a></p>
<p>So while App Inventor is aimed primarily at kids, it&#8217;s not just a classroom tool. In principle, it should be powerful enough to produce any application you can imagine.</p>
<p><strong>Writers&#8217; blocks</strong></p>
<p>Sadly, as soon as I started using App Inventor, I discovered the catch. Dragging blocks about may be a fine first introduction to computing, but if you want to create anything more complex than “Pet the Kitty” it&#8217;s a slow and fiddly way to work. It doesn&#8217;t help that the blocks you need are split across two tabs of seven or more drawers, and as you build up functions the workspace becomes messier and harder to navigate (see the screenshot at the top of this post). Perhaps in time the Blocks Editor will improve, but right now it&#8217;s such a faff I can see it driving people away from programming altogether.</p>
<p>That&#8217;s a shame, because some of the functions on offer seem designed to appeal to experienced coders, and support some neat mobile-specific capabilities:</p>
<p><a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks3.png"><img class="aligncenter size-full wp-image-24007" title="Blocks3" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/09/Blocks3.png" alt="Blocks3" width="462" height="280" /></a></p>
<p>But if you ask me, this representation is actually harder to understand than a function written in plain text — and it was certainly harder to construct.</p>
<p>All of which leaves App Inventor looking like a missed opportunity. Yes, for the kids at whom it&#8217;s chiefly aimed, it&#8217;s a decent introduction to programming concepts. But it has potential far beyond that, and I fear that will never be usefully harnessed, because anyone with the programming nous to make full use of App Inventor&#8217;s abilities will surely prefer a language that doesn&#8217;t force you to pedantically assemble every function, procedure and event out of multicoloured blocks.</p>
<p><strong>Rewriting the script</strong></p>
<p>In fairness, it&#8217;s optimistic to think that any development environment could ever be perfect for both beginner projects and more  complex designs. But, tantalisingly, I think App Inventor could get close with one single addition. What’s needed is a traditional script-based view that operates in parallel with the Blocks Editor. For beginners, this would show automatically-generated code (presumably using simple Java-type syntax) representing their block-based constructions, making App Inventor an even better introduction to programming.</p>
<p>Meanwhile, more advanced users could develop directly within the script editor, while still using App Inventor as a time-saving tool for designing interfaces and packaging completed projects. The blocks view, automatically generated from your code, would become a handy visual aid to debugging and program flow.</p>
<p>But in the absence of a script editor, I doubt I’ll be producing any mobile applications with App Inventor. Google certainly deserves credit for the   excellent work it&#8217;s done in simplifying Android development, and abstracting it away from   the nitty gritty of libraries and dependencies. But if the only way to take advantage of that is via drag-and-drop programming then personally I think I might be better off simply learning Java.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2010/09/07/googles-app-inventor/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The hard facts: what languages web developers should learn</title>
		<link>http://www.pcpro.co.uk/blogs/2010/05/06/the-hard-facts-what-languages-web-developers-should-learn/</link>
		<comments>http://www.pcpro.co.uk/blogs/2010/05/06/the-hard-facts-what-languages-web-developers-should-learn/#comments</comments>
		<pubDate>Thu, 06 May 2010 11:43:59 +0000</pubDate>
		<dc:creator>Kevin Partner</dc:creator>
				<category><![CDATA[Online business]]></category>
		<category><![CDATA[Real World Computing]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[web developers]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=15973</guid>
		<description><![CDATA[When I first started learning programming, choices were limited to machine code or a version of BASIC. But then I am ancient.
In many ways, the newcomer to programming who’s aiming at web or mobile development has a much better time of it today. This is because whilst there are many, many languages to choose from, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-15979" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2010/05/silverlight_v_web-156x175.jpg" alt="SL_logo_v" width="156" height="175" />When I first started learning programming, choices were limited to machine code or a version of BASIC. But then I am ancient.</p>
<p>In many ways, the newcomer to programming who’s aiming at web or mobile development has a much better time of it today. This is because whilst there are many, many languages to choose from, they have much more in common than languages of the past. Learn ActionScript, for example, and you’re half way there with C#, PHP and JavaScript, as their basic constructs are identical.</p>
<p>But the real value you, as a web developer, can bring to a project is specialist skill. Whilst every good PHP developer understands the basics of C#, no web project can be completed without in-depth knowledge, and this takes time and lots and lots of practice to develop. It’s a huge investment so the choice of which language to specialise in is also critical, at least in the short- to medium-term.<span id="more-15973"></span></p>
<p>If you’re aiming to develop your own web applications, you can choose whichever language flies your kite. I develop in PHP, JavaScript/jQuery and Flex/Flash Builder because I like them. PHP is my absolute favourite, and I tend to use that alongside jQuery unless I need the super-rich application features that only Flex/Flash can deliver. My brother, on the other hand, is a massive fan of C# and either language is perfectly capable of creating sophisticated web applications.</p>
<p>If you want to hire yourself out you need to make a more pragmatic choice about which development tool to specialise in and one way to do this is to look at the demand for each. <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">According to the TIOBE Programming Community Index for April 2010</a>, the venerable trinity of C, Java and C++ are the most widely used and requested programming languages. This is mainly because of the huge quantity of legacy code that needs to be managed within large corporations. PHP is the top web scripting language with C# around half of PHP’s level and Python and Perl next. Objective-C, the language used for creating iPhone applications, still only accounts for a tiny fraction of the programming market but is massively on the rise.</p>
<p>So, for web development, PHP is the most popular language (note, I did not say “best”). That’s all very well but I rather suspect that there are more programmers working in PHP than any other development language, which means the competition is huge. We need to know the ratio between popularity and competition.</p>
<p>I went to freelance recruitment site <a title="Guru.com" href="http://www.guru.com/" target="_blank">Guru.com</a> and, for each language, found out the number of projects posted for each of the common web and mobile platform development languages. I then noted how many freelancers/companies offered each language. By dividing one into the other, we end up with a rough idea of how competitive the market for expertise in each language is. For example, when I checked there were 151 PHP projects on Guru and 7,769 providers. This means that there are 51.45 providers for each job.</p>
<p>Here’s the full list:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="177" valign="top"><strong>Tool</strong></td>
<td width="170" valign="top"><strong>Providers/Jobs</strong> (low is better)</td>
</tr>
<tr>
<td width="177" valign="top">Android</td>
<td width="170" valign="top">1.86</td>
</tr>
<tr>
<td width="177" valign="top">iPhone</td>
<td width="170" valign="top">3.39</td>
</tr>
<tr>
<td width="177" valign="top">Silverlight</td>
<td width="170" valign="top">14.44</td>
</tr>
<tr>
<td width="177" valign="top">Flex</td>
<td width="170" valign="top">38</td>
</tr>
<tr>
<td width="177" valign="top">PHP</td>
<td width="170" valign="top">51.45</td>
</tr>
<tr>
<td width="177" valign="top">ASP/ASPX</td>
<td width="170" valign="top">52.5</td>
</tr>
<tr>
<td width="177" valign="top">Ruby</td>
<td width="170" valign="top">83.8</td>
</tr>
<tr>
<td width="177" valign="top">Python</td>
<td width="170" valign="top">90.3</td>
</tr>
<tr>
<td width="177" valign="top">Flash</td>
<td width="170" valign="top">90.9</td>
</tr>
</tbody>
</table>
<p>What leaps out immediately is that the competition ratio for mobile development is much lower than for web development, and within that Android development is almost twice as attractive a market as iPhone development.</p>
<p>Looking at the web development languages, it looks as though Flash, Python and Ruby development are markets that are saturated with developers chasing relatively few projects. PHP and ASP (which includes ASP and ASPX) are neck-and-neck but the head and shoulders winners are Flex and Silverlight. Whilst there are relatively few projects, there are also few developers.</p>
<p>So which should you choose? Looking at these ratios, it seems to me that choosing either PHP or ASP development with Visual Studio for creating standard web applications is a good initial approach. PHP has the advantage of being free to install and develop for (there are plenty of free IDEs) whereas skills developed in C#, for example, are also transferrable into desktop development. The other benefit of developing in the Visual Studio environment is that adding Flash-like functionality is simply a matter of extending your existing C# skills so that they use the Silverlight player.</p>
<p>From the purely commercial point of view (and if you assume that Silverlight will, eventually, succeed as a technology in becoming as ubiquitous as Flash Player) the Visual Studio approach has a lot going for it: C# becomes a single language that can be used on the desktop, for creating standard .aspx web applications and for developing Silverlight applications.</p>
<p>For me, however, PHP is unbeatable when it comes to productivity, and Flash Player is way ahead in terms of browser installations so, at least for now, I’ll be sticking to this combination. My advice to a newcomer to programming, however, would probably be to download Visual Studio 2010 Express and try C# for size – it may well, finally, be the future Microsoft always intended it to be.</p>
<p>On the other hand, with the forthcoming release of Adobe Air for Android and the low competition level for Android development, Flex has suddenly become a very credible development environment for that platform. You pays your money&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2010/05/06/the-hard-facts-what-languages-web-developers-should-learn/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Google says it can keep Chrome on top</title>
		<link>http://www.pcpro.co.uk/blogs/2008/09/16/google-says-it-can-keep-chrome-on-top/</link>
		<comments>http://www.pcpro.co.uk/blogs/2008/09/16/google-says-it-can-keep-chrome-on-top/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 18:07:32 +0000</pubDate>
		<dc:creator>Matthew Sparkes</dc:creator>
				<category><![CDATA[Just in]]></category>
		<category><![CDATA[View from the Labs]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pcpro.co.uk/blogs/?p=3276</guid>
		<description><![CDATA[
Chrome may have impressed with its speedy rendering and JavaScript performance, but there&#8217;s more where that came from says a Google developer.
Kevin Millikin, one of the team which worked on the V8 JavaScript rendering engine that underpins Chrome, gave a talk at the Google Developers Conference today where he explained that although the code is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pcpro.co.uk/blogs/wp-content/uploads/2008/09/laptops_hundreds_generic.jpg"><img class="alignnone size-medium wp-image-3279" src="http://www.pcpro.co.uk/blogs/wp-content/uploads/2008/09/laptops_hundreds_generic-300x212.jpg" alt="" width="300" height="212" /></a></p>
<p>Chrome may have impressed with its speedy rendering and JavaScript performance, but there&#8217;s more where that came from says a Google developer.</p>
<p>Kevin Millikin, one of the team which worked on the V8 JavaScript rendering engine that underpins Chrome, gave a talk at the Google Developers Conference today where he explained that although the code is already pretty unique, there are plenty more avenues they can explore to eke out more performance.<span id="more-3276"></span></p>
<p>&#8220;The internet has changed. Inside of Google we do almost all our work, except engineering, in the browser,&#8221; said Millikin, explaining that the public aren&#8217;t the only ones waiting on Linux and Mac versions of the browser. &#8220;We&#8217;re looking for it too. We&#8217;ve all got MacBooks.&#8221;</p>
<p>The company decided early on that it did not want to create a new web platform, which would upset web developers worldwide. Instead they chose to base Chrome on WebKit and have it act just like Safari, almost to the exact pixel. &#8220;We even implemented bugs, as long as they weren&#8217;t security bugs,&#8221; said the developer proudly.</p>
<p>In a talk which was deeply technical to say the least, Millikin ran through the ways in which V8 manages to overtake its rivals. One important method is hidden classes, which takes the messy and loose way that JavaScript handles objects and tidies it up behind the scenes by trying to lay an object-oriented model over it. Add some just-in-time translation to machine code and you already have a speedier engine.</p>
<p>However, there are more tweaks to come. In order to speed up creating new processes V8 already caches the heap at the appropriate moment, but this could also be done with new pages under the same site, and even refreshes – certain JavaScript elements will remain from page to page, and these don’t necessarily have to be recompiled.</p>
<p>It seems that not only has Google nailed JavaScript rendering already, but that it has some excellent engineers with some decent plans for the future to make sure it stays on top. Perhaps Firefox would be wise to take a look at V8. In fact, it may well be unwise not to do so quickly, with news that it is losing market share to the new, faster kid on the block.</p>
<p>&#8220;We&#8217;ve now entered a new phase in an arms race on JavaScript performance,&#8221; said Millikin, diplomatically not naming names. He explained that Google would be keen to see the open source V8 taken into other browser products. With two years of engineering and research behind the project, I’d say that it was the plan from the very start. &#8220;When we started the project the JavaScript landscape was pretty grim,&#8221; admits Millikin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pcpro.co.uk/blogs/2008/09/16/google-says-it-can-keep-chrome-on-top/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

