Touch Develop retirement postponed until June 22, 2019. Sign-in and access to cloud assets to be removed on May 23, 2018.Learn More..


dev bootcamp

This tutorial assumes that you have some basic knowledge of programming languages such as Java, C# or Javascript. Here we go...

overview

TouchDevelop is a mobile-first cloud-first IDE. Many design decisions about the language, runtime or editor were made to work on mobile touch devices.
  • touch-friendly: a typed imperative language on top of a semi-structured editor that allow entering code with no syntax errors.
  • mobile: designed to run on phones, small screen, low power, interruptible execution.
  • cloud-connected: leverages the cloud for script synchronization, art search, code synthesis and more to come.
  • cross-cross platform: allows to build apps on most platforms and provides export to Windows, Windows Phone, Android, iOS and Azure Web Apps.

show me some code!

You can inspect the code of any published script. Here is a reading list if you'd like to dive in the code immediately:

language

The TouchDevelop language is a typed imperative language that works in pair with a semi-structured editor. Code is entered token by token rather than character by character to allow efficient input on touch devices.
  • local variables are declared using the := assignment operator. Their type is inferred and they live within their scope.
var x := 0
  • global variable are declared under the data singleton. Global variables can be persisted in memory, locally or in the cloud. To save space, the data symbol is shortened to field.
 score := 0
  • there is only 1 number type that represents a floating point number;
  • the language provides the usual control flow structures: if, while, for, for each. There is no jump so no exception, no break, no continue or no return.
for 0 i < x do
if x < 0 then
...
else ... end if
end for
  • the upper bound of the for loop is not re-evaluated during the loop. If you need to modify the upper bound from within the loop, use a while loop.
  • procedures are called actions, they may take multiple input and/or output parameters. Output parameters are named and have to be assigned before leaving the action.
function
sum
(
left : Number,
right : Number)
returns (
result : Number,
greater : Boolean)
do
result := left + right
greater := left < right
end function
  • you can find the actions defined in the script under the code singleton (which gets shortened to play). Action invocation take parameters unless the action has no input parameters.
var result, greater :=  sum(1, 2)
  • async actions can be used to create responsive apps.
  • you can define custom data types, called records. Records come in 4 flavors: a table of rows, an index (table with keys), garbage collected object or decorator (garbage collected index).
replicated
 
table
 
grocery
columns
name : String
quantity : Number
  • a script marked as library can be referenced by other scripts. Only public actions are callable from a library.
var id :=  facebook → post text("me", "hello there!")

data structures

You can define records which to store and read custom data. Records can be stored as a table, an index, an objects (garbage collected) or fields (decorator). All changes are always automatically saved.
Tables and indexes are persisted in memory, locally or in the cloud.
replicated
 
table
 
grocery
columns
name : String
quantity : Number
  • adding a new row
var grocery :=  grocery table → add row
  • setting a field value
grocery → name := "pizza"
  • reading a field value
var q := grocery → quantity
  • enumerating the rows
for each g in  grocery table do
...
end for each
  • for an index, rows do not have to be added. A row exists if any of its field value is not the default.
replicated
 
index
 
order
keys
id : String
fields
product : String
quantity : Number
  • accessing a row and setting a field
var order :=  order index → at("123")
order → quantity := 1

user interface (basic)

  • the screen is a wall Values can be posted on the wall by calling post to wall and the newest will show on top by default.
"hello world!" → post to wall
  • stack of pages Empty walls, called pages, can be pushed on stack. The user can press the back button to pop the page.
wall → push new page
wall → pop page

user interface (advanced)

  • boxes When the wall rendering becomes too restrictive, you can define your user interface using a tree of boxes similarly to HTML divs.
page
show
()
initialize
...
display
boxed
box → set font size(2)
"hello world" → post to wall
box → on tapped(handler)
where handler() is
wall → prompt("hello again!")
end
end
end boxed
end page
  • try the soundboard tutorial for a quick intro to boxes.

apis

The TouchDevelop APIs provide high-level easy access to sensors and assets from the device. Depending on the platform, access to this information will vary.
  • getting the accelerometer reading,
var acc := senses → acceleration quick
  • getting the current geo-location and displaying a map
var loc := senses → current location
loc → post to wall

web services

You can use web requests to interact with existing web services. OAuth authentication is also supported.
var request := web → create request("http://contoso.com/")
request → set method("post")
request → set header("Authorization", "secret")
var response := request → send
response → status code → post to wall

libraries and code reuse

Scripts can reference other scripts if those are marked as libraries (in the script settings).
  • the facebook library allows to issue queries against the Facebook group.
var post id :=  facebook → post text("", "hello from TouchDevelop!")
  • the turtle library allows to build Logo like programs
 turtle → forward(200)

teach

Want to teach using Touch Develop? Have a look at the Creative Coding Through Games And Apps course!

ecosystem

  • Scripts are automatically backed up in the cloud. The cloud acts as a central script store and takes care of synchronizing your scripts across all your devices.
  • You can publish a script to make it available to all other users.
  • Users are free to modify, comment, or add hearts to any published script.
  • TouchDevelop comes as a Web App that runs on any modern browsers, and there is a native app for Windows Phone. Both use the same basic language, but differ in which features are available.

export as apps

The scripts can be exported as app for various environment: Windows Store, Windows Phone Store or HTML5 WebApp.