SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Sugar :
  More sweetness for
programming languages

        Sébastien Pierre, Datalicious
    @FreeHackers's Union Mtl, Mar. 2009
www.datalicious.ca | github.com/sebastien/sugar
1: The Origin
Much in common

Many languages
…   Java, C#, Python, Ruby, JavaScript, ActionScript ....
have a lot in common
Primitive types : numbers, strings, arrays, etc.
Control structures : if, for, while, etc.
Constructs : functions, objects, modules, etc.

                                                            3
So what's the difference ?
Syntax, of course !


F (1)                     (Algol­style)
(f 1)                     (Lisp­style)
[f withN:1]               (Smalltalk­style)
f←1                       (Why not ?)



                                              4
Syntax only ?
Well, we have traits*


Never change anything                                (Purely functional)
Everything is an object                              (Purely object­oriented)
Evaluate only when needed                            (Lazy evaluation)
Code as data                                         (Homoiconic)

* we could actually call that “ language features”


                                                                                5
Syntax, Traits, and ... ?
…   the base library !


Lisp        : lambda, car, cdr
C           : libc, POSIX
JavaScript : ECMA standard library
Java        : everything but the kitchen sink



                                                6
The Idea
Considerations
Languages have a lot in common
But I keep rewriting the same code in different languages
I came to learn how I prefer to express myself
Ideally
I would like to write once, in my syntax of choice
And translate to the target language

                                                            7
However...
Languages are still “ black boxes”
Cannot change syntax easily
Difficult to access program representation


We think that the program is the source code, but...
The source code is one expression of the program
The program is a compound construct interpreted by a
  runtime system
                                                       8
So...
Let's do “ something*” that
Is a syntactic wrapper for other languages
Offers full program model representation
Translates to commonly used languages
Can be easily customized by mortals

* This would be a program that writes programs (meta­program)




                                                                9
2: Sugar
A Meta­Programming
     Language




                     10
It's all about syntax
And we can have the luxury to design it !


readability       : visual cues, typographic rhythm
expressiveness : constructs to describe common patterns
consistency       : many developers, same code
accessibility     : learn it in a few hours



                                                          11
We can reuse a lot
We take advantage of
  Language­specific primitive types (lists, maps)
  Language­specific libraries (file, os, etc.)
And we provide
  Abstraction over language­specific traits
  Emulation of non­supported primitive types, constructs or
   operations



                                                              12
Design Goals
“ A program is a design expressed in code”
Goals
   Be learned in a couple of hours
   Put focus on software architecture
   Encourage clear, readable code
   Favor thinking over typing




                                             13
Inspiration

Python               : expressiveness and consistency
Eiffel               : formalizing structure and dynamics
Smalltalk : objects and message­passing
JavaScript : functions and objects having fun together !

And indirectly, Lisp, Io, Erlang and Scala.




                                                            14
The syntax : Primitive Types
Lists
   []   [1,2,3]        [“ a” , 2, [3, 4]]


Maps/objects­as­maps
   {}   {a:1, b:2}     {name:” bob” , email:” bob@gmail.com” }


And of course... numbers
   1    ­1.0           0xFFAAD0

                                                                 15
The syntax : Indexes and Slices
value [ start index : end index]
   var list     =      [1,2,3,4,5,6,7,8,9]
   list [0]            1                     (first element)
   list [­1]           9                     (last element)


   list [:]            [1,2,3,4,5,6,7,8,9]   (list copy)
   list [1:]           [2,3,4,5,6,7,8,9]     (copy after index 1)
   list [:­1]          [1,2,3,4,5,6,7,8]     (copy until last index)

                                                                       16
The syntax : Iterators
The traditional “ for each in”
   for value, index in [1,2,3,4]
         print (value, index)
   end
With objects too, one one line
   for value, index in {a:1,b:2,c:3} ­> print (value, index)
And the compact form (with a closure)
   [1,2,3,4] :: {v,k | print (v,k) }


                                                               17
The syntax : Closures
Closures as blocks
   var hello = {message|
        print (“ You said:” + message)
   }


Compact syntax for callbacks (here using jQuery)
   $ (“ .sayhello” ) click {alert (“ say hello” )}




                                                     18
The syntax : Idioms (1)
Spaces instead of dots
   var user = {name:” bob” , email:” bob gmail.com” }
   print (user name)


Why ?
   Less dense code / more whitespace
   space denotes “ message sending”
   dot   denotes “ structural resolution” (ask me for details ;)

                                                                   19
