590 likes | 763 Views
Presentation Techniques for more Expressive Programs. Andrew Eisenberg PhD Oral Defense. Brett is a programmer. I need the mean of a bunch of integers. The program Brett intends to write. The program in Java. public double mean(List<Integer> x) { int sum = 0; for (int i : x) {
E N D
Presentation Techniques for more Expressive Programs Andrew Eisenberg PhD Oral Defense
Brett is a programmer I need the mean of a bunch of integers
The program in Java public double mean(List<Integer> x) { int sum = 0; for (int i : x) { sum += i; } return sum / x.size(); }
Ducky is a programmer What does this mean? public double mean(List<Integer> x) { int sum = 0; for (int i : x) { sum += i; } return sum/ x.size(); }
Another Program What does this mean? Perceived Meaning Intended Meaning
Expressive programs An expressive program is one where its perceived meaning reliably aligns with its intended meaning. public double mean(List<Integer> x) { int sum = 0; for (int i : x) { sum += i; } return sum / x.size(); }
Expressiveness • Many things affect a program’s expressiveness • language features • abstraction techniques • naming conventions …and… • presentation
Using presentation for more expressive programs • Need a different kind of editor • Is this feasible? • Architecture? • Capabilities? • Kinds of programs?
Thesis statement Program editors that can present programs using a non-surjective relationship to the concrete syntax enable a set of presentation techniques that are natural alternatives to existing language design, editor design, and programming best-practices techniques. Careful use of these presentation techniques appears to lead to more expressive programs.
Argument structure 5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
Architecture is Feasible • Composable Presentation Editor Architecture • Two implementations • ETMOP (Edit time metaobject protocol) • Open, extensible editor • Presentation extensions • Embedded CAL • Closed, domain specific editor • Embeds a small language in a host language • Developed at Business Objects • Now part of CAL open source distribution
ETMOP Presentation Extensions @Getter("get") @Setter("set") private int x; @Previous private int y; @Getter("get") @Setter("set") private int x; public int getX() { return x; } public void setX(int x) { this.x = x; } @Previous private int y; public int getY() { return y; } public void setY(int y) { this.y = y; } Edit time Metaobject protocol (ETMOP) editorprovides editing semantics Compile time Metobject protocol (CTMOP)provides execution semantics
5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
Presentation Techniques • Spatial arrangement • Textual manipulation • Temporal referencing • Graphical enhancements • Constrained editing public @After(value="changes(p)") void changesAdvice(Point p){ Screen.logDistanceFromOrigin(p); } @Pointcut("this(p) && execution(void Point.set*(int))") void changes(Point p){}
Parse & Apply metadata Program AST + Metadata @Getter("get") private int x; @Previous private int y; @Getter("get") private int x; @Previous private int y; Metadata is shared between field declarations
Logical Layout Logical Layout AST + Metadata Program @Getter("get") private int x; @Previous private int y;
Physical Layout Logical Layout Physical Layout AST + Metadata Program @Getter("get") private int x; @Previous private int y;
Source ↔ Presentation Logical Layout Physical Layout AST + Metadata Program @Getter("get") private int x; @Previous private int y; • “get” gets shunted around • allows spatial arrangement • (other presentation techniques as well)
5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
Establish editor & language properties • Abstraction in computer programs • Polymorphism • Inheritance • Functional abstraction … • Graphical enhancements Example: Defining webservices
Webservices are verbose public class HelloService { public String sayHello(String username) { return "Hello "+username+"!!!"; } public String sayHelloDocument(String username) { System.out.println(username+" said hello!!!"); } } • RPC over internet • Implementation (Java) • WSDL service descriptor (XML) <?xml version="1.0" encoding="utf-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.org/wsm/10/2004/SimpleES" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://example.org/wsm/10/2004/SimpleES" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <types> <xsd:schema targetNamespace="http://example.org/wsm/10/2004/SimpleES"> <xsd:element name="sayHello"> <xsd:complexType> <xsd:sequence> <xsd:element name="username" type="xsd:string" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="greetings"> <xsd:complexType> <xsd:sequence> <xsd:element name="greetings" type="xsd:string" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="sayHelloDocument"> <xsd:complexType> <xsd:sequence> <xsd:element name="username" type="xsd:string" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </types> <message name="sayHello"> <part name="username" element="tns:sayHello"/> </message> <message name="greetings"> <part name="username" element="tns:greetings"/> </message> <message name="sayHelloDocument"> <part name="username" element="tns:sayHelloDocument"/> </message> <portType name="SimpleExampleService"> <operation name="sayHello"> <input message="tns:sayHello"/> <output message="tns:greetings"/> </operation> <operation name="sayHelloDocument"> <input message="tns:sayHelloDocument"/> </operation> </portType> <binding name="SimpleExampleServiceSoapHttp" type="tns:SimpleExampleService"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> <operation name="sayHello"> <soap:operation soapAction="urn:sayHello" style="rpc"/> <input> <soap:body use="literal" namespace="http://example.org/wsm/10/2004/SimpleES"/> </input> <output> <soap:body use="literal" namespace="http://example.org/wsm/10/2004/SimpleES"/> </output> </operation> <operation name="sayHelloDocument"> <soap:operation soapAction="urn:sayHelloDocument" style="document"/> <input> <soap:body use="literal"/> </input> </operation> </binding> <service name="SimpleExampleWebService"> <port name="SimpleExampleServiceSoapHttp" binding="tns:SimpleExampleServiceSoapHttp"> <soap:address /> </port> </service> </definitions>
Java annotations as abstraction mechanism @WebService( name="HelloWebService", targetNamespace= "http://example.org/wsm/10/2004/SimpleExampleService") @SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL) public class HelloService { @WebMethod(action="urn:sayHello") @WebResult(name="greetings") public String sayHello( @WebParam(name="username") String username) { return "Hello "+username+"!!!"; } @WebMethod(action="urn:sayHelloDocument") @OneWay @SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL) public String sayHelloDocument( @WebParam(name="username") String username) { System.out.println(username+" said hello!!!"); } } • JSR 181 • specification • defines Webservices as annotations in Java code • pre-processor converts to WSDL Webservice concern is tangled with Java concern Presentation techniques provide alternative abstraction mechanism
Abstraction: Metadata vs. Graphical @WebService(name=“HelloWebService", targetNamespace= "http://example.org/wsm/10/2004/SimpleExampleService") @SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL) public class HelloService { @WebMethod(action="urn:sayHello") @WebResult(name="greetings") public String sayHello( @WebParam(name="username") String username) { return "Hello "+username+"!!!"; } @WebMethod(action="urn:sayHelloDocument") @OneWay @SOAPBinding(style= SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL) public String sayHelloDocument( @WebParam(name="username") String username) { System.out.println(username + " said hello!!!"); } } • Metadata: • all text • Graphical: • Java implementation is clear • icons emphasize structure • stored form is text
5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
Ideas are expressed What is the perceived meaning of this program?
Perceived meaning This is a Java class… I see icons that indicate a Webservice This is likely to be a Java class that implements a webservice.
5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
More expressive Recall: An expressive program is one in which the perceived meaning reliably aligns with the intended meaning.
Intended meaning This is a program about Java class that implements a Webservice This is a program about Java class that implements a Webservice Intended and Perceived meanings align More expressive
Alternative Presentation This is a program about Java class that implements a Webservice (Mockup)
Alternative Perceived Meaning This looks like a webservice I can see the structure of the Webservice But how is it implemented? This is a program about Java class that implements a Webservice Intended and Perceived meanings do not align Less expressive
Summary of claims • Editors that enable a set of presentation techniques are feasible to implement. • Architecture & two implementations • These presentation techniques are alternativesto standard programming language and editor techniques. • Graphical abstraction • Proper use of these techniques make programs more expressive. • Presenting webservices
Open Questions • Are these presentations useful? • feasibility of implementing editors • properties of programs • user study • Definition of expressiveness • qualitative, not quantitative • does not allow absolute analysis • can be used comparatively
Related Work • Editor architectures • Traditional (Emacs, vi) • Hard structure • Cornell Program Synthesizer [Teitelbaum 81] • Interlisp-D [Barstow 81] • Soft structure (Eclipse, Visual Studio, NetBeans) • Display-oriented • DrScheme [Findler 97] • MPS [Dmitriev 04] • Domain Workbench [Simonyi 06] • Smalltalk [Goldberg 83] • Expressiveness through language extension • Syntax Macros [Leavenworth 66] • Attribute grammars [Kennedy 76] • Syntactic stylesheets [Edwards 05] • Metaobject protocols [Kiczales 91] • Expressiveness through Multi-lingual programming • Embedding syntax [Bravenboer 04] • Common runtime environments [Meijer 00] • Pipelines [Garlan 93] • Service-oriented architecture [Newcomer 04]
Related Work • Editor architectures • Traditional (Emacs, vi) • Soft structure (Eclipse, Visual Studio, NetBeans) • Language extension mechanisms
Bijection Surjection Soft-structure editors package ca.ubc.ships; public class Ship { private int x; private int y; public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } }
Composable Presentation editors Non-Surjection @Getter("get") private int x; @Previous private int y; Can copy, rearrange, remove elements
Related Work • Editor architectures • Traditional (Emacs, vi) • Soft structure (Eclipse, Visual Studio, NetBeans) • Display-driven • DrScheme [Findler 97] • MPS [Dmitriev 04] • Domain Workbench [Simonyi 06] • Language extension mechanisms • Syntax Macros [Leavenworth 66] • Syntactic Stylesheets [Edwards 05]
Contributions • Composable presentation editor architecture • Set of presentation techniques • Qualitative framework for evaluating expressiveness of programs • Analysis of how presentation techniques compare to other kinds of techniques • ETMOP-CTMOP • open, extensible editor & semantic processor • set of examples • Embedded CAL • closed, domain specific editor
Thank you! 5. More Expressive When aligned with intended meaning 4. Higher Level ideas Express 3. Various Editor and language properties Establish 2. Presentation Techniques Enables 1. Architecture (is feasible)
Temporal Referencing Sum of constants must be 100