SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
Dealing comfortably with
the confusion of tongues
Ralf Lämmel
Software Languages Team, Koblenz
http://en.wikipedia.org/wiki/Tower_of_Babel_(M._C._Escher)
Consider the following
system. How to reasonably
summarize its architecture?
RL: c9 is MSFT’s
community-oriented
youtube.
Technology used in the
5th edition of Channel9
ASP.NET MVC
SparkView engine
jQuery
Silverlight 4
Windows Azure, SQL Azure, “other Azures”
ECN for the Content Delivery Network (videos)
http://channel9.msdn.com/Blogs/C9Team/Welcome-to-the-all-new-Channel-9
Abeginner’sviewon...
Channel9
http://www.epochtimes.de/pics/2009/07/20/xxl/2009-07-20-xxl--NASA_ueber_AP_Mond_Erde_1969_000_SAWH990715682240_new.jpg
Abstraction! Abstraction! Abstraction!
• What domain?
• Programming
• X/O/R mapping
• XML/database processing
• GUI
• ...
• What engineering?
• megamodeling programming
• software language engineering
CH
O
O
SE
Forum
2012
D
om
ain-specific
Engineering
A simpler riddle: how to usefully
characterize these XML technologies?
DOM
SAX
StAX
DOM [Wikipedia]
The Document Object Model (DOM) is a cross-platform
and language-independent convention for
representing and interacting with objects in HTML,
XHTML and XML documents. Aspects of the DOM
(such as its "Elements") may be addressed and
manipulated within the syntax of the programming
language in use. The public interface of a DOM is
specified in its Application Programming Interface
(API). ...
SAX [Wikipedia]
SAX (Simple API for XML) is a sequential access
parser API for XML. SAX provides a mechanism for
reading data from an XML document. It is a popular
alternative to the Document Object Model (DOM). ... A
parser which implements SAX (ie, a SAX Parser)
functions as a stream parser, with an event-driven API.
The user defines a number of callback methods that
will be called when events occur during parsing. ...
StAX [Wikipedia]
Streaming API for XML (StAX) is an application
programming interface (API) to read and write XML
documents, originating from the Java programming
language community. Traditionally, XML APIs are
either: tree based, ..., event based. ... These two access
metaphors can be thought of as polar opposites. ...
StAX was designed as a median between these two
opposites. ...
DOM SAX StAX
Read (parse, query) XML • • •
Write XML • •
Metadata! Metadata! Metadata!
DOM SAX StAX
In-memory XML processing •
Push-based XML parsing •
Pull-based XML parsing •
Metadata! Metadata! Metadata!
DOM SAX StAX
Standardization • ·
.NET counterpart • •
Metadata! Metadata! Metadata!
Follow-up questions?
How to usefully abstract from XML in
defining “push-based”?
How to usefully share conceptual
understanding across DOM and JAXB?
... between JAXB and Hibernate?
...
An advanced programming class
The Expression Problem
The Visitor Design Pattern
Parsing
XML Processing
XML Validation
XML Data Binding
Database Access
O/R Mapping
Model View Controller
More Design Patterns
Reflection
Aspect-Oriented Programming
Functional OO Programming
Combinator Libraries
Generic Programming
Programming with Threads
Distributed Programming
WebService Programming
Our ultimate goal:
heavily annotate programmig
and language technologies and
their uses with metadata
facilitating understanding.
A running example:
101companies
http://sourceforge.net/apps/mediawiki/developers/index.php?title=101companies
101companies
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
...
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
...
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
A few variation points
X vs. O vs. R vs. λ etc.
Static typing vs. dynamic typing
Textual vs. abstract vs. visual syntax
GPPL vs. DSL vs. embedding vs. API
Instance- vs. operation-based mapping
Type checking vs. inference vs. reasoning
Code first vs. schema first vs. mapping only
In-memory processing vs. push vs. pull parsing
Pure vs. impure transformations (or in between)
Code vs. generative vs. model-driven vs. mapping
101 ways
to run a company.
101companies
Modeling companies
Model ANTLR
company : 'company' STRING '{' dept* '}';
dept :
'department' STRING '{'
('manager' employee)
('employee' employee)*
dept* '}';
employee :
STRING '{'
'address' STRING
'salary' FLOAT '}';
WS : (' '|'r'? 'n'|'t')+ {skip();};
STRING : '"' (~'"')* '"';
FLOAT : ('0'..'9')+ ('.' ('0'..'9')+)?;
CFGs for HR notation.
The aspect of “sharing
knowledge” is
underestimated.
Purity of CFGs
is an i!usion.
Model Haske!
type Company = [Dept]
data Dept = Dept Name Manager [SubUnit]
type Manager = Employee
data Employee = Employee Name Address Salary
data SubUnit = PU Employee | DU Dept
type Name = String
type Address = String
type Salary = Float
Structure is defined by
sequence, cases, and
recursion.
Algebraic datatypes
imply tree shape of
data instances.
Models use nominal
& structural types,
and aliases.
Model Ecore
There are recurring
themes for
primitive types.
Lists or co!ections
may in fact be
distinguished
structural forms.
Model Ecore/Java/EMF
/**
* @model
*/
public interface Person extends EObject {
	 /**
	 * @model required="true" ordered="false"
	 */
	 String getName();
	 void setName(String value);
	 /**
	 * @model required="true" ordered="false"
	 */
	 String getAddress();
	 void setAddress(String value);
}
Programs
are
models.
Models
are
programs.
<xs:element name="company"> ... </xs:element>
	 <xs:complexType name="dept">
	 	 <xs:sequence>
	 	 	 <xs:element name="name" type="xs:string"/>
	 	 	 <xs:element name="manager" type="employee"/>
	 	 	 <xs:element maxOccurs="unbounded" minOccurs="0" ref="subunit"/>
	 	 </xs:sequence>
	 </xs:complexType>
	 <xs:element name="subunit">
	 	 <xs:complexType>
	 	 	 <xs:choice>
	 	 	 	 <xs:element name="pu" type="employee"/>
	 	 	 	 <xs:element name="du" type="dept"/>
	 	 	 </xs:choice>
	 	 </xs:complexType>
	 </xs:element>
	 <xs:complexType name="employee">
	 	 <xs:sequence>
	 	 	 <xs:element ref="person"/>
	 	 	 <xs:element ref="salary"/>
	 	 </xs:sequence>
	 </xs:complexType>
	 <xs:element name="person"> ... </xs:element>
	 <xs:element name="salary"> ... </xs:element>