The syntax : Idioms (2)
Indentation instead of commas or semicolons
  var user = {name:” bob” , email:” bob@gmail.com” }
  var user = {
                                      ← no trailing comma here
        name     : “ bob”
        email    : “ bob@gmail.com”
  }
Why ?
  Got too many errors for missing or extra trailing comma


                                                                 20
The syntax : Idioms (3)
Optional parens in single­argument invocations
   print “ Hello, world !”
   user addPoints 10
   $ “ .sayhello” click {alert “ Hello” }
   article setAuthor 'user                  ← single quote to denote single­argument



Why ?
   A lot of invocations are single argument


                                                                                       21
The syntax: Constructs
Constructs start with @, body is indented
   @function name arg1, arg2,...rest
   | Documentation string
       ...
   @end
The flavors
   @module, @function
   @class, @property, @shared, @constructor, @method, @operation



                                                                   22
Under The Hood
Full program model API (LambdaFactory)
  Constructs Program, Module, Class, Function, ...
  Control     Iteration, Selection, ...
  Operations Computation, Evaluation, Resolution


Meta­programming
  Flexible plug­in “ program pass” system:
  Modify, manipulate, analyze your program

                                                     23
Plugin Languages
Multiple back­ends (provided by LambdaFactory)
   JavaScript             (production quality)
   ActionScript           (not so bad)
   Python                 (mature, but missing some stuff)
   Pnuts                  (for fast scripting on the JDK)


Multiple front­ends
   Sugar is just one of them !

                                                             24
3: What's In It for Me ?
     Sugar in practice




                           25
Why would I use Sugar ?
To replace JavaScript for front (or back) end Web dev :


     simplified syntax          fewer errors
     simplified semantics       less surprised
     higher level constructs    more structured code
     easy to learn              no excuse !



                                                          26
You will code like Douglas Crockford !
                                                                In Sugar (with mandatory indentation)
In JavaScript
                                                                var requestNumber = JSONRequest post (
requestNumber = JSONRequest.post(
                                                                  quot;https://json.penzance.org/requestquot;
   quot;https://json.penzance.org/requestquot;,
                                                                  {
   {
                                                                     user        : quot;doctoravatar@yahoo.comquot;
      user: quot;doctoravatar@yahoo.comquot;,
                                                                     t           : quot;vlIjquot;
      t: quot;vlIjquot;,
                                                                     zip         : 94089
      zip: 94089,
                                                                     forecast : 7
      forecast: 7
                                                                  }
   },
                                                                  {requestNumber, value, exception|
   function (requestNumber, value, exception) {
                                                                     if value
      if (value) {
                                                                        processResponse(value)
         processResponse(value);
                                                                     else
      } else {
                                                                        processError(exception)
         processError(exception);
                                                                     end
      }
                                                                  }
   }
                                                                )
);
From Douglas Crockford : http://www.json.org/JSONRequest.html

                                                                                                              27
Get started !
You'll need
   Python 2.4+


And install these
   git clone git://github.com/sebastien/lambdafactory.git
   git clone git://github.com/sebastien/sugar.git




                                                            28
The end



Thank you !
   www.datalicious.ca
www.github.com/sebastien
 sebastien@datalicious.ca

Mais conteúdo relacionado

Mais procurados

Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric SystemErin Dees
 
Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Chicago Hadoop Users Group
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web appschrisbuckett
 
F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformHoward Mansell
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovypaulbowler
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting languageVamshi Santhapuri
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroadJim Jones
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoadwebuploader
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015Jorg Janke
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1ppJ. C.
 

Mais procurados (20)

Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
Dart programming language
Dart programming languageDart programming language
Dart programming language
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
 
Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web apps
 
Dart ppt
Dart pptDart ppt
Dart ppt
 
F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical Platform
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Start dart
Start dartStart dart
Start dart
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
 

Destaque

Java Script入門
Java Script入門Java Script入門
Java Script入門guest87c6b0
 
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8spierre
 
Bulletin_2 2009_SF
Bulletin_2 2009_SFBulletin_2 2009_SF
Bulletin_2 2009_SFSemyon Fomin
 
Sample research by S.Fomin_PIK_rus
Sample research by S.Fomin_PIK_rusSample research by S.Fomin_PIK_rus
Sample research by S.Fomin_PIK_rusSemyon Fomin
 
State Corporations_2009_SF
State Corporations_2009_SFState Corporations_2009_SF
State Corporations_2009_SFSemyon Fomin
 
