![Page 1: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/1.jpg)
Dealing comfortably with the confusion of tongues
Ralf LämmelSoftware Languages Team, Koblenz
http://en.wikipedia.org/wiki/Tower_of_Babel_(M._C._Escher)
![Page 2: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/2.jpg)
Consider the following system. How to reasonably
summarize its architecture?
![Page 3: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/3.jpg)
RL: c9 is MSFT’s community-oriented
youtube.
![Page 4: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/4.jpg)
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
![Page 5: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/5.jpg)
A b
egin
ner’s
vie
w o
n ...
Ch
an
ne
l9
![Page 6: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/6.jpg)
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!
![Page 7: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/7.jpg)
• What domain?
• Programming
• X/O/R mapping
• XML/database processing
• GUI
• ...
• What engineering?
• megamodeling programming
• software language engineering
CHO
OSE Forum
2012
Dom
ain-specific Engineering
![Page 8: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/8.jpg)
A simpler riddle: how to usefully characterize these XML technologies?
DOM
SAX
StAX
![Page 9: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/9.jpg)
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). ...
![Page 10: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/10.jpg)
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. ...
![Page 11: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/11.jpg)
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. ...
![Page 12: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/12.jpg)
DOM SAX StAX
Read (parse, query) XML • • •
Write XML • •
Metadata! Metadata! Metadata!
![Page 13: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/13.jpg)
DOM SAX StAX
In-memory XML processing •Push-based XML parsing •Pull-based XML parsing •
Metadata! Metadata! Metadata!
![Page 14: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/14.jpg)
DOM SAX StAX
Standardization • ·
.NET counterpart • •
Metadata! Metadata! Metadata!
![Page 15: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/15.jpg)
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?
...
![Page 16: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/16.jpg)
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
![Page 17: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/17.jpg)
Our ultimate goal: heavily annotate programmig
and language technologies and their uses with metadata facilitating understanding.
![Page 18: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/18.jpg)
A running example:
101companies
http://sourceforge.net/apps/mediawiki/developers/index.php?title=101companies
![Page 19: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/19.jpg)
101companies
![Page 20: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/20.jpg)
![Page 21: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/21.jpg)
...
![Page 22: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/22.jpg)
![Page 23: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/23.jpg)
...
![Page 24: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/24.jpg)
![Page 25: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/25.jpg)
A few variation pointsX vs. O vs. R vs. λ etc.Static typing vs. dynamic typingTextual vs. abstract vs. visual syntaxGPPL vs. DSL vs. embedding vs. APIInstance- vs. operation-based mappingType checking vs. inference vs. reasoningCode first vs. schema first vs. mapping onlyIn-memory processing vs. push vs. pull parsingPure vs. impure transformations (or in between)Code vs. generative vs. model-driven vs. mapping
![Page 26: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/26.jpg)
101 ways to run a company.
![Page 27: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/27.jpg)
101companies
Modeling companies
![Page 28: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/28.jpg)
Model ANTLRcompany : '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.
![Page 29: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/29.jpg)
Model Haske!
type Company = [Dept]data Dept = Dept Name Manager [SubUnit]type Manager = Employeedata Employee = Employee Name Address Salarydata SubUnit = PU Employee | DU Depttype Name = Stringtype Address = Stringtype 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.
![Page 30: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/30.jpg)
Model Ecore
There are recurring themes for
primitive types.
Lists or co!ections may in fact be distinguished
structural forms.
![Page 31: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/31.jpg)
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.
![Page 32: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/32.jpg)
<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.
![Page 33: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/33.jpg)
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.
![Page 34: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/34.jpg)
101companies
Totaling salaries
![Page 35: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/35.jpg)
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”.
![Page 36: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/36.jpg)
Total Haske!
total :: Company -> Floattotal = everything (+) (mkQ 0 id)
Traversal or genera!y:quantification Type case
![Page 37: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/37.jpg)
Total XML/XQuery
<result>{sum(//salary)}</result>
A domain-specific language for queries is good at doing, we!, queries.
![Page 38: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/38.jpg)
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.
![Page 39: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/39.jpg)
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) { ... }
}
POJOsTime and again.
![Page 40: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/40.jpg)
Total SQL DML
SELECT SUM(salary) FROM employee;
What’s the XML/OO counterpart to projection?
Query languages provide aggregators.
![Page 41: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/41.jpg)
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
![Page 42: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/42.jpg)
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.
![Page 43: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/43.jpg)
Ecore/ATLmodule 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
![Page 44: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/44.jpg)
101companies
Cutting salaries
![Page 45: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/45.jpg)
Cut Haske!
cut :: Company -> Company
cut = everywhere (mkT (/(2::Float)))
The type of a pure function reveals its nature of being a transformation.
![Page 46: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/46.jpg)
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.
![Page 47: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/47.jpg)
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.
![Page 48: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/48.jpg)
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.
![Page 49: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/49.jpg)
Cut SQL DML
UPDATE employee SET salary = salary / 2;
Type-based quantification is rea!y simple with RDBMS.
![Page 50: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/50.jpg)
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
![Page 51: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/51.jpg)
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.
![Page 52: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/52.jpg)
101companies
Mapping companies
![Page 53: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/53.jpg)
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.
![Page 54: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/54.jpg)
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.
![Page 55: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/55.jpg)
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.
![Page 56: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/56.jpg)
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.
![Page 57: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/57.jpg)
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.
![Page 58: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/58.jpg)
Relational/Java/Hibernateimport 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
![Page 59: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/59.jpg)
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
![Page 60: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/60.jpg)
101companies
Interacting with companies
![Page 61: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/61.jpg)
GUI Java/Swing
A GUI essentia!y provides a concrete syntax for the underlying language.
![Page 62: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/62.jpg)
GUI Ajax/Java[Script] /GWT
Compared to a regular GUI, this scheme involves distribution, and, in
fact, mapping.
![Page 63: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/63.jpg)
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
![Page 64: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/64.jpg)
Our ultimate goal: heavily annotate programmig
and language technologies and their uses with metadata facilitating understanding.
![Page 65: Dealing comfortably with the confusion of tongueslaemmel/choose10/... · · 2010-10-22Dealing comfortably with the confusion of tongues Ralf Lämmel Software Languages Team,](https://reader036.vdocument.in/reader036/viewer/2022070607/5aacf7907f8b9a8d678d91b9/html5/thumbnails/65.jpg)
Thanks!Questions or comments?