Model XSD
Let’s hope XSD goes
away faster than
Cobol.
CREATE TABLE dept (
	 deptId INTEGER AUTO_INCREMENT PRIMARY KEY,
	 name VARCHAR(100),
	 managerId INTEGER,
	 FOREIGN KEY (managerId) REFERENCES employee(employeeID),
	 upperDeptId INTEGER,
	 FOREIGN KEY (upperDeptId) REFERENCES dept(deptId)
	 	 ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE employee (
employeeId INTEGER AUTO_INCREMENT PRIMARY KEY,
	 name VARCHAR(50) NOT NULL,
	 address VARCHAR(50) NOT NULL,
	 salary DOUBLE,
	 deptId INTEGER,
	 FOREIGN KEY (deptId) REFERENCES dept(deptId)
	 	 ON DELETE CASCADE ON UPDATE CASCADE
);
Model SQL DDL
Type references may
be represented
through key
references.
Eventua!y
behavioral aspects
join in.
101companies
Totaling salaries
Total EMF/Java
public class Total {
	 public static double total(Company company) {
	 	 double total = 0;
	 	 for (Dept dept : company.getDepts())
	 	 	 total += total(dept);
	 	 return total;
	 }
	 private static double total(Dept dept) { ... }
	 private static double total(Subunit subunit) { ... }
	 private static double total(Employee employee) { ... }
}
Queries over
(systems of)
recursive datatypes
may require
(systems of)
recursive “functions”.
Total Haske!
total :: Company -> Float
total = everything (+) (mkQ 0 id)
Traversal or genera!y:
quantification
Type case
Total XML/XQuery
<result>
	{sum(//salary)}
</result>
A domain-specific language for
queries is good at doing, we!, queries.
Total XML/DOM/XPath
public static double total(Document doc)
	 	 throws Exception {
	 double total = 0;
NodeList nodelist =
	 	 	 XPathAPI.selectNodeList(doc, "//salary");	
	 for (int i=0; i<nodelist.getLength(); i++) {
Element elem = (Element)nodelist.item(i);
total += Double.parseDouble(elem.getTextContent());
}
	 return total;
} Host language may run embedded programs
and inspect results.
Total XML/Java/JAXB
public class Total {
	 public static double total(Company c) {
	 	 double total = 0;
	 	 if (c.getDept() != null)
	 	 	 for (Dept d : c.getDept())
	 	 	 	 total += total(d);
	 	 return total;
	 }	
	 public static double total(Dept d) { ... }	
	 public static double total(Employee e) { ... }	
	 public static double total(Subunit s) { ... }
}
POJOs
Time and again.
Total SQL DML
SELECT SUM(salary)
FROM employee;
What’s the XML/OO
counterpart to
projection?
Query languages
provide aggregators.
Total Java / JDBC
public static double total(MyConnection myConnection)
	 	 throws SQLException {
	 double total = 0;
	 String query =
	 	 "SELECT salary FROM employee";
	 PreparedStatement pstmtEmployees =
	 	 myConnection
	 	 	 .getConn()
	 	 	 .prepareStatement(query);
	 ResultSet salaries = pstmtEmployees.executeQuery();
	 while (salaries.next())
	 	 total += salaries.getDouble("salary");
	 return total;
}
Iterators on lazy
server results
Total RDF/Java/Jena
public static double total(CompanyModel c) {
	 double total = 0;
	 StmtIterator i =
	 	 c.getModel().listStatements(
	 	 	 new SimpleSelector(
	 	 	 	 null, c.SALARY, (RDFNode) null));
	 while (i.hasNext()) {
	 	 Statement s = i.next();
	 	 total += s.getDouble();
	 }
	 return total;
}
Selection
(quantification) over
graphs requires
identities.
Ecore/ATL
module Total;
create OUT: Total from IN: Company;
rule Company2Total {
	 from
	 company : Company!Company
	 to
	 t : Total!TotalWrapper (
	 	 total <- Company!Employee.allInstances()
	 	 	 	 -> collect(e | e.salary)
	 	 	 	 -> sum()	 	 	
	 )
}
Total
Quantification,
Projection,
A'regation
101companies
Cutting salaries
Cut Haske!
cut :: Company -> Company
cut = everywhere (mkT (/(2::Float)))
The type of a pure function reveals
its nature of being a transformation.
Cut EMF/Java
public class Cut {
	 public static void cutCompany(Company company) {
	 	 for (Dept dept : company.getDepts())
	 	 	 cut(dept);
	 }
	 private static void cut(Dept dept) { ... }
	 private static void cut(Subunit subunit) { ... }
	 private static void cut(Employee employee) {
	 	 employee.setSalary(employee.getSalary() / 2);
	 }
}
The appearance of “void” in an
imperative (OO) language su'ests
impure transformation.
Cut XML/XQuery
copy $copy := .
modify
	 for $salary in $copy//salary
	 return
replace value of node $salary
with $salary div 2
return $copy
The distinction of pure vs.
impure is not always easy.
Cut XML/XSLT
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:com="http://www.softlang.org/company.xsd"
version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="com:salary">
<xsl:copy>
<xsl:value-of select=". div 2"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Don’t confuse notation with
concepts. Conceptua!y, XSLT is
potentia!y simple.
Cut SQL DML
UPDATE employee
SET
salary = salary / 2;
Type-based quantification is
rea!y simple with RDBMS.
Cut RDF/Java/Jena
public static void cut(CompanyModel c) {
	 List<Statement> l =
	 	 c.getModel().listStatements(
	 	 	 new SimpleSelector(
	 	 	 	 null, c.SALARY, (RDFNode) null)).toList();
	 for (Statement s : l)
	 	 s.changeLiteralObject(s.getDouble() / 2);
}
laziness + mutation = evil
Cut Ecore/ATL
module Cut;
create OUT: Company from IN: Company;
rule Company2Company {
	 from s : Company!Company
	 to t : Company!Company ( depts <- s.depts )
}
rule Employee2Employee {
	 from s : Company!Employee
	 to t : Company!Employee (
	 person <- s.person,
	 salary <- s.salary / 2 )
}
rule Dept2Dept { ... }
rule Subunit2Subunit_Pu { ... }
rule Subunit2Subunit_Du { ... }
rule Person2Person { ... }
Rule-based
thinking as opposed
to )ee-wheeling
functions.
101companies
Mapping companies
Map Java/Serializable
import org.softlang.company.*;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
FileInputStream fis =
	 	 new FileInputStream("sampleCompany.ser");
ObjectInputStream in =
	 	 new ObjectInputStream(fis);
Object o =
	 	 in.readObject();
in.close();
Company c = (Company)o; Use a universal object
representation.
XML/Java/JAXBMap
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"name", "address"})
@XmlRootElement(name = "person")
public class Person {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String address;
public String getName() { return name; }
public void setName(String value) { name = value; }
public String getAddress() { return address; }
public void setAddress(String value) { address = value; }
}
Annotations capture mapping
including constraints.
XML/Java/JAXB
import org.softlang.company.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;
File input =
	 new File("sampleCompany.xml");