Вводное занятие_СФ_для загрузки
Вводное занятие_СФ_для загрузкиВводное занятие_СФ_для загрузки
Вводное занятие_СФ_для загрузкиSemyon Fomin
 

Destaque (7)

Java Script入門
Java Script入門Java Script入門
Java Script入門
 
Turkey
TurkeyTurkey
Turkey
 
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
 
Bulletin_2 2009_SF
Bulletin_2 2009_SFBulletin_2 2009_SF
Bulletin_2 2009_SF
 
Sample research by S.Fomin_PIK_rus
Sample research by S.Fomin_PIK_rusSample research by S.Fomin_PIK_rus
Sample research by S.Fomin_PIK_rus
 
State Corporations_2009_SF
State Corporations_2009_SFState Corporations_2009_SF
State Corporations_2009_SF
 
Вводное занятие_СФ_для загрузки
Вводное занятие_СФ_для загрузкиВводное занятие_СФ_для загрузки
Вводное занятие_СФ_для загрузки
 

Semelhante a Sugar Presentation - YULHackers March 2009

Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Michał Konarski
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Ary Borenszweig
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Ary Borenszweig
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Crystal Language
 
Why hadoop map reduce needs scala, an introduction to scoobi and scalding
Why hadoop map reduce needs scala, an introduction to scoobi and scaldingWhy hadoop map reduce needs scala, an introduction to scoobi and scalding
Why hadoop map reduce needs scala, an introduction to scoobi and scaldingXebia Nederland BV
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaDmitry Buzdin
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...Maarten Balliauw
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futureTakayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionEelco Visser
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming languageMario Castro Contreras
 
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...InfinIT - Innovationsnetværket for it
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 

