SlideShare a Scribd company logo
1 of 51
eero
objective-c, evolved

  Andy Arvanitis
What is Eero?

  •    A programming language

      •    It is a dialect of Objective-C

      •    It has a streamlined syntax

      •    It is binary- and header-compatible with
           Objective-C

      •    Its toolchain is implemented using a
           continuously updated fork of LLVM/Clang
           (trunk)

Cocoaheads-SF                                     Aug. 9, 2012
Why did I do this?

  •    My background: I’ve mostly worked for large
       companies, large organizations, often large
       teams

  •    Whether an architect or individual contributor, I
       end up reading lots and lots of other people’s
       code

  •    Even reading your own code after a few
       months (or years) is like reading someone
       else’s code

Cocoaheads-SF                                    Aug. 9, 2012
Code readability

  •    Code is read much more often than it’s written

  •    Human “parsability” of code is critical

  •    Readability matters A LOT! And when it comes
       to a programming language, it’s not “just
       syntactic sugar”

  •    Eero is an unrepentant project about syntactic
       sugar



Cocoaheads-SF                                    Aug. 9, 2012
Eero goals

  •    To be a practical tool, not just an experiment

  •    To reuse ALL Objective-C frameworks out
       there, as seamlessly as possible

  •    To keep Objective-C strengths: named
       parameters, type checking, performance,
       interoperability with C libraries, tools




Cocoaheads-SF                                    Aug. 9, 2012
Eero principles

  •    DRY

  •    WYSIWYG (POLS)

  •    Make the compiler, not the human, do the
       work




Cocoaheads-SF                                 Aug. 9, 2012
Eero techniques

  •    Remove clutter without introducing ambiguity

  •    Avoid “syntactic saccharin”

  •    Employ sane defaults




Cocoaheads-SF                                 Aug. 9, 2012
General code-
structure changes
Significant whitespace

  •    Offside-rule, à la Python

  •    Lots of controversy — strong opinions on both
       sides

  •    Personally, I wasn’t so sure about it at first, but
       grew to appreciate/love it




Cocoaheads-SF                                      Aug. 9, 2012
Significant whitespace — why?

  •    WYSIWYG / DRY:

      •    most agree that blocks should be indented

      •    Why should I have to indent and use
           braces?

  •    Readability! — less visual clutter




Cocoaheads-SF                                    Aug. 9, 2012
Optional semicolons

  •    Readability (less visual clutter)

  •    DRY

  •    Good compilers generally know where they
       should go. Why should I have to do it? (works
       best when newline is significant)

      •    Clang very good for this, made it easy to
           implement



Cocoaheads-SF                                     Aug. 9, 2012
Local type inference

  •    The := operator specifies a variable definition
       and assignment, with the type inferred from
       the value

  •    Same behavior as C++11’s “auto”


   counter := 0   // infers an int

   const title := ”hello, world”




Cocoaheads-SF                                    Aug. 9, 2012
Local type inference

  •    Gains some of the conciseness advantages of
       Ruby/Python, but a bit safer

      •    Compiler can still catch typos in subsequent
           assignments

  •    Normal = assignment operator remains
       unchanged




Cocoaheads-SF                                    Aug. 9, 2012
Namespace-like prefixes

  •    Eero does not introduce a true namespace
       facility, but instead works with existing
       Objective-C prefix conventions

  •    Prefixes can be “registered” within a scope

  •    If a symbol (class, type, function, etc.) is not
       found by the compiler, it tries again, with prefix

  •    The “NS” prefix is built-in, e.g., “String”
       resolves to “NSString”


Cocoaheads-SF                                        Aug. 9, 2012
Namespace-like prefixes, cont.

  •    User-defined prefixes

      •    Eero introduces keyword using (borrowed
           from C++), and context keyword prefix

      •    To register prefix: using prefix XX

      •    Declared (and valid) within an enclosing
           scope: file, method, function, conditional
           block, etc.



Cocoaheads-SF                                      Aug. 9, 2012
Example

   using prefix UI // file scope

   int myFunction()

      using prefix AB // only in function scope

      AddressBook addressBook = nil

      Log(...) // resolves to NSLog()

      return 0




Cocoaheads-SF                                     Aug. 9, 2012
Objective-C–specific
     changes
Objective-C keywords

  •    Objective-C keywords “promoted” to first-class
       keywords

      •    @ no longer needed in front of them



   interface MyClass : Object
   ...
   end




Cocoaheads-SF                                    Aug. 9, 2012
NSString literals

  •    No @, enclosed in single quotes

  •    C string literals remain in double-quotes




   title := ’hello, world’




Cocoaheads-SF                                      Aug. 9, 2012
Array and dictionary literals

  •    Neither type of literal needs @




   myArray := [’a’, ’b’, ’c’]

   myDict := {’A’ : ’a’, ’B’ : ’b’}




Cocoaheads-SF                            Aug. 9, 2012
Array and dictionary literals

  •    Since we’re on the topic: empty object literals
       are mutable




   myMutableArray := []

   myMutableDict := {}

   myMutableString := ’’




Cocoaheads-SF                                    Aug. 9, 2012
NSRange literals

  •    Alternative to NSMakeRange() or C99’s
       (NSRange){ start, length }

  •    Accepts any integer values, not just numeric
       literals


   range := 1 .. 10

   otherRange := kFirst .. kLast




Cocoaheads-SF                                  Aug. 9, 2012
Objects are always pointers

  •    In Objective-C, we never have objects on the
       stack, so it is never valid to declare a non-
       pointer object variable

  •    Eero assumes you mean a pointer; nothing
       else is valid anyway

      •    Consistent with message-passing syntax

   String title = ’Hello, World!’




Cocoaheads-SF                                  Aug. 9, 2012
Methods and
message-passing
Message-passing sans brackets

  •    Like Smalltalk, message passing is done
       without square brackets

  •    However, commas are used to help humans
       (and the compiler) disambiguate selectors/
       parameters

  •    Message-passing expressions are just like any
       other expression; they can be put in
       parentheses, if needed


Cocoaheads-SF                                    Aug. 9, 2012
Examples

   names := []

   names addObject: ’Saarinen’

   names insertObject: ‘Eero’, atIndex: 0

   names addObject: (otherNames objectAtIndex: 0)




Cocoaheads-SF                                       Aug. 9, 2012
Method declarations

  •    An observation: argument variable names are
       not really needed in interfaces

      •    The users of the method don’t care about
           them (it’s an implementation detail)

      •    The implementor of the method doesn’t
           need to make variable naming decisions
           when designing just the interface




Cocoaheads-SF                                   Aug. 9, 2012
Method declarations, cont.

  •    Another observation: argument variable
       names tend to be very similar to (or derived
       from) their selector names

      •    Can we use sane defaults?

      •    When we do need to specify arg variable
           names, can we get something a little more
           consistent with normal variable declarations
           (maybe without those parentheses)?


Cocoaheads-SF                                    Aug. 9, 2012
Method declarations in Eero

  •    Argument variable names default to last
       camel-case word in selector (see site for more
       details)

      •    Similar to Apple’s approach to properties/
           setters

      •    Override with variable name following type,
           just like a normal declaration




Cocoaheads-SF                                     Aug. 9, 2012
Example

   @interface MyNotificationCenterClass

    -(void)addObserver:(id)observer
              selector:(SEL)selector
                  name:(NSString *)notificationName
                object:(id)object;

   @end




Cocoaheads-SF                                     Aug. 9, 2012
Example

   interface MyNotificationCenterClass

                addObserver:   id,
                   selector:   SEL,
                       name:   String,
                     object:   SEL

   end




Cocoaheads-SF                            Aug. 9, 2012
Example

   implementation MyNotificationCenterClass

                addObserver:   id,
                   selector:   SEL,
                       name:   String,
                     object:   SEL

                    if observer == nil
                        ...

   end




Cocoaheads-SF                                 Aug. 9, 2012
Example

   implementation MyNotificationCenterClass

                addObserver:   id,
                   selector:   SEL,
                       name:   String notificationName,
                     object:   SEL

                    if observer == nil
                        ...

   end




Cocoaheads-SF                                             Aug. 9, 2012
Method declarations in Eero

  •    Note: there are a couple of (subtle) departures
       from Objective-C

      •    Parameter types are no longer optional
           (they do not default to id)

      •    When absent, return type no longer defaults
           to id, it now means no return value at all,
           i.e., void — WYSIWYG




Cocoaheads-SF                                   Aug. 9, 2012
Optional and default parameters

  •    Eero’s method prototype syntax allows
       specification of optional parameters (selector
       pieces) and default values

      •    Optional parameters are enclosed in square
           brackets in the interface (mirroring common
           software/tech-doc convention)

      •    Defaults are assigned in the implementation
           using “= value” (they are, in fact, an
           implementation detail)

Cocoaheads-SF                                   Aug. 9, 2012
Example
   interface MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                  name: String,
                object: SEL
   end

   implementation MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                  name: String,
                object: SEL

                if name == nil
                    ...
   end


Cocoaheads-SF                                 Aug. 9, 2012
Example
   interface MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                 [name: String],
                object: SEL
   end

   implementation MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                  name: String,
                object: SEL

                if name == nil
                    ...
   end


Cocoaheads-SF                                 Aug. 9, 2012
Example
   interface MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                 [name: String],
                object: SEL
   end

   implementation MyNotificationCenterClass
           addObserver: id,
              selector: SEL,
                  name: String = nil,
                object: SEL

                if name == nil
                    ...
   end


Cocoaheads-SF                                 Aug. 9, 2012
Optional and default parameters

  •    This is all just sugar, and doesn’t introduce
       any semantic changes

      •    The compiler simply generates the
           appropriate method interfaces and
           implementations

  •    You can mix/match these with existing
       Objective-C classes




Cocoaheads-SF                                     Aug. 9, 2012
Object operators
Object subscript operators

  •    Same support recently added to Objective-C
       (although Eero had them first ;-)

      •    Integers imply array operations; objects
           imply dictionary operations

  •    Eero introduces support for NSRange
       subscripts

      •    If a string, slice via substringWithRange

      •    Otherwise, slice via subarrayWithRange

Cocoaheads-SF                                     Aug. 9, 2012
Example
   implementation MyClass

         + truncateString: String, return String
             if string.length > 10
                 truncatedString := string[0 .. 9]
                 return truncatedString
             return string




   end



Cocoaheads-SF                                        Aug. 9, 2012
Example
   implementation MyClass

         + truncateString: String, return String
             if string.length > 10
                 truncatedString := string[0 .. 9]
                 return truncatedString
             return string

         + truncateArray: Array, return Array
             if array.length > 100
                 truncatedArray := array[0 .. 99]
                 return truncatedArray
             return array
   end



Cocoaheads-SF                                        Aug. 9, 2012
Overloadable binary operators

  •    Supported operators are + - * / < >

      •    Includes implicit support for operator/equal
           variants (+=, -=, <=, etc.)

  •    Each of these map to method selectors plus,
       minus, multipliedBy, isLess, etc.

      •    Overloaded by implementing any of these
           methods



Cocoaheads-SF                                     Aug. 9, 2012
Example
   // Defining some string comparison operators using
   // a category

   implementation String (operators)

         isLess: String string, return BOOL
             const comparison := self compare: string
             return (comparison == OrderedAscending)

         isGreater: String string, return BOOL
             const comparison := self compare: string
             return (comparison == OrderedDescending)

   end




Cocoaheads-SF                                       Aug. 9, 2012
Example
   // Using the string comparison operator ‘<‘ from
   // the category

   name := ‘Eames’
   previousName := ‘Saarinen’

   if name < previousName
       ...




Cocoaheads-SF                                     Aug. 9, 2012
Overloadable operators, cont.

  •    There are some built-in operators

      •    == and != via isEqual for all object types

      •    If object is a String, + is concatenation via
           stringWithString

      •    If object is a MutableString, << is
           concatenation via appendString




Cocoaheads-SF                                       Aug. 9, 2012
Example

         hello := ’hello’
         world := ’world’

         title := hello + ’, ’ + world

         // title is now ‘hello, world’

         itemName   :=   ’’
         itemName   <<   ‘tulip’
         itemName   <<   ’ ’
         itemName   <<   ‘chair’

         // itemName is now ‘tulip chair’




Cocoaheads-SF                               Aug. 9, 2012
Other features

  •    Optional parentheses around conditions

  •    Concise boxing/unboxing

  •    Enhanced blocks (including compact form)

  •    Stricter enum type checking

  •    Enhanced switch/case

  •    And more!



Cocoaheads-SF                                   Aug. 9, 2012
Questions?




Cocoaheads-SF   Aug. 9, 2012
Thank you!

  •    More information:

      •    http://eerolanguage.org

      •    https://github.com/eerolanguage

      •    My twitter: @andyarvanitis




Cocoaheads-SF                                Aug. 9, 2012

More Related Content

Viewers also liked

Matte 1 uke 35
Matte 1 uke 35Matte 1 uke 35
Matte 1 uke 35
annabring
 
Matte 4 uke 35
Matte 4 uke 35Matte 4 uke 35
Matte 4 uke 35
annabring
 
б ъ л г а р с к и е з и к іі кл.
б ъ л г а р с к и     е з и к   іі кл.б ъ л г а р с к и     е з и к   іі кл.
б ъ л г а р с к и е з и к іі кл.
Zlatka Atanasova
 
Matte 2 uke 35
Matte 2 uke 35Matte 2 uke 35
Matte 2 uke 35
annabring
 
Matte 3 uke 35
Matte 3 uke 35Matte 3 uke 35
Matte 3 uke 35
annabring
 

Viewers also liked (15)

Matte 1 uke 35
Matte 1 uke 35Matte 1 uke 35
Matte 1 uke 35
 
Mezcla del marketing social el producto sesión 5
Mezcla del marketing social el producto sesión 5Mezcla del marketing social el producto sesión 5
Mezcla del marketing social el producto sesión 5
 
Matte 4 uke 34
Matte 4 uke 34Matte 4 uke 34
Matte 4 uke 34
 
Matte 1 uke 34
Matte 1 uke 34Matte 1 uke 34
Matte 1 uke 34
 
Matte 4 uke 35
Matte 4 uke 35Matte 4 uke 35
Matte 4 uke 35
 
Promoción,planeación, proceso y personal sesión 7
Promoción,planeación, proceso y personal sesión 7Promoción,planeación, proceso y personal sesión 7
Promoción,planeación, proceso y personal sesión 7
 
Pregnancy
PregnancyPregnancy
Pregnancy
 
б ъ л г а р с к и е з и к іі кл.
б ъ л г а р с к и     е з и к   іі кл.б ъ л г а р с к и     е з и к   іі кл.
б ъ л г а р с к и е з и к іі кл.
 
Matte 2 uke 34
Matte 2 uke 34Matte 2 uke 34
Matte 2 uke 34
 
Matte 2 uke 35
Matte 2 uke 35Matte 2 uke 35
Matte 2 uke 35
 
Matte 3 uke 35
Matte 3 uke 35Matte 3 uke 35
Matte 3 uke 35
 
La mercadotecnia estratégica como cimiento de la comunicación
La mercadotecnia estratégica como cimiento de la comunicaciónLa mercadotecnia estratégica como cimiento de la comunicación
La mercadotecnia estratégica como cimiento de la comunicación
 
Precio y plaza sesion 6
Precio y plaza sesion 6Precio y plaza sesion 6
Precio y plaza sesion 6
 
Pregnancy
PregnancyPregnancy
Pregnancy
 
Project report on Raj Express Newspaper
Project report on Raj Express NewspaperProject report on Raj Express Newspaper
Project report on Raj Express Newspaper
 

Similar to Eero cocoaheadssf-talk

Obj-C and iOS for .NET Developers
Obj-C and iOS for .NET DevelopersObj-C and iOS for .NET Developers
Obj-C and iOS for .NET Developers
escoz
 

Similar to Eero cocoaheadssf-talk (20)

Intro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CIntro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-C
 
Irving iOS Jumpstart Meetup - Objective-C Session 2
Irving iOS Jumpstart Meetup - Objective-C Session 2Irving iOS Jumpstart Meetup - Objective-C Session 2
Irving iOS Jumpstart Meetup - Objective-C Session 2
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Oops
OopsOops
Oops
 
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
 
oodb.ppt
oodb.pptoodb.ppt
oodb.ppt
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talk
 
Understanding iOS from an Android perspective
Understanding iOS from an Android perspectiveUnderstanding iOS from an Android perspective
Understanding iOS from an Android perspective
 
Objc
ObjcObjc
Objc
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
Eclipse Training - Introduction
Eclipse Training - IntroductionEclipse Training - Introduction
Eclipse Training - Introduction
 
Oodb
OodbOodb
Oodb
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Metamorphic Domain-Specific Languages
Metamorphic Domain-Specific LanguagesMetamorphic Domain-Specific Languages
Metamorphic Domain-Specific Languages
 
Crash Course in Objective-C
Crash Course in Objective-CCrash Course in Objective-C
Crash Course in Objective-C
 
Obj-C and iOS for .NET Developers
Obj-C and iOS for .NET DevelopersObj-C and iOS for .NET Developers
Obj-C and iOS for .NET Developers
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Eero cocoaheadssf-talk

  • 1. eero objective-c, evolved Andy Arvanitis
  • 2. What is Eero? • A programming language • It is a dialect of Objective-C • It has a streamlined syntax • It is binary- and header-compatible with Objective-C • Its toolchain is implemented using a continuously updated fork of LLVM/Clang (trunk) Cocoaheads-SF Aug. 9, 2012
  • 3. Why did I do this? • My background: I’ve mostly worked for large companies, large organizations, often large teams • Whether an architect or individual contributor, I end up reading lots and lots of other people’s code • Even reading your own code after a few months (or years) is like reading someone else’s code Cocoaheads-SF Aug. 9, 2012
  • 4. Code readability • Code is read much more often than it’s written • Human “parsability” of code is critical • Readability matters A LOT! And when it comes to a programming language, it’s not “just syntactic sugar” • Eero is an unrepentant project about syntactic sugar Cocoaheads-SF Aug. 9, 2012
  • 5. Eero goals • To be a practical tool, not just an experiment • To reuse ALL Objective-C frameworks out there, as seamlessly as possible • To keep Objective-C strengths: named parameters, type checking, performance, interoperability with C libraries, tools Cocoaheads-SF Aug. 9, 2012
  • 6. Eero principles • DRY • WYSIWYG (POLS) • Make the compiler, not the human, do the work Cocoaheads-SF Aug. 9, 2012
  • 7. Eero techniques • Remove clutter without introducing ambiguity • Avoid “syntactic saccharin” • Employ sane defaults Cocoaheads-SF Aug. 9, 2012
  • 9. Significant whitespace • Offside-rule, à la Python • Lots of controversy — strong opinions on both sides • Personally, I wasn’t so sure about it at first, but grew to appreciate/love it Cocoaheads-SF Aug. 9, 2012
  • 10. Significant whitespace — why? • WYSIWYG / DRY: • most agree that blocks should be indented • Why should I have to indent and use braces? • Readability! — less visual clutter Cocoaheads-SF Aug. 9, 2012
  • 11. Optional semicolons • Readability (less visual clutter) • DRY • Good compilers generally know where they should go. Why should I have to do it? (works best when newline is significant) • Clang very good for this, made it easy to implement Cocoaheads-SF Aug. 9, 2012
  • 12. Local type inference • The := operator specifies a variable definition and assignment, with the type inferred from the value • Same behavior as C++11’s “auto” counter := 0 // infers an int const title := ”hello, world” Cocoaheads-SF Aug. 9, 2012
  • 13. Local type inference • Gains some of the conciseness advantages of Ruby/Python, but a bit safer • Compiler can still catch typos in subsequent assignments • Normal = assignment operator remains unchanged Cocoaheads-SF Aug. 9, 2012
  • 14. Namespace-like prefixes • Eero does not introduce a true namespace facility, but instead works with existing Objective-C prefix conventions • Prefixes can be “registered” within a scope • If a symbol (class, type, function, etc.) is not found by the compiler, it tries again, with prefix • The “NS” prefix is built-in, e.g., “String” resolves to “NSString” Cocoaheads-SF Aug. 9, 2012
  • 15. Namespace-like prefixes, cont. • User-defined prefixes • Eero introduces keyword using (borrowed from C++), and context keyword prefix • To register prefix: using prefix XX • Declared (and valid) within an enclosing scope: file, method, function, conditional block, etc. Cocoaheads-SF Aug. 9, 2012
  • 16. Example using prefix UI // file scope int myFunction() using prefix AB // only in function scope AddressBook addressBook = nil Log(...) // resolves to NSLog() return 0 Cocoaheads-SF Aug. 9, 2012
  • 18. Objective-C keywords • Objective-C keywords “promoted” to first-class keywords • @ no longer needed in front of them interface MyClass : Object ... end Cocoaheads-SF Aug. 9, 2012
  • 19. NSString literals • No @, enclosed in single quotes • C string literals remain in double-quotes title := ’hello, world’ Cocoaheads-SF Aug. 9, 2012
  • 20. Array and dictionary literals • Neither type of literal needs @ myArray := [’a’, ’b’, ’c’] myDict := {’A’ : ’a’, ’B’ : ’b’} Cocoaheads-SF Aug. 9, 2012
  • 21. Array and dictionary literals • Since we’re on the topic: empty object literals are mutable myMutableArray := [] myMutableDict := {} myMutableString := ’’ Cocoaheads-SF Aug. 9, 2012
  • 22. NSRange literals • Alternative to NSMakeRange() or C99’s (NSRange){ start, length } • Accepts any integer values, not just numeric literals range := 1 .. 10 otherRange := kFirst .. kLast Cocoaheads-SF Aug. 9, 2012
  • 23. Objects are always pointers • In Objective-C, we never have objects on the stack, so it is never valid to declare a non- pointer object variable • Eero assumes you mean a pointer; nothing else is valid anyway • Consistent with message-passing syntax String title = ’Hello, World!’ Cocoaheads-SF Aug. 9, 2012
  • 25. Message-passing sans brackets • Like Smalltalk, message passing is done without square brackets • However, commas are used to help humans (and the compiler) disambiguate selectors/ parameters • Message-passing expressions are just like any other expression; they can be put in parentheses, if needed Cocoaheads-SF Aug. 9, 2012
  • 26. Examples names := [] names addObject: ’Saarinen’ names insertObject: ‘Eero’, atIndex: 0 names addObject: (otherNames objectAtIndex: 0) Cocoaheads-SF Aug. 9, 2012
  • 27. Method declarations • An observation: argument variable names are not really needed in interfaces • The users of the method don’t care about them (it’s an implementation detail) • The implementor of the method doesn’t need to make variable naming decisions when designing just the interface Cocoaheads-SF Aug. 9, 2012
  • 28. Method declarations, cont. • Another observation: argument variable names tend to be very similar to (or derived from) their selector names • Can we use sane defaults? • When we do need to specify arg variable names, can we get something a little more consistent with normal variable declarations (maybe without those parentheses)? Cocoaheads-SF Aug. 9, 2012
  • 29. Method declarations in Eero • Argument variable names default to last camel-case word in selector (see site for more details) • Similar to Apple’s approach to properties/ setters • Override with variable name following type, just like a normal declaration Cocoaheads-SF Aug. 9, 2012
  • 30. Example @interface MyNotificationCenterClass -(void)addObserver:(id)observer selector:(SEL)selector name:(NSString *)notificationName object:(id)object; @end Cocoaheads-SF Aug. 9, 2012
  • 31. Example interface MyNotificationCenterClass addObserver: id, selector: SEL, name: String, object: SEL end Cocoaheads-SF Aug. 9, 2012
  • 32. Example implementation MyNotificationCenterClass addObserver: id, selector: SEL, name: String, object: SEL if observer == nil ... end Cocoaheads-SF Aug. 9, 2012
  • 33. Example implementation MyNotificationCenterClass addObserver: id, selector: SEL, name: String notificationName, object: SEL if observer == nil ... end Cocoaheads-SF Aug. 9, 2012
  • 34. Method declarations in Eero • Note: there are a couple of (subtle) departures from Objective-C • Parameter types are no longer optional (they do not default to id) • When absent, return type no longer defaults to id, it now means no return value at all, i.e., void — WYSIWYG Cocoaheads-SF Aug. 9, 2012
  • 35. Optional and default parameters • Eero’s method prototype syntax allows specification of optional parameters (selector pieces) and default values • Optional parameters are enclosed in square brackets in the interface (mirroring common software/tech-doc convention) • Defaults are assigned in the implementation using “= value” (they are, in fact, an implementation detail) Cocoaheads-SF Aug. 9, 2012
  • 36. Example interface MyNotificationCenterClass addObserver: id, selector: SEL, name: String, object: SEL end implementation MyNotificationCenterClass addObserver: id, selector: SEL, name: String, object: SEL if name == nil ... end Cocoaheads-SF Aug. 9, 2012
  • 37. Example interface MyNotificationCenterClass addObserver: id, selector: SEL, [name: String], object: SEL end implementation MyNotificationCenterClass addObserver: id, selector: SEL, name: String, object: SEL if name == nil ... end Cocoaheads-SF Aug. 9, 2012
  • 38. Example interface MyNotificationCenterClass addObserver: id, selector: SEL, [name: String], object: SEL end implementation MyNotificationCenterClass addObserver: id, selector: SEL, name: String = nil, object: SEL if name == nil ... end Cocoaheads-SF Aug. 9, 2012
  • 39. Optional and default parameters • This is all just sugar, and doesn’t introduce any semantic changes • The compiler simply generates the appropriate method interfaces and implementations • You can mix/match these with existing Objective-C classes Cocoaheads-SF Aug. 9, 2012
  • 41. Object subscript operators • Same support recently added to Objective-C (although Eero had them first ;-) • Integers imply array operations; objects imply dictionary operations • Eero introduces support for NSRange subscripts • If a string, slice via substringWithRange • Otherwise, slice via subarrayWithRange Cocoaheads-SF Aug. 9, 2012
  • 42. Example implementation MyClass + truncateString: String, return String if string.length > 10 truncatedString := string[0 .. 9] return truncatedString return string end Cocoaheads-SF Aug. 9, 2012
  • 43. Example implementation MyClass + truncateString: String, return String if string.length > 10 truncatedString := string[0 .. 9] return truncatedString return string + truncateArray: Array, return Array if array.length > 100 truncatedArray := array[0 .. 99] return truncatedArray return array end Cocoaheads-SF Aug. 9, 2012
  • 44. Overloadable binary operators • Supported operators are + - * / < > • Includes implicit support for operator/equal variants (+=, -=, <=, etc.) • Each of these map to method selectors plus, minus, multipliedBy, isLess, etc. • Overloaded by implementing any of these methods Cocoaheads-SF Aug. 9, 2012
  • 45. Example // Defining some string comparison operators using // a category implementation String (operators) isLess: String string, return BOOL const comparison := self compare: string return (comparison == OrderedAscending) isGreater: String string, return BOOL const comparison := self compare: string return (comparison == OrderedDescending) end Cocoaheads-SF Aug. 9, 2012
  • 46. Example // Using the string comparison operator ‘<‘ from // the category name := ‘Eames’ previousName := ‘Saarinen’ if name < previousName ... Cocoaheads-SF Aug. 9, 2012
  • 47. Overloadable operators, cont. • There are some built-in operators • == and != via isEqual for all object types • If object is a String, + is concatenation via stringWithString • If object is a MutableString, << is concatenation via appendString Cocoaheads-SF Aug. 9, 2012
  • 48. Example hello := ’hello’ world := ’world’ title := hello + ’, ’ + world // title is now ‘hello, world’ itemName := ’’ itemName << ‘tulip’ itemName << ’ ’ itemName << ‘chair’ // itemName is now ‘tulip chair’ Cocoaheads-SF Aug. 9, 2012
  • 49. Other features • Optional parentheses around conditions • Concise boxing/unboxing • Enhanced blocks (including compact form) • Stricter enum type checking • Enhanced switch/case • And more! Cocoaheads-SF Aug. 9, 2012
  • 50. Questions? Cocoaheads-SF Aug. 9, 2012
  • 51. Thank you! • More information: • http://eerolanguage.org • https://github.com/eerolanguage • My twitter: @andyarvanitis Cocoaheads-SF Aug. 9, 2012