JAXBContext jaxbContext =
	 	 JAXBContext.newInstance("org.softlang.company");
Unmarshaller unMarshaller =
	 	 jaxbContext.createUnmarshaller();
Company c =
(Company) unMarshaller.unmarshal(input);
Map
There is a 1:1 mapping
between
names of program types &
serialization-level names.
Ecore/Java/EMFMap
<GenModel ...>
<genPackages prefix="Company" ...>
<genClasses ecoreClass="Company.ecore#//Company">
<genFeatures ... ecoreFeature="...//Company/depts"/>
</genClasses>
<genClasses ecoreClass="Company.ecore#//Dept">
<genFeatures ... ecoreFeature="...//Dept/name"/>
<genFeatures ... ecoreFeature="...//Dept/manager"/>
<genFeatures ... ecoreFeature="...//Dept/subunits"/>
</genClasses>
...
</genPackages>
</GenModel>
types-to-types &
properties-to-properties
mapping
modulo renaming and exclusion.
Relational/Java/HibernateMap
<hibernate-mapping>
<class name="org.softlang.om.Dept" table="DEPT">
<id name="id" column="DEPT_ID">
<generator class="native" />
</id>
<property name="name" />
<many-to-one
name="manager"
class="org.softlang.om.Employee"
column="MANAGER_ID" unique="true" />
<set
name="subunits"
table="DEPT_SUBUNIT"
inverse="true">
<key column="DEPT_ID" />
<many-to-many column="SUBUNIT_ID" class="org.softlang.om.Subunit" />
</set>
</class>
</hibernate-mapping>
Given: tables and classes.
Recover relationship as
mapping.
Relational/Java/Hibernate
import org.hibernate.Session;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Company c =
	 new Company();
