SlideShare una empresa de Scribd logo
1 de 29
Typ-sichere DSLs
Mit Xtext/TS, Xtend, Groovy und
anderen Sprachen
             Werner Keil

         Eclipse DemoCamp Berlin
              20. Juni 2012
Zielsetzung


          ARITHMETISCHE ODER
          DATENTYP FEHLER BEI DSL
          NUTZUNG VERMEIDEN
2   © 2007-2012 Creative Arts & Technologies
Überblick
• Einleitung
       • Was ist eine DSL?
       • Interne und Externe DSLs
       • Type-Sicherheit

• Einheiten im Gesundheitswesen
       • Unit-API, UOMo
       • UCUM, HL7, Groovy in der Gesundheitsbranche

• Andere Sprachen
       • Jython/WLST
       • Xtext/Xbase/Xtend
       • Scala, Fantom, F#

• Demo
• Q&A
3   © 2007-2012 Creative Arts & Technologies
Was bin Ich?
Werner Keil




                 • Consultant – Coach
                 • Creative Cosmopolitan
                 • Open Source Evangelist
                 • Software Architect
                 • Java Godfather
                 • UOMo Lead
                 • …
                     Twitter @wernerkeil

4   © 2007-2012 Creative Arts & Technologies
Was ist eine DSL?
• Eine DSL ist eine Computersprache (Spezification,
  Modellierung, Programmierung,…) angepasst an
  eine bestimmte Domäne. Doch was ist eine
  Domäne? (siehe nächste Seite;-)
• DSL Beispiele: SQL, CSS, Sawzall (Google)
• Gewinn von Aussagekraft und
  Benutzerfreundlichkeit (kann u.U. Bis zur
  Entwicklung durch Endbenutzer führen)
• Gewinn von Produktivität
• Geringerer Wartungsaufwand und -kosten
5   © 2007-2012 Creative Arts & Technologies
Was ist eine Domäne?
                             Real-Time                      Business
                               Systems                      Systems

                                                                            Requirements




                                                                             Specification


                             Aircraft            Patient       Insurance
                             control           Management    Management    Implementation
                           systems              Systems        Systems


                                                                             Deployment



6   © 2007-2012 Creative Arts & Technologies
Internal Domain Specific Languages
• Sprachen mit Hilfe syntaktischer Elemente der
  darunter liegenden Sprache/Umgebung
• Im Fall von Java, eine DSL verwendet Java
  Klassen und Methoden
• Bei anderen JVM-basierenden Sprachen ist es in
  der Regel ähnlich, meist wird Java Code oder
  Klassen generiert



7   © 2007-2012 Creative Arts & Technologies
External Domain Specific Languages
• Externe DSLs
       • Geschriebern in einer eigenen Sprache als der darunterliegenden (Host)
         Sprache der Anwendung
       • Umgewandelt mit Hilfe eines Compilers, Parsers oder Interpreters

• Kann auch enthalten
       • XML Konfigurationsdateien
       • Textdateien zur Konfiguration
       • Eigene Sprachen (Meta-DSLs)




8   © 2007-2012 Creative Arts & Technologies
Typ-Sicherheit
• Java hat keine stark typisierten Primitiven
  Datentypen (wie etwa Ada).
• Zwecks Performance nutzen die meisten
  Entwickler Primitive Datentypen an Stelle der
  entsprechenden Objekt-Typen.
• Primitive Datentypen in Argumenten führen oft zu
  Namensverwirrung (Methoden mit ident wirkender
  Signatur)


9   © 2007-2012 Creative Arts & Technologies
Was haben diese Vorfälle gemeinsam?
• Patriot Missile
  Ungenaue Berechnung der Zeit, die seit dem Start
  verging verursachte den Absturz.
• Ariane 5 Explosion
  Floating point Zahl die in einen Wert umgewandelt
  wurde, der den verfügbaren 16 bit signed integer
  überstieg.



