/* jquery */ /* jquery accordion style*/ /* jquery init */

26 July 2013

TypeScript & CoffeeScript: A Better JavaScript

JavaScript is a hugely popular language. Its scope extends well beyond the classic web development scenario. Today developers are able to create cross-platform mobile apps and full-sized applications in pure JavaScript.

Google, Appcelerator, PhoneGap and many others have active, well resourced JavaScript-based projects and compilers are springing up all over the place.

Nevertheless JavaScript coding can be a challenge, even for the professional developer. As code listings grow in size and complexity the language's many shortfalls induce to a steep increase in bug count and raise developer frustration.

Using a quality IDE will certainly help. But, how about a new language with a cleaner, modern-looking syntax? One that requires less lines of code for the same functionality, yet is still 100% JavaScript compatible.

Here I'll take a brief look at two, TypeScript and CoffeeScript.


TypeScript version 0.9 was unwrapped in front of Microsoft's developer community during Microsoft's Build 2013 event by Anders Hejlsberg.

In common with many recent Microsoft initiatives there's a strong lean towards openness, exemplified by the Apache 2 licence and CodePlex-hosted source code. In fact, TypeScript is a preview of what to expect in the upcoming ECMAScript 6 standard.

The open source, open specification, cross-platform compiler is itself written in TypeScript. Type declarations are removed by the compiler and the ECMA standard JavaScript output runs in any browser and on any host.

TypeScript is a superset of JavaScript. So developers can start with a JavaScript listing then use whichever TypeScript features seem most appropriate. The addition of types and generics, plus improved class definitions and 'intellisense' support allow developers to create well structured code and introduce fewer bugs.

TypeScript header files add type information to existing libraries. A github-hosted project called DefinitelyTyped already contains an impressive collection of '.ts' definition files covering many popular libraries and frameworks, including jQuery, MongoDB, Node.js and D3.js.

There are IDE plugins for Visual Studio and WebMatrix, plus support for editors such as Sublime Text, Emacs and Vim editors. However, at present only Microsoft's Visual Studio 2012/2013 tool delivers comprehensive support for all TypeScript's features.

To discover more watch Anders Hejlsberg's hour long Build 2013 talk or navigate to the TypeScript preview website and select the 'Play' mode.


CoffeeScript appeared in 2009 when Jeremy Ashkenas placed an early version on GitHub. The stable 1.0 version appeared in December 2010.

CoffeeScript aims to increase developer productivity via syntax influences from Python, Ruby and Haskall. It's a succinct language, with noticeably less syntactic fluff. Consequently, a CoffeeScript listing is not only easier to read, understand and debug, but typically requires less than half the code when compared with JavaScript.

CoffeeScript code is trans-compiled into pure JavaScript. This means any Javascript framework or library can be referenced, including the ever popular jQuery and Prototype products. There's support in Node.js and Ruby On Rails version 3.1, plus an online tool to convert existing JavaScript code into CoffeeScript.

To find out more checkout the free open source introduction to CoffeeScript.

Click to read more analysis articles and posts.

21 July 2013

Microsoft Under Pressure

Microsoft is under pressure as never before.

Reaction to Windows 8 is at best mixed.
Millions of RT Surface devices lie unsold in warehouses.
Nokia isn't selling nearly enough Windows Mobile smartphones.
First quarter 2013 revenue was down eight percent.
Profits are dwindling fast.
And now there's been dramatic share sell-off.

It puts even more pressure on Ballmer's company-wide reorganisation, which amounts to one of the biggest upheavals since Microsoft's inception in 1972.

Ballmer's can only hope his call to arms memo will have far greater impact than the 1995 Bill Gates memo.

Read more Microsoft analysis posts.

17 July 2013

How much should an RT Surface tablet cost?

With millions of RT Surface tablets gathering dust on warehouse shelves, Microsoft has slashed the price.

But is it enough? What is the right price?

After all, it's certainly a powerful device with a rich, powerful operating system capable of both desktop and tablet functionality. Yet, it doesn't have allure of an Apple device - and probably never will.

However, presenting consumers with a straight, equal-cost choice between a 7.9" iPad Mini or a 10.6" RT Surface, complete with free touch keyboard cover, might prove interesting.

Would that be enough to swing the pendulum in Microsoft's favour?

Read more Microsoft analysis posts.

1 July 2013

Learn Python - PyGame Complete App

Over the last few posts we've looked at PyGame installation, events, event handling, colour definition, initialisation and drawing.

Now it's time to put all the ingredients together in the form of a complete app.

Here's the listing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
35
35
36
37
38
39
40
41
# PyGame Skeleton

import pygame, sys, random

def check_events(pos):
  # loop through all events
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.quit()
    if event.type == pygame.MOUSEBUTTONDOWN:
      # draw a coloured disc at the current mouse position
      discSize = random.randint(5,50)
      r = random.randint(100,255)
      g = random.randint(100,255)
      b = random.randint(100,255)
      discCol = [r,g,b]
      pygame.draw.circle(screen, discCol, pos, discSize)

def run():
  # get mouse position
  pos = pygame.mouse.get_pos()

  # check events
  check_events(pos)

  # update the screen with what we've drawn
  pygame.display.flip()

  # control the draw update speed
  clock.tick(50)

# initialise pygame
pygame.init()
screen = pygame.display.set_mode([500,400])
screen.fill(pygame.Color('black'))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()

# loop until the user clicks the close button
while True:
  run()

Take this basic structure and add your own enhancements. Maybe additional event handling or drawing different shapes.

I hope you've enjoyed this series. Happy coding.

Visit my Raspberry Pi page for news, reviews, advice and tutorials.

Learn Python - PyGame Skeleton

Over the last few posts we've looked at PyGame installation, events, event handling, colour definition, initialisation and drawing.

Now it's time to put all the ingredients together in the form of an complete app skeleton.

Here's the listing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
35
35
36
37
38
39
40
41
# PyGame Skeleton

import pygame, sys, random

def check_events(pos):
  # loop through all events
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.quit()
    if event.type == pygame.MOUSEBUTTONDOWN:
      # draw a coloured disc at the current mouse position
      discSize = random.randint(5,50)
      r = random.randint(100,255)
      g = random.randint(100,255)
      b = random.randint(100,255)
      discCol = [r,g,b]
      pygame.draw.circle(screen, discCol, pos, discSize)

def run():
  # get mouse position
  pos = pygame.mouse.get_pos()

  # check events
  check_events(pos)

  # update the screen with what we've drawn
  pygame.display.flip()

  # control the draw update speed
  clock.tick(50)

# initialise pygame
pygame.init()
screen = pygame.display.set_mode([500,400])
screen.fill(pygame.Color('black'))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()

# loop until the user clicks the close button
while True:
  run()

Take this basic structure and add your own enhancements. Maybe additional event handling or drawing different shapes.

I hope you've enjoyed this series. Happy coding.

A post from my Learn Python on the Raspberry Pi tutorial.