c.session =
	 new Configuration().
	 	 configure().
	 	 buildSessionFactory().
	 	 getCurrentSession();	 	
c.session.beginTransaction();
List<?> depts =
	 c.session.createQuery(
	 	 "from Dept where UPPER_DEPT_ID is null").list();
	 for (Object o : depts)
	 	 c.getDepts().add((Dept) o);
Map
Persistence
incl. transactions
Relational/Java/HibernateMap
<hibernate-mapping>
<class name="org.softlang.om.Dept" table="DEPT">
<id name="id" column="DEPT_ID">
<generator class="native" />
</id>
<property name="name" />
<many-to-one
name="manager"
column="MANAGER_ID"
class="org.softlang.om.Employee" />
<set name="employees" cascade="all">
<key column="DEPT_ID" />
<one-to-many class="org.softlang.om.Employee" />
</set>
<set name="subDepartments" cascade="all">
<key column="UPPER_DEPT_ID" />
<one-to-many class="org.softlang.om.Dept" />
</set>
</class>
</hibernate-mapping>
Another schema
Another mapping
101companies
Interacting with
companies
GUI Java/Swing
A GUI essentia!y provides a concrete
syntax for the underlying language.
GUI Ajax/Java[Script] /GWT
Compared to a regular GUI, this
scheme involves distribution, and, in
fact, mapping.
public CompanyInfo getCompanyInfo(Company company) {
	 CompanyInfo companyInfo = new CompanyInfo();
	 for (Dept dept : company.getDepts())
	 	 companyInfo.getDeptsInfos().add(dept.getName());
	 return companyInfo;
}
public class CompanyInfo
implements Serializable {
	 private List<String> deptsInfos;
	 public CompanyInfo() {
	 	 deptsInfos =
	 	 	 new LinkedList<String>();
	 }
	 public List<String> getDeptsInfos() {
	 	 return deptsInfos;
	 }
}
public class Company {
	 private List<Dept> depts;
	 public Company() {
	 	 depts =
	 	 	 new LinkedList<Dept>();
	 }
	 public List<Dept> getDepts() {
	 	 return depts;
	 }
	 public Double total() { ... }
	 public void cut() { ... }
}
Ajax/Java[Script] /GWTMap
Instance-level
mapping
Our ultimate goal:
heavily annotate programmig
and language technologies and
their uses with metadata
facilitating understanding.
Thanks!
Questions or comments?

Contenu connexe

Tendances

DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#Rasan Samarasinghe
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmersAlexander Varwijk
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
Decaf language specification
Decaf language specificationDecaf language specification
Decaf language specificationSami Said
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIAjit Nayak
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NETRasan Samarasinghe
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editingDr. Jan Köhnlein
 
2011 10-24-initiatives-tracker-launch-v1.0
2011 10-24-initiatives-tracker-launch-v1.02011 10-24-initiatives-tracker-launch-v1.0
2011 10-24-initiatives-tracker-launch-v1.0tommyoneill
 
OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 

Tendances (19)

DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
Decaf language specification
Decaf language specificationDecaf language specification
Decaf language specification
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
 
LEARN C#
LEARN C#LEARN C#
LEARN C#
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NET
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
C#
C#C#
C#
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
2011 10-24-initiatives-tracker-launch-v1.0
2011 10-24-initiatives-tracker-launch-v1.02011 10-24-initiatives-tracker-launch-v1.0
2011 10-24-initiatives-tracker-launch-v1.0
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Oop l2
Oop l2Oop l2
Oop l2
 