Semelhante a Sugar Presentation - YULHackers March 2009 (20)

Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Why hadoop map reduce needs scala, an introduction to scoobi and scalding
Why hadoop map reduce needs scala, an introduction to scoobi and scaldingWhy hadoop map reduce needs scala, an introduction to scoobi and scalding
Why hadoop map reduce needs scala, an introduction to scoobi and scalding
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
Java
JavaJava
Java
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming language
 
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Sugar Presentation - YULHackers March 2009

  • 1. Sugar : More sweetness for programming languages Sébastien Pierre, Datalicious @FreeHackers's Union Mtl, Mar. 2009 www.datalicious.ca | github.com/sebastien/sugar
  • 3. Much in common Many languages … Java, C#, Python, Ruby, JavaScript, ActionScript .... have a lot in common Primitive types : numbers, strings, arrays, etc. Control structures : if, for, while, etc. Constructs : functions, objects, modules, etc. 3
  • 4. So what's the difference ? Syntax, of course ! F (1) (Algol­style) (f 1) (Lisp­style) [f withN:1] (Smalltalk­style) f←1 (Why not ?) 4
  • 5. Syntax only ? Well, we have traits* Never change anything (Purely functional) Everything is an object (Purely object­oriented) Evaluate only when needed (Lazy evaluation) Code as data (Homoiconic) * we could actually call that “ language features” 5
  • 6. Syntax, Traits, and ... ? … the base library ! Lisp : lambda, car, cdr C : libc, POSIX JavaScript : ECMA standard library Java : everything but the kitchen sink 6
  • 7. The Idea Considerations Languages have a lot in common But I keep rewriting the same code in different languages I came to learn how I prefer to express myself Ideally I would like to write once, in my syntax of choice And translate to the target language 7
  • 8. However... Languages are still “ black boxes” Cannot change syntax easily Difficult to access program representation We think that the program is the source code, but... The source code is one expression of the program The program is a compound construct interpreted by a runtime system 8
  • 9. So... Let's do “ something*” that Is a syntactic wrapper for other languages Offers full program model representation Translates to commonly used languages Can be easily customized by mortals * This would be a program that writes programs (meta­program) 9
  • 11. It's all about syntax And we can have the luxury to design it ! readability : visual cues, typographic rhythm expressiveness : constructs to describe common patterns consistency : many developers, same code accessibility : learn it in a few hours 11
  • 12. We can reuse a lot We take advantage of Language­specific primitive types (lists, maps) Language­specific libraries (file, os, etc.) And we provide Abstraction over language­specific traits Emulation of non­supported primitive types, constructs or operations 12
  • 13. Design Goals “ A program is a design expressed in code” Goals Be learned in a couple of hours Put focus on software architecture Encourage clear, readable code Favor thinking over typing 13
  • 14. Inspiration Python : expressiveness and consistency Eiffel : formalizing structure and dynamics Smalltalk : objects and message­passing JavaScript : functions and objects having fun together ! And indirectly, Lisp, Io, Erlang and Scala. 14
  • 15. The syntax : Primitive Types Lists [] [1,2,3] [“ a” , 2, [3, 4]] Maps/objects­as­maps {} {a:1, b:2} {name:” bob” , email:” bob@gmail.com” } And of course... numbers 1 ­1.0 0xFFAAD0 15
  • 16. The syntax : Indexes and Slices value [ start index : end index] var list = [1,2,3,4,5,6,7,8,9] list [0] 1 (first element) list [­1] 9 (last element) list [:] [1,2,3,4,5,6,7,8,9] (list copy) list [1:] [2,3,4,5,6,7,8,9] (copy after index 1) list [:­1] [1,2,3,4,5,6,7,8] (copy until last index) 16
  • 17. The syntax : Iterators The traditional “ for each in” for value, index in [1,2,3,4] print (value, index) end With objects too, one one line for value, index in {a:1,b:2,c:3} ­> print (value, index) And the compact form (with a closure) [1,2,3,4] :: {v,k | print (v,k) } 17
  • 18. The syntax : Closures Closures as blocks var hello = {message| print (“ You said:” + message) } Compact syntax for callbacks (here using jQuery) $ (“ .sayhello” ) click {alert (“ say hello” )} 18
  • 19. The syntax : Idioms (1) Spaces instead of dots var user = {name:” bob” , email:” bob gmail.com” } print (user name) Why ? Less dense code / more whitespace space denotes “ message sending” dot denotes “ structural resolution” (ask me for details ;) 19
  • 20. The syntax : Idioms (2) Indentation instead of commas or semicolons var user = {name:” bob” , email:” bob@gmail.com” } var user = { ← no trailing comma here name : “ bob” email : “ bob@gmail.com” } Why ? Got too many errors for missing or extra trailing comma 20
  • 21. The syntax : Idioms (3) Optional parens in single­argument invocations print “ Hello, world !” user addPoints 10 $ “ .sayhello” click {alert “ Hello” } article setAuthor 'user ← single quote to denote single­argument Why ? A lot of invocations are single argument 21
  • 22. The syntax: Constructs Constructs start with @, body is indented @function name arg1, arg2,...rest | Documentation string ... @end The flavors @module, @function @class, @property, @shared, @constructor, @method, @operation 22
  • 23. Under The Hood Full program model API (LambdaFactory) Constructs Program, Module, Class, Function, ... Control Iteration, Selection, ... Operations Computation, Evaluation, Resolution Meta­programming Flexible plug­in “ program pass” system: Modify, manipulate, analyze your program 23
  • 24. Plugin Languages Multiple back­ends (provided by LambdaFactory) JavaScript (production quality) ActionScript (not so bad) Python (mature, but missing some stuff) Pnuts (for fast scripting on the JDK) Multiple front­ends Sugar is just one of them ! 24
  • 25. 3: What's In It for Me ? Sugar in practice 25
  • 26. Why would I use Sugar ? To replace JavaScript for front (or back) end Web dev : simplified syntax fewer errors simplified semantics less surprised higher level constructs more structured code easy to learn no excuse ! 26
  • 27. You will code like Douglas Crockford ! In Sugar (with mandatory indentation) In JavaScript var requestNumber = JSONRequest post ( requestNumber = JSONRequest.post( quot;https://json.penzance.org/requestquot; quot;https://json.penzance.org/requestquot;, { { user : quot;doctoravatar@yahoo.comquot; user: quot;doctoravatar@yahoo.comquot;, t : quot;vlIjquot; t: quot;vlIjquot;, zip : 94089 zip: 94089, forecast : 7 forecast: 7 } }, {requestNumber, value, exception| function (requestNumber, value, exception) { if value if (value) { processResponse(value) processResponse(value); else } else { processError(exception) processError(exception); end } } } ) ); From Douglas Crockford : http://www.json.org/JSONRequest.html 27
  • 28. Get started ! You'll need Python 2.4+ And install these git clone git://github.com/sebastien/lambdafactory.git git clone git://github.com/sebastien/sugar.git 28
  • 29. The end Thank you ! www.datalicious.ca www.github.com/sebastien sebastien@datalicious.ca