Apple's New Swift Language Should Feel Familiar for SmartApp Authors


(Ben Edwards) #1

The lead developer of the Groovy language just posted an interesting writeup about the similarities between the newly announced Swift language and Groovy.

Here is an excerpt and some code (I, for one, appreciate the Firefly reference):

But Swift clearly took inspiration from Groovy on the following aspects.

Groovy and Swift (as well as other scripting languages) do have that concept of script, where free-standing statements don’t need to be bundled into some kind of class structure, making scripting languages nice for the REPL feedback loop.

The syntax for lists and maps is the same in Swift and Groovy, with a comma-separated list of values surrounded by square brackets for lists, and key:value pairs comma-separated and surrounded again by square brackets for creating maps. The empty map is also the same with the [:] syntax.

// Swift 
var shoppingList = ["catfish", "water", "tulips", "blue paint"] 
shoppingList[1] = "bottle of water"   
    
var occupations = [     
  "Malcolm": "Captain",     
  "Kaylee": "Mechanic", 
] 
occupations["Jayne"] = "Public Relations" 
var emptyMap = [:] 
var emptyList = [] 

// Groovy 
def shoppingList = ["catfish", "water", "tulips", "blue paint"] 
shoppingList[1] = "bottle of water"   

def occupations = [     
  "Malcolm": "Captain",     
  "Kaylee": "Mechanic", 
] 
occupations["Jayne"] = "Public Relations" 
def emptyMap = [:] 
def emptyList = []

(Eric) #2

Nice! That’s fortuitous timing, given that I’ve just started poking around with Groovy for SmartThings and that I’ve maybe got some app ideas bouncing around in my head.

Have the SmartThings developers gotten a chance to really dig into the docs yet? Any first impressions?