En vedette

Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...CHOOSE
 
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...CHOOSE
 
Services and Models in a Large IT System
Services and Models in a Large IT SystemServices and Models in a Large IT System
Services and Models in a Large IT SystemCHOOSE
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkCHOOSE
 
Security patterns and model driven architecture
Security patterns and model driven architectureSecurity patterns and model driven architecture
Security patterns and model driven architecturebdemchak
 
CPI, Inflation for Belize, July 2014 (PowerPoint)
CPI, Inflation for Belize, July 2014 (PowerPoint)CPI, Inflation for Belize, July 2014 (PowerPoint)
CPI, Inflation for Belize, July 2014 (PowerPoint)Adele Ramos
 
Ralph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutRalph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutCHOOSE
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsCHOOSE
 
Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Sagar Sen
 
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...Alberto Lluch Lafuente
 
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesFilip Krikava
 
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software 201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software Javier Gonzalez-Sanchez
 

En vedette (12)

Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
 
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
 
Services and Models in a Large IT System
Services and Models in a Large IT SystemServices and Models in a Large IT System
Services and Models in a Large IT System
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
 
Security patterns and model driven architecture
Security patterns and model driven architectureSecurity patterns and model driven architecture
Security patterns and model driven architecture
 
CPI, Inflation for Belize, July 2014 (PowerPoint)
CPI, Inflation for Belize, July 2014 (PowerPoint)CPI, Inflation for Belize, July 2014 (PowerPoint)
CPI, Inflation for Belize, July 2014 (PowerPoint)
 
Ralph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutRalph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum Handout
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
 
Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction
 
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...
A White-box Perspective on Self-Adaptation and Self-Awareness (with a focus o...
 
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
 
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software 201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
 

Similaire à Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues

Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For XmlLars Trieloff
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Eclipse Modeling Framework
Eclipse Modeling FrameworkEclipse Modeling Framework
Eclipse Modeling FrameworkAjay K
 
EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework
EclipseCon 2008: Fundamentals of the Eclipse Modeling FrameworkEclipseCon 2008: Fundamentals of the Eclipse Modeling Framework
EclipseCon 2008: Fundamentals of the Eclipse Modeling FrameworkDave Steinberg
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And XmlDavid Truxall
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...Michael Rys
 
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkEclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkDave Steinberg
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQLjeykottalam
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLStephan H. Wissel
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
RESTful Services
RESTful ServicesRESTful Services
RESTful ServicesKurt Cagle
 
XRX Presentation to Minnesota OTUG
XRX Presentation to Minnesota OTUGXRX Presentation to Minnesota OTUG
XRX Presentation to Minnesota OTUGOptum
 

Similaire à Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues (20)

Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Eclipse Modeling Framework
Eclipse Modeling FrameworkEclipse Modeling Framework
Eclipse Modeling Framework
 
EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework
EclipseCon 2008: Fundamentals of the Eclipse Modeling FrameworkEclipseCon 2008: Fundamentals of the Eclipse Modeling Framework
EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...
 
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkEclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXL
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
 
XRX Presentation to Minnesota OTUG
XRX Presentation to Minnesota OTUGXRX Presentation to Minnesota OTUG
XRX Presentation to Minnesota OTUG
 

Plus de CHOOSE

Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisDissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisCHOOSE
 
Continuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsContinuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsCHOOSE
 
Ralph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumRalph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumCHOOSE
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14CHOOSE
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
2008 02 01 Zeller
2008 02 01 Zeller2008 02 01 Zeller
2008 02 01 ZellerCHOOSE
 

Plus de CHOOSE (6)

Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisDissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
 
Continuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsContinuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based Systems
 
Ralph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumRalph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of Scrum
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
2008 02 01 Zeller
2008 02 01 Zeller2008 02 01 Zeller
2008 02 01 Zeller
 

Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues

  • 1. Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team, Koblenz http://en.wikipedia.org/wiki/Tower_of_Babel_(M._C._Escher)
  • 2. Consider the following system. How to reasonably summarize its architecture?
  • 3. RL: c9 is MSFT’s community-oriented youtube.
  • 4. Technology used in the 5th edition of Channel9 ASP.NET MVC SparkView engine jQuery Silverlight 4 Windows Azure, SQL Azure, “other Azures” ECN for the Content Delivery Network (videos) http://channel9.msdn.com/Blogs/C9Team/Welcome-to-the-all-new-Channel-9
  • 7. • What domain? • Programming • X/O/R mapping • XML/database processing • GUI • ... • What engineering? • megamodeling programming • software language engineering CH O O SE Forum 2012 D om ain-specific Engineering
  • 8. A simpler riddle: how to usefully characterize these XML technologies? DOM SAX StAX
  • 9. DOM [Wikipedia] The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Aspects of the DOM (such as its "Elements") may be addressed and manipulated within the syntax of the programming language in use. The public interface of a DOM is specified in its Application Programming Interface (API). ...
  • 10. SAX [Wikipedia] SAX (Simple API for XML) is a sequential access parser API for XML. SAX provides a mechanism for reading data from an XML document. It is a popular alternative to the Document Object Model (DOM). ... A parser which implements SAX (ie, a SAX Parser) functions as a stream parser, with an event-driven API. The user defines a number of callback methods that will be called when events occur during parsing. ...
  • 11. StAX [Wikipedia] Streaming API for XML (StAX) is an application programming interface (API) to read and write XML documents, originating from the Java programming language community. Traditionally, XML APIs are either: tree based, ..., event based. ... These two access metaphors can be thought of as polar opposites. ... StAX was designed as a median between these two opposites. ...
  • 12. DOM SAX StAX Read (parse, query) XML • • • Write XML • • Metadata! Metadata! Metadata!
  • 13. DOM SAX StAX In-memory XML processing • Push-based XML parsing • Pull-based XML parsing • Metadata! Metadata! Metadata!
  • 14. DOM SAX StAX Standardization • · .NET counterpart • • Metadata! Metadata! Metadata!
  • 15. Follow-up questions? How to usefully abstract from XML in defining “push-based”? How to usefully share conceptual understanding across DOM and JAXB? ... between JAXB and Hibernate? ...
  • 16. An advanced programming class The Expression Problem The Visitor Design Pattern Parsing XML Processing XML Validation XML Data Binding Database Access O/R Mapping Model View Controller More Design Patterns Reflection Aspect-Oriented Programming Functional OO Programming Combinator Libraries Generic Programming Programming with Threads Distributed Programming WebService Programming
  • 17. Our ultimate goal: heavily annotate programmig and language technologies and their uses with metadata facilitating understanding.
  • 21. ...
  • 23. ...
  • 25. A few variation points X vs. O vs. R vs. λ etc. Static typing vs. dynamic typing Textual vs. abstract vs. visual syntax GPPL vs. DSL vs. embedding vs. API Instance- vs. operation-based mapping Type checking vs. inference vs. reasoning Code first vs. schema first vs. mapping only In-memory processing vs. push vs. pull parsing Pure vs. impure transformations (or in between) Code vs. generative vs. model-driven vs. mapping
  • 26. 101 ways to run a company.
  • 28. Model ANTLR company : 'company' STRING '{' dept* '}'; dept : 'department' STRING '{' ('manager' employee) ('employee' employee)* dept* '}'; employee : STRING '{' 'address' STRING 'salary' FLOAT '}'; WS : (' '|'r'? 'n'|'t')+ {skip();}; STRING : '"' (~'"')* '"'; FLOAT : ('0'..'9')+ ('.' ('0'..'9')+)?; CFGs for HR notation. The aspect of “sharing knowledge” is underestimated. Purity of CFGs is an i!usion.
  • 29. Model Haske! type Company = [Dept] data Dept = Dept Name Manager [SubUnit] type Manager = Employee data Employee = Employee Name Address Salary data SubUnit = PU Employee | DU Dept type Name = String type Address = String type Salary = Float Structure is defined by sequence, cases, and recursion. Algebraic datatypes imply tree shape of data instances. Models use nominal & structural types, and aliases.
  • 30. Model Ecore There are recurring themes for primitive types. Lists or co!ections may in fact be distinguished structural forms.
  • 31. Model Ecore/Java/EMF /** * @model */ public interface Person extends EObject { /** * @model required="true" ordered="false" */ String getName(); void setName(String value); /** * @model required="true" ordered="false" */ String getAddress(); void setAddress(String value); } Programs are models. Models are programs.
  • 32. <xs:element name="company"> ... </xs:element> <xs:complexType name="dept"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="manager" type="employee"/> <xs:element maxOccurs="unbounded" minOccurs="0" ref="subunit"/> </xs:sequence> </xs:complexType> <xs:element name="subunit"> <xs:complexType> <xs:choice> <xs:element name="pu" type="employee"/> <xs:element name="du" type="dept"/> </xs:choice> </xs:complexType> </xs:element> <xs:complexType name="employee"> <xs:sequence> <xs:element ref="person"/> <xs:element ref="salary"/> </xs:sequence> </xs:complexType> <xs:element name="person"> ... </xs:element> <xs:element name="salary"> ... </xs:element> Model XSD Let’s hope XSD goes away faster than Cobol.
  • 33. CREATE TABLE dept ( deptId INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), managerId INTEGER, FOREIGN KEY (managerId) REFERENCES employee(employeeID), upperDeptId INTEGER, FOREIGN KEY (upperDeptId) REFERENCES dept(deptId) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE employee ( employeeId INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL, salary DOUBLE, deptId INTEGER, FOREIGN KEY (deptId) REFERENCES dept(deptId) ON DELETE CASCADE ON UPDATE CASCADE ); Model SQL DDL Type references may be represented through key references. Eventua!y behavioral aspects join in.
  • 35. Total EMF/Java public class Total { public static double total(Company company) { double total = 0; for (Dept dept : company.getDepts()) total += total(dept); return total; } private static double total(Dept dept) { ... } private static double total(Subunit subunit) { ... } private static double total(Employee employee) { ... } } Queries over (systems of) recursive datatypes may require (systems of) recursive “functions”.
  • 36. Total Haske! total :: Company -> Float total = everything (+) (mkQ 0 id) Traversal or genera!y: quantification Type case
  • 37. Total XML/XQuery <result> {sum(//salary)} </result> A domain-specific language for queries is good at doing, we!, queries.
  • 38. Total XML/DOM/XPath public static double total(Document doc) throws Exception { double total = 0; NodeList nodelist = XPathAPI.selectNodeList(doc, "//salary"); for (int i=0; i<nodelist.getLength(); i++) { Element elem = (Element)nodelist.item(i); total += Double.parseDouble(elem.getTextContent()); } return total; } Host language may run embedded programs and inspect results.
  • 39. Total XML/Java/JAXB public class Total { public static double total(Company c) { double total = 0; if (c.getDept() != null) for (Dept d : c.getDept()) total += total(d); return total; } public static double total(Dept d) { ... } public static double total(Employee e) { ... } public static double total(Subunit s) { ... } } POJOs Time and again.
  • 40. Total SQL DML SELECT SUM(salary) FROM employee; What’s the XML/OO counterpart to projection? Query languages provide aggregators.
  • 41. Total Java / JDBC public static double total(MyConnection myConnection) throws SQLException { double total = 0; String query = "SELECT salary FROM employee"; PreparedStatement pstmtEmployees = myConnection .getConn() .prepareStatement(query); ResultSet salaries = pstmtEmployees.executeQuery(); while (salaries.next()) total += salaries.getDouble("salary"); return total; } Iterators on lazy server results
  • 42. Total RDF/Java/Jena public static double total(CompanyModel c) { double total = 0; StmtIterator i = c.getModel().listStatements( new SimpleSelector( null, c.SALARY, (RDFNode) null)); while (i.hasNext()) { Statement s = i.next(); total += s.getDouble(); } return total; } Selection (quantification) over graphs requires identities.
  • 43. Ecore/ATL module Total; create OUT: Total from IN: Company; rule Company2Total { from company : Company!Company to t : Total!TotalWrapper ( total <- Company!Employee.allInstances() -> collect(e | e.salary) -> sum() ) } Total Quantification, Projection, A'regation
  • 45. Cut Haske! cut :: Company -> Company cut = everywhere (mkT (/(2::Float))) The type of a pure function reveals its nature of being a transformation.
  • 46. Cut EMF/Java public class Cut { public static void cutCompany(Company company) { for (Dept dept : company.getDepts()) cut(dept); } private static void cut(Dept dept) { ... } private static void cut(Subunit subunit) { ... } private static void cut(Employee employee) { employee.setSalary(employee.getSalary() / 2); } } The appearance of “void” in an imperative (OO) language su'ests impure transformation.
  • 47. Cut XML/XQuery copy $copy := . modify for $salary in $copy//salary return replace value of node $salary with $salary div 2 return $copy The distinction of pure vs. impure is not always easy.
  • 48. Cut XML/XSLT <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:com="http://www.softlang.org/company.xsd" version="1.0"> <xsl:output method="xml" encoding="UTF-8"/> <xsl:template match="com:salary"> <xsl:copy> <xsl:value-of select=". div 2"/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> Don’t confuse notation with concepts. Conceptua!y, XSLT is potentia!y simple.
  • 49. Cut SQL DML UPDATE employee SET salary = salary / 2; Type-based quantification is rea!y simple with RDBMS.
  • 50. Cut RDF/Java/Jena public static void cut(CompanyModel c) { List<Statement> l = c.getModel().listStatements( new SimpleSelector( null, c.SALARY, (RDFNode) null)).toList(); for (Statement s : l) s.changeLiteralObject(s.getDouble() / 2); } laziness + mutation = evil
  • 51. Cut Ecore/ATL module Cut; create OUT: Company from IN: Company; rule Company2Company { from s : Company!Company to t : Company!Company ( depts <- s.depts ) } rule Employee2Employee { from s : Company!Employee to t : Company!Employee ( person <- s.person, salary <- s.salary / 2 ) } rule Dept2Dept { ... } rule Subunit2Subunit_Pu { ... } rule Subunit2Subunit_Du { ... } rule Person2Person { ... } Rule-based thinking as opposed to )ee-wheeling functions.
  • 53. Map Java/Serializable import org.softlang.company.*; import java.io.FileInputStream; import java.io.ObjectInputStream; FileInputStream fis = new FileInputStream("sampleCompany.ser"); ObjectInputStream in = new ObjectInputStream(fis); Object o = in.readObject(); in.close(); Company c = (Company)o; Use a universal object representation.
  • 54. XML/Java/JAXBMap @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {"name", "address"}) @XmlRootElement(name = "person") public class Person { @XmlElement(required = true) protected String name; @XmlElement(required = true) protected String address; public String getName() { return name; } public void setName(String value) { name = value; } public String getAddress() { return address; } public void setAddress(String value) { address = value; } } Annotations capture mapping including constraints.
  • 55. XML/Java/JAXB import org.softlang.company.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import java.io.File; File input = new File("sampleCompany.xml"); JAXBContext jaxbContext = JAXBContext.newInstance("org.softlang.company"); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); Company c = (Company) unMarshaller.unmarshal(input); Map There is a 1:1 mapping between names of program types & serialization-level names.
  • 56. Ecore/Java/EMFMap <GenModel ...> <genPackages prefix="Company" ...> <genClasses ecoreClass="Company.ecore#//Company"> <genFeatures ... ecoreFeature="...//Company/depts"/> </genClasses> <genClasses ecoreClass="Company.ecore#//Dept"> <genFeatures ... ecoreFeature="...//Dept/name"/> <genFeatures ... ecoreFeature="...//Dept/manager"/> <genFeatures ... ecoreFeature="...//Dept/subunits"/> </genClasses> ... </genPackages> </GenModel> types-to-types & properties-to-properties mapping modulo renaming and exclusion.
  • 57. Relational/Java/HibernateMap <hibernate-mapping> <class name="org.softlang.om.Dept" table="DEPT"> <id name="id" column="DEPT_ID"> <generator class="native" /> </id> <property name="name" /> <many-to-one name="manager" class="org.softlang.om.Employee" column="MANAGER_ID" unique="true" /> <set name="subunits" table="DEPT_SUBUNIT" inverse="true"> <key column="DEPT_ID" /> <many-to-many column="SUBUNIT_ID" class="org.softlang.om.Subunit" /> </set> </class> </hibernate-mapping> Given: tables and classes. Recover relationship as mapping.
  • 58. Relational/Java/Hibernate import org.hibernate.Session; import java.util.HashSet; import java.util.List; import java.util.Set; Company c = new Company(); c.session = new Configuration(). configure(). buildSessionFactory(). getCurrentSession(); c.session.beginTransaction(); List<?> depts = c.session.createQuery( "from Dept where UPPER_DEPT_ID is null").list(); for (Object o : depts) c.getDepts().add((Dept) o); Map Persistence incl. transactions
  • 59. Relational/Java/HibernateMap <hibernate-mapping> <class name="org.softlang.om.Dept" table="DEPT"> <id name="id" column="DEPT_ID"> <generator class="native" /> </id> <property name="name" /> <many-to-one name="manager" column="MANAGER_ID" class="org.softlang.om.Employee" /> <set name="employees" cascade="all"> <key column="DEPT_ID" /> <one-to-many class="org.softlang.om.Employee" /> </set> <set name="subDepartments" cascade="all"> <key column="UPPER_DEPT_ID" /> <one-to-many class="org.softlang.om.Dept" /> </set> </class> </hibernate-mapping> Another schema Another mapping
  • 61. GUI Java/Swing A GUI essentia!y provides a concrete syntax for the underlying language.
  • 62. GUI Ajax/Java[Script] /GWT Compared to a regular GUI, this scheme involves distribution, and, in fact, mapping.
  • 63. public CompanyInfo getCompanyInfo(Company company) { CompanyInfo companyInfo = new CompanyInfo(); for (Dept dept : company.getDepts()) companyInfo.getDeptsInfos().add(dept.getName()); return companyInfo; } public class CompanyInfo implements Serializable { private List<String> deptsInfos; public CompanyInfo() { deptsInfos = new LinkedList<String>(); } public List<String> getDeptsInfos() { return deptsInfos; } } public class Company { private List<Dept> depts; public Company() { depts = new LinkedList<Dept>(); } public List<Dept> getDepts() { return depts; } public Double total() { ... } public void cut() { ... } } Ajax/Java[Script] /GWTMap Instance-level mapping
  • 64. Our ultimate goal: heavily annotate programmig and language technologies and their uses with metadata facilitating understanding.