10   © 2007-2012 Creative Arts & Technologies
Was haben diese Vorfälle gemeinsam?
• Gimli Glider (Beinahe Disaster)
     Treibstoffmenge falsch berechnet wegen Fehlinterpretation des gerade
     eingeführten Metrischen Systems in Kanada, statt des Britischen Imperial
     System of Units
• Mars Orbiter
     Vorläufige Erkenntnisse deuten darauf hin, dass ein Team Englische
     Einheiten (e.g. inches, feet and pounds) benutzte, während andere Teams
     Metrische Einheiten zur Steuerung der Raumsonde nutzten.
        • NASA lost a $125 million Mars orbiter because a Lockheed Martin engineering team used English
          units of measurement while the agency's team used the more conventional metric system for a key
          spacecraft operation
                  • A credible source disclosed, there was a manual step with an outsourced person to convert these
                    calculations between the different teams, and NASA budget cuts caused them to fire him and have the
                    wrong, unpatched data transmitted!!!
        • This also underlines the added risk when 3rd party contractors are involved or projects are developed
          Offshore




11    © 2007-2012 Creative Arts & Technologies
Unit Tests helfen hier selten…
  Dem Namen zum Trotz
• Alle Beispiele illustrieren 3 Kategorien von Fehlern,
  die man mit Unit Tests nur schwer aufspüren kann:
       • Schnittstellen-Fehler (z.B. millisecond/second, radian/degree, meters/feet).
       • Arithmetische Fehler (z.B. overflow).
       • Konvertierungsfehler.




17   © 2007-2012 Creative Arts & Technologies
SQL Beispiel mit Fehlern
     StringBuilder sql = new StringBuilder();
     sql.append("SELECT o.sum,(SELECT first_name,last_name");
     sql.append("                                       FROM person p");
     sql.append("                                      WHERE o.person_id=p.id) AS
     client");
     sql.append(" FROM order o");
     sql.append("WHERE o.id = "+orderId);
     sql.append("                               AND o.status_code IN (?,?)");
     PreparedStatement stmt =
     conn.prepareStatement(sql.toString());
     stmt.setString(1, "PAID");


     //...

19   © 2007-2012 Creative Arts & Technologies
Typ-sicheres SQL Beispiel
     Person p = new Person();
     List<Tuple<String, Integer, Date>> rows =
           new QueryBuilder(datasource)
                 .from(p)
                 .where(gt(p.height, 170))
                 .select(p.name, p.height, p.birthday)
                 .list();
     for (Tuple<String, Integer, Date> row : rows) {
           String name = row.v1;
           Integer height = row.v2;
           Date birthday = row.v3;
           System.out.println(
           name + " " + height + " " + birthday);
     }
20   © 2007-2012 Creative Arts & Technologies
Unit-API | Operationen


   Ergebnis mit
   Gleicher Dimension            Anderer Dimension

   Binäre Operationen            Binäre Operationen

   add(double) od. (long)        root(int)

   multiply(double) od. (long)   power(int)

   divide(double) od. (long)     multiply(Unit)

   compound(Unit)                divide(Unit)

   Unäre Operationen

   inverse()
UOMo UCUM

          Unified Code for Units of Measure
          Unified Code for Units of Measure ist inspiriert und stark
           beeinflusst von
          • ISO 2955-1983
          • ANSI X3.50-1986
          • HL7's Erweiterungen namens ISO+



25   © 2007-2012 Creative Arts & Technologies
HL7 DSL
     def mySegment = ...                                    // assignment to another
     NK1 segment instance
     def group = message.PATIENT_RESULT(0).PATIENT
     group.NK1(0) = 'abc'                                   // syntax error!
     msg1.NK1(0) = mySegment                                // syntax error!
     msg1.NK1(0).from(mySegment)                            // works!

     def nk1                                = message.PATIENT_RESULT(0).PATIENT.NK1(0)
     def otherNk1 = message.PATIENT_RESULT(0).PATIENT.NK1(0)
     nk1[4]                                 = otherNk1[4]    // copy address
     nk1[4][4]                              = otherNk1[4][4] // copy state or province
     only
     nk1[4][4].from(otherNk1[4][4])// equivalent
     nk1[4][4]                              = 'NY'   // set state or province directly

26   © 2007-2012 Creative Arts & Technologies
Healthcare DSL mit Groovy




  DEMO
Jython
     /** * Java calculator class that contains two simple
     methods */
     public class Calculator {
                      public Calculator(){ }
                      public double calculateTip(double cost, double
                        tipPercentage) {
                                         return cost * tipPercentage;
                      }
                      public double calculateTax(double cost, double
                        taxPercentage) {
                                         return cost * taxPercentage;
                      }
     }


28   © 2007-2012 Creative Arts & Technologies
Jython (2)
     import Calculator
     from java.lang import Math
     class JythonCalc(Calculator):
     def __init__(self):
                      pass
     def calculateTotal(self, cost, tip, tax):
                      return cost + self.calculateTip(tip) + self.calculateTax(tax)
     if __name__ == "__main__":
                      calc = JythonCalc()
                      cost = 23.75
                      tip = .15
                      tax = .07
     print "Starting Cost: ", cost
     print "Tip Percentage: ", tip
     print "Tax Percentage: ", tax
     print Math.round(calc.calculateTotal(cost, tip, tax))


29   © 2007-2012 Creative Arts & Technologies
Jython (3)

          Result
     Starting Cost: 23.75
     Tip Percentage: 0.15
     Tax Percentage: 0.07
     29




30   © 2007-2012 Creative Arts & Technologies
Xtext Examples




  DEMO
Scala, Fantom, F#
• Scala
       • Functional programming language. Type-safe, as the company driving it was
         called.
       • Very popular for DSLs

• Fantom
       • Functional programming language
       • Units of Measurement support built in.
       • Runs on both JVM and CLR

• F#
       • Functional programming language
       • Units of Measurement support built in.

33   © 2007-2012 Creative Arts & Technologies
Scala und Fantom Beispiele




  DEMO
Links

   Eclipse – Project UOMo
   http://www.eclipse.org/uomo/


   Units of Measurement API
   http://www.unitsofmeasurement.org


   UCUM
   http://www.unitsofmeasure.org
Links (2)

   OpenHealth Project
   http://www.openhealth.org

   Groovy DSL Example
   http://groovy.dzone.com/news/domain-
   specific-language-unit-

   Jython
   http://www.jython.org
Links (3)

   Xtext
   http://www.eclipse.org/xtext


   Scala DSLs
   http://www.scala-lang.org/node/1403


   Fantom
   http://fantom.org/
Fragen

Q&A
Kontakt

          werner@catmedia.us
                 oder
          uomo@catmedia.us


          Twitter: @wernerkeil
          Hashtag #EclipseUOMo

Más contenido relacionado

Similar a Typ-sichere DSLs

Entity Framework hinter den Kulissen
Entity Framework hinter den KulissenEntity Framework hinter den Kulissen
Entity Framework hinter den KulissenAndré Krämer
 
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher Software
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher SoftwareEinsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher Software
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher SoftwareAndreas Schreiber
 
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET Куранкова Татьяна
 
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best PracticesGFU Cyrus AG
 
Entity Framework Core - Der Umstieg auf Core
Entity Framework Core - Der Umstieg auf CoreEntity Framework Core - Der Umstieg auf Core
Entity Framework Core - Der Umstieg auf CoreNETUserGroupBern
 
Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Josef Adersberger
 
Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?QAware GmbH
 
Oracle Text 12c New Features
Oracle Text 12c New FeaturesOracle Text 12c New Features
Oracle Text 12c New FeaturesUlrike Schwinn
 
Technologieraum übergreifende Programmierung
Technologieraum übergreifende ProgrammierungTechnologieraum übergreifende Programmierung
Technologieraum übergreifende ProgrammierungFalk Hartmann
 
Java und Python - Das Beste aus beiden Welten nutzen
Java und Python - Das Beste aus beiden Welten nutzenJava und Python - Das Beste aus beiden Welten nutzen
Java und Python - Das Beste aus beiden Welten nutzenAndreas Schreiber
 
Python, Plone und Zope in der Luft- und Raumfahrtforschung
Python, Plone und Zope in der Luft- und RaumfahrtforschungPython, Plone und Zope in der Luft- und Raumfahrtforschung
Python, Plone und Zope in der Luft- und RaumfahrtforschungAndreas Schreiber
 
Event Driven Architecture - OPITZ CONSULTING - Schmutz - Winterberg
Event Driven Architecture - OPITZ CONSULTING - Schmutz - WinterbergEvent Driven Architecture - OPITZ CONSULTING - Schmutz - Winterberg
Event Driven Architecture - OPITZ CONSULTING - Schmutz - WinterbergOPITZ CONSULTING Deutschland
 
LAIK: A Library for Fault Tolerant Distribution of Global Data
LAIK: A Library for Fault Tolerant Distribution of Global DataLAIK: A Library for Fault Tolerant Distribution of Global Data
LAIK: A Library for Fault Tolerant Distribution of Global DataDai Yang
 
Große Applikationen mit AngularJS
Große Applikationen mit AngularJSGroße Applikationen mit AngularJS
Große Applikationen mit AngularJSSebastian Springer
 
Lightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPALightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPAmh0708
 
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014Werner Keil
 

Similar a Typ-sichere DSLs (20)

Entity Framework hinter den Kulissen
Entity Framework hinter den KulissenEntity Framework hinter den Kulissen
Entity Framework hinter den Kulissen
 
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher Software
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher SoftwareEinsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher Software
Einsatz von Subversion bei der Entwicklung technisch-wissenschaftlicher Software
 
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET
Modell der Zusammenarbeit. Migration von Progress 4GL nach C#.NET
 
.NET und jetzt!
.NET und jetzt!.NET und jetzt!
.NET und jetzt!
 
PLUX.NET – SOFTWAREKOMPOSITION DURCH PLUG & PLAY
PLUX.NET – SOFTWAREKOMPOSITION DURCH PLUG & PLAYPLUX.NET – SOFTWAREKOMPOSITION DURCH PLUG & PLAY
PLUX.NET – SOFTWAREKOMPOSITION DURCH PLUG & PLAY
 
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
 
Entity Framework Core - Der Umstieg auf Core
Entity Framework Core - Der Umstieg auf CoreEntity Framework Core - Der Umstieg auf Core
Entity Framework Core - Der Umstieg auf Core
 
Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?
 
Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?
 
Java User Group Düsseldorf - Vortrag der iks am 13. März 2008
Java User Group Düsseldorf - Vortrag der iks am 13. März 2008Java User Group Düsseldorf - Vortrag der iks am 13. März 2008
Java User Group Düsseldorf - Vortrag der iks am 13. März 2008
 
Oracle Text 12c New Features
Oracle Text 12c New FeaturesOracle Text 12c New Features
Oracle Text 12c New Features
 
profil_2017
profil_2017profil_2017
profil_2017
 
Technologieraum übergreifende Programmierung
Technologieraum übergreifende ProgrammierungTechnologieraum übergreifende Programmierung
Technologieraum übergreifende Programmierung
 
Java und Python - Das Beste aus beiden Welten nutzen
Java und Python - Das Beste aus beiden Welten nutzenJava und Python - Das Beste aus beiden Welten nutzen
Java und Python - Das Beste aus beiden Welten nutzen
 
Python, Plone und Zope in der Luft- und Raumfahrtforschung
Python, Plone und Zope in der Luft- und RaumfahrtforschungPython, Plone und Zope in der Luft- und Raumfahrtforschung
Python, Plone und Zope in der Luft- und Raumfahrtforschung
 
Event Driven Architecture - OPITZ CONSULTING - Schmutz - Winterberg
Event Driven Architecture - OPITZ CONSULTING - Schmutz - WinterbergEvent Driven Architecture - OPITZ CONSULTING - Schmutz - Winterberg
Event Driven Architecture - OPITZ CONSULTING - Schmutz - Winterberg
 
LAIK: A Library for Fault Tolerant Distribution of Global Data
LAIK: A Library for Fault Tolerant Distribution of Global DataLAIK: A Library for Fault Tolerant Distribution of Global Data
LAIK: A Library for Fault Tolerant Distribution of Global Data
 
Große Applikationen mit AngularJS
Große Applikationen mit AngularJSGroße Applikationen mit AngularJS
Große Applikationen mit AngularJS
 
Lightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPALightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPA
 
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014
Bitte ein Maß - JSR-363 - Units of Measurement API - IoTDay 2014
 

Más de Werner Keil

Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21Werner Keil
 
OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021Werner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021Werner Keil
 
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 VirtualOpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 VirtualWerner Keil
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualWerner Keil
 
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDRJCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDRWerner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020Werner Keil
 
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)Werner Keil
 
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Werner Keil
 
NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)Werner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR DayHow JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR DayWerner Keil
 
JNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL DatabasesJNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL DatabasesWerner Keil
 
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL DatabasesEclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL DatabasesWerner Keil
 
Physikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG MunichPhysikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG MunichWerner Keil
 
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017Werner Keil
 
Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017Werner Keil
 
Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363Werner Keil
 
Java2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the CloudJava2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the CloudWerner Keil
 
Apache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ StuttgartApache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ StuttgartWerner Keil
 
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-BrandenburgThe First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-BrandenburgWerner Keil
 

Más de Werner Keil (20)

Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21
 
OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021
 
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
 
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 VirtualOpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDRJCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
 
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
 
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
 
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
 
NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)
 
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR DayHow JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
 
JNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL DatabasesJNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL Databases
 
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL DatabasesEclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
 
Physikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG MunichPhysikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG Munich
 
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
 
Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017
 
Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363
 
Java2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the CloudJava2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the Cloud
 
Apache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ StuttgartApache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ Stuttgart
 
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-BrandenburgThe First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
 

Typ-sichere DSLs

  • 1. Typ-sichere DSLs Mit Xtext/TS, Xtend, Groovy und anderen Sprachen Werner Keil Eclipse DemoCamp Berlin 20. Juni 2012
  • 2. Zielsetzung ARITHMETISCHE ODER DATENTYP FEHLER BEI DSL NUTZUNG VERMEIDEN 2 © 2007-2012 Creative Arts & Technologies
  • 3. Überblick • Einleitung • Was ist eine DSL? • Interne und Externe DSLs • Type-Sicherheit • Einheiten im Gesundheitswesen • Unit-API, UOMo • UCUM, HL7, Groovy in der Gesundheitsbranche • Andere Sprachen • Jython/WLST • Xtext/Xbase/Xtend • Scala, Fantom, F# • Demo • Q&A 3 © 2007-2012 Creative Arts & Technologies
  • 4. Was bin Ich? Werner Keil • Consultant – Coach • Creative Cosmopolitan • Open Source Evangelist • Software Architect • Java Godfather • UOMo Lead • … Twitter @wernerkeil 4 © 2007-2012 Creative Arts & Technologies
  • 5. Was ist eine DSL? • Eine DSL ist eine Computersprache (Spezification, Modellierung, Programmierung,…) angepasst an eine bestimmte Domäne. Doch was ist eine Domäne? (siehe nächste Seite;-) • DSL Beispiele: SQL, CSS, Sawzall (Google) • Gewinn von Aussagekraft und Benutzerfreundlichkeit (kann u.U. Bis zur Entwicklung durch Endbenutzer führen) • Gewinn von Produktivität • Geringerer Wartungsaufwand und -kosten 5 © 2007-2012 Creative Arts & Technologies
  • 6. Was ist eine Domäne? Real-Time Business Systems Systems Requirements Specification Aircraft Patient Insurance control Management Management Implementation systems Systems Systems Deployment 6 © 2007-2012 Creative Arts & Technologies
  • 7. Internal Domain Specific Languages • Sprachen mit Hilfe syntaktischer Elemente der darunter liegenden Sprache/Umgebung • Im Fall von Java, eine DSL verwendet Java Klassen und Methoden • Bei anderen JVM-basierenden Sprachen ist es in der Regel ähnlich, meist wird Java Code oder Klassen generiert 7 © 2007-2012 Creative Arts & Technologies
  • 8. External Domain Specific Languages • Externe DSLs • Geschriebern in einer eigenen Sprache als der darunterliegenden (Host) Sprache der Anwendung • Umgewandelt mit Hilfe eines Compilers, Parsers oder Interpreters • Kann auch enthalten • XML Konfigurationsdateien • Textdateien zur Konfiguration • Eigene Sprachen (Meta-DSLs) 8 © 2007-2012 Creative Arts & Technologies
  • 9. Typ-Sicherheit • Java hat keine stark typisierten Primitiven Datentypen (wie etwa Ada). • Zwecks Performance nutzen die meisten Entwickler Primitive Datentypen an Stelle der entsprechenden Objekt-Typen. • Primitive Datentypen in Argumenten führen oft zu Namensverwirrung (Methoden mit ident wirkender Signatur) 9 © 2007-2012 Creative Arts & Technologies
  • 10. Was haben diese Vorfälle gemeinsam? • Patriot Missile Ungenaue Berechnung der Zeit, die seit dem Start verging verursachte den Absturz. • Ariane 5 Explosion Floating point Zahl die in einen Wert umgewandelt wurde, der den verfügbaren 16 bit signed integer überstieg. 10 © 2007-2012 Creative Arts & Technologies
  • 11. Was haben diese Vorfälle gemeinsam? • Gimli Glider (Beinahe Disaster) Treibstoffmenge falsch berechnet wegen Fehlinterpretation des gerade eingeführten Metrischen Systems in Kanada, statt des Britischen Imperial System of Units • Mars Orbiter Vorläufige Erkenntnisse deuten darauf hin, dass ein Team Englische Einheiten (e.g. inches, feet and pounds) benutzte, während andere Teams Metrische Einheiten zur Steuerung der Raumsonde nutzten. • NASA lost a $125 million Mars orbiter because a Lockheed Martin engineering team used English units of measurement while the agency's team used the more conventional metric system for a key spacecraft operation • A credible source disclosed, there was a manual step with an outsourced person to convert these calculations between the different teams, and NASA budget cuts caused them to fire him and have the wrong, unpatched data transmitted!!! • This also underlines the added risk when 3rd party contractors are involved or projects are developed Offshore 11 © 2007-2012 Creative Arts & Technologies
  • 12. Unit Tests helfen hier selten… Dem Namen zum Trotz • Alle Beispiele illustrieren 3 Kategorien von Fehlern, die man mit Unit Tests nur schwer aufspüren kann: • Schnittstellen-Fehler (z.B. millisecond/second, radian/degree, meters/feet). • Arithmetische Fehler (z.B. overflow). • Konvertierungsfehler. 17 © 2007-2012 Creative Arts & Technologies
  • 13. SQL Beispiel mit Fehlern StringBuilder sql = new StringBuilder(); sql.append("SELECT o.sum,(SELECT first_name,last_name"); sql.append(" FROM person p"); sql.append(" WHERE o.person_id=p.id) AS client"); sql.append(" FROM order o"); sql.append("WHERE o.id = "+orderId); sql.append(" AND o.status_code IN (?,?)"); PreparedStatement stmt = conn.prepareStatement(sql.toString()); stmt.setString(1, "PAID"); //... 19 © 2007-2012 Creative Arts & Technologies
  • 14. Typ-sicheres SQL Beispiel Person p = new Person(); List<Tuple<String, Integer, Date>> rows = new QueryBuilder(datasource) .from(p) .where(gt(p.height, 170)) .select(p.name, p.height, p.birthday) .list(); for (Tuple<String, Integer, Date> row : rows) { String name = row.v1; Integer height = row.v2; Date birthday = row.v3; System.out.println( name + " " + height + " " + birthday); } 20 © 2007-2012 Creative Arts & Technologies
  • 15. Unit-API | Operationen Ergebnis mit Gleicher Dimension Anderer Dimension Binäre Operationen Binäre Operationen add(double) od. (long) root(int) multiply(double) od. (long) power(int) divide(double) od. (long) multiply(Unit) compound(Unit) divide(Unit) Unäre Operationen inverse()
  • 16. UOMo UCUM Unified Code for Units of Measure Unified Code for Units of Measure ist inspiriert und stark beeinflusst von • ISO 2955-1983 • ANSI X3.50-1986 • HL7's Erweiterungen namens ISO+ 25 © 2007-2012 Creative Arts & Technologies
  • 17. HL7 DSL def mySegment = ... // assignment to another NK1 segment instance def group = message.PATIENT_RESULT(0).PATIENT group.NK1(0) = 'abc' // syntax error! msg1.NK1(0) = mySegment // syntax error! msg1.NK1(0).from(mySegment) // works! def nk1 = message.PATIENT_RESULT(0).PATIENT.NK1(0) def otherNk1 = message.PATIENT_RESULT(0).PATIENT.NK1(0) nk1[4] = otherNk1[4] // copy address nk1[4][4] = otherNk1[4][4] // copy state or province only nk1[4][4].from(otherNk1[4][4])// equivalent nk1[4][4] = 'NY' // set state or province directly 26 © 2007-2012 Creative Arts & Technologies
  • 18. Healthcare DSL mit Groovy DEMO
  • 19. Jython /** * Java calculator class that contains two simple methods */ public class Calculator { public Calculator(){ } public double calculateTip(double cost, double tipPercentage) { return cost * tipPercentage; } public double calculateTax(double cost, double taxPercentage) { return cost * taxPercentage; } } 28 © 2007-2012 Creative Arts & Technologies
  • 20. Jython (2) import Calculator from java.lang import Math class JythonCalc(Calculator): def __init__(self): pass def calculateTotal(self, cost, tip, tax): return cost + self.calculateTip(tip) + self.calculateTax(tax) if __name__ == "__main__": calc = JythonCalc() cost = 23.75 tip = .15 tax = .07 print "Starting Cost: ", cost print "Tip Percentage: ", tip print "Tax Percentage: ", tax print Math.round(calc.calculateTotal(cost, tip, tax)) 29 © 2007-2012 Creative Arts & Technologies
  • 21. Jython (3) Result Starting Cost: 23.75 Tip Percentage: 0.15 Tax Percentage: 0.07 29 30 © 2007-2012 Creative Arts & Technologies
  • 23. Scala, Fantom, F# • Scala • Functional programming language. Type-safe, as the company driving it was called. • Very popular for DSLs • Fantom • Functional programming language • Units of Measurement support built in. • Runs on both JVM and CLR • F# • Functional programming language • Units of Measurement support built in. 33 © 2007-2012 Creative Arts & Technologies
  • 24. Scala und Fantom Beispiele DEMO
  • 25. Links Eclipse – Project UOMo http://www.eclipse.org/uomo/ Units of Measurement API http://www.unitsofmeasurement.org UCUM http://www.unitsofmeasure.org
  • 26. Links (2) OpenHealth Project http://www.openhealth.org Groovy DSL Example http://groovy.dzone.com/news/domain- specific-language-unit- Jython http://www.jython.org
  • 27. Links (3) Xtext http://www.eclipse.org/xtext Scala DSLs http://www.scala-lang.org/node/1403 Fantom http://fantom.org/
  • 29. Kontakt werner@catmedia.us oder uomo@catmedia.us Twitter: @wernerkeil Hashtag #EclipseUOMo