2. Finding the best leverage
(How) Can I Move It?(How) Can I Move It?
Multiply the Available ForceMultiply the Available Force
3. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 3
Leverage
●
Software re-shapes the world as we know it
●
Languages shape how we think about software
●
Tools shape how we work with languages
By empowering millions of software developers,
we might indeed “move the world”?
By empowering millions of software developers,
we might indeed “move the world”?
4. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 4
Agenda
●
Java 8
– supporting innovation in the Java world
●
@NonNull
– bringing quality assurance to the Java world
●
Roles in Object Teams
– extending the Object-Oriented paradigm
●
Domain Specific Languages
– abstractions for sustainable retail applications
5. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 5
JDT ready for Java 8
●
Eclipse should „support“ Java 8:
●
Compiler should accept and compile Java 8
– analysis (resolve types, detect errors)
– produce class files
●
JDT/UI should support working with Java 8
– visualize
– modify
Java 8 ready
8
2013 / 2014
6. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 6
Java 8
●
A big step in the evolution of Java!
– λ
– default methods
– type annotations
– library enhancements
– …
8
7. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 7
Compiling λ
●
„Just“ a bit new syntax
8
personList.setLabelProvider(new LabelProvider<Person>() {
public String getLabel(Person p) {
return p.getFullName();
}
});
personList.setLabelProvider(p -> p.getFullName());
personList.setLabelProvider(Person::getFullName);
8. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 8
λ Backstage
●
Abbreviated code style relies on type inference
●
Challenges
– „guess“ all the types that have been omitted
– deterministic
– no 7½ million years Deep Thought pondering
8
9. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 9
Prior Art – Aggravated
●
Lambdas are typically arguments to
generic library functions
– public static <T, K, U, M extends Map<K, U>>
Collector<T, ?, M> toMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper,
BinaryOperator<U> mergeFunction)
●
Would you prefer to call:
– Collectors.<Person,String,Integer,Map<String,Integer>>toMap(..)
●
or:
– Collectors.toMap(..)
●
Similar for instantiation of a generic class (Java 7)
– Collector<String,Integer> coll = new MyCollector<>();
●
How does it work?
8
10. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 10
How it works
●
Solving this little example
– Map<String, Integer> test3(Stream<Person> persons) {
return persons.collect(Collectors.toMap(
p -> p.getLastName(),
p -> p.getAge(),
(i1, i2) -> i1+i2));
}
●
Produces these constraints:
8
12. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 12
Chicken and Egg
●
Type inference
– Infers types of arguments
●
based on a given method signature
●
Overloading
– Selects method
●
e.g., based on types of arguments
<U> void m(Listener<U> l);
<T> void m(Consumer<T> c);
…
m(a -> print(a));
13. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 13
Genesis of a new Java Feature
spec
abstractly capture
the concepts
ecj
implement the spec,
the full spec,
and nothing but the spec
deviation
bug?
bug?
bug?
compare behavior
javac
8
14. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 14
Take-Away Java 8
●
Second implementation improves quality
●
Java is a Monster
– E.g.: overloading conflicts with type inference ...
– „Orthogonality in Language Design –
Why and how to fake it.“ [Herrmann 2003]
●
ECJ is an enabler
– used by implementations for „working with Java 8“
8
15. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 15
Contribution
●
No own invention: Don't interpret!
– No influence on the direction of change
– Some influence on the quality
●
Interact with users / bug reporters
●
Be part of a big step for the Java world
– Acknowledged in the JLS 8 preface
8
16. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 16
Quality
●
Quality of Java as a Language
– governed by a specification (JLS)
●
Quality of Java Programs?
– can JDT help developers avoiding problems / bugs?
– which problems?
17. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 17
Quality
●
Quality of Java as a Language
– governed by a specification (JLS)
●
Quality of Java Programs?
– can JDT help developers avoiding problems / bugs?
– which problems?
18. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 18
An Old Problem
●
1965
– Tony Hoare introduced Null references in ALGOL W
– “simply because it was so easy to implement”
– “The Billion Dollar Mistake”
PhotographbyRama,WikimediaCommons,Cc-by-sa-2.0-fr
19. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 19
An Old Problem
●
1965
– Tony Hoare introduced Null references in ALGOL W
– “simply because it was so easy to implement”
– “The Billion Dollar Mistake”
●
Today
– All Java software is threatened by risk of NPE
– Can we bid „bye-bye“ to NPE?
NPE
NPE
20. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 20
2005
1. Flow Analysis
●
Flow Analysis in the Compiler
– needed to check „definite assignment“
– was extended for null information in Eclipse 3.1
– gradually improved ever since
NPE
21. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 21
2005
1. Flow Analysis
●
Flow Analysis in the Compiler
– needed to check „definite assignment“
– was extended for null information in Eclipse 3.1
– gradually improved ever since
NPE
22. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 22
1. Flow Analysis
●
Flow Analysis in the Compiler
– needed to check „definite assignment“
– was extended for null information in Eclipse 3.1
– gradually improved ever since
+1
– high precision
-1
– some warnings can be perceived as „false positives“
– (slightly) incomplete analysis of loops
– no inter procedural analysis!
NPE
23. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 23
1. Flow Analysis
●
Flow Analysis in the Compiler
– needed to check „definite assignment“
– was extended for null information in Eclipse 3.1
– gradually improved ever since
+1
– high precision
-1
– some warnings can be perceived as „false positives“
– (slightly) incomplete analysis of loops
– no inter procedural analysis!
NPE
NPE
24. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 24
2. Null Annotations
●
Use @NonNull and @Nullable
– declare contracts for methods (and fields)
●
Use @NonNullByDefault
– to alleviate the annotation burden
●
(70% of „good API“ are @NonNull by intention)
2012
NPE
25. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 25
2. Null Annotations
●
Use @NonNull and @Nullable
– declare contracts for methods (and fields)
●
Use @NonNullByDefault
– to alleviate the annotation burden
●
(70% of „good API“ are @NonNull by intention)
2012
NPE
26. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 26
2. Null Annotations
●
Use @NonNull and @Nullable
– declare contracts for methods (and fields)
●
Use @NonNullByDefault
– to alleviate the annotation burden
●
(70% of „good API“ are @NonNull by intention)
+1
– detect contract violations
●
definition, usage and specialization
– feed context information into flow analysis
-1
– does not cover: generics (type parameters, type variables)
2012
NPE
27. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 27
2. Null Annotations
●
Use @NonNull and @Nullable
– declare contracts for methods (and fields)
●
Use @NonNullByDefault
– to alleviate the annotation burden
●
(70% of „good API“ are @NonNull by intention)
+1
– detect contract violations
●
definition, usage and specialization
– feed context information into flow analysis
-1
– does not cover: generics (type parameters, type variables)
2012
NPE
NPE
28. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 28
3. Null Type Annotations
●
@NonNull and @Nullable „Everywhere“
– JSR 308: Annotations on Java Types
●
„Make nullness a part of the type system“
Two kinds of types
●
those that include null
●
those that don't
2014
NPE
+1
@Target(ElementType.PARAMETER)
@interface NonNull5 {}
void java5(@NonNull5 String arg);
arg is qualified to be non-null
@Target(ElementType.TYPE_USE)
@interface NonNull8 {}
void java8(@NonNull8 String arg);
String is qualified to be non-null
29. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 29
3. Null Type Annotations
●
@NonNull and @Nullable „Everywhere“
– JSR 308: Annotations on Java Types
●
„Make nullness a part of the type system“
Two kinds of types
●
those that include null
●
those that don't
2014
NPE
+1
@Target(ElementType.PARAMETER)
@interface NonNull5 {}
void java5(@NonNull5 String arg);
arg is qualified to be non-null
@Target(ElementType.TYPE_USE)
@interface NonNull8 {}
void java8(@NonNull8 String arg);
String is qualified to be non-null
30. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 30
NPE
3. Null Type Annotations
●
@NonNull and @Nullable „Everywhere“ 2014
NPE
+1
31. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 31
NPE
3. Null Type Annotations
●
@NonNull and @Nullable „Everywhere“ 2014
NPE
+1
32. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 32
4. External Annotations
●
Attach annotations to libraries 2015
NPE
33. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 33
4. External Annotations
●
Attach annotations to libraries 2015
NPE
34. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 34
4. External Annotations
●
The bad news:
– No more excuse
– You've got some home work to do
●
Existing code:
– who is responsible for handling null?
– recover design that probably has decayed?
●
New code:
– start by saying @NonNullByDefault
– always be explicit about null (or avoid it)
NPE
35. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 35
Contribution
●
Not the only tool for null analysis
●
But the most complete main-stream solution
– to the tiniest, most embarrassing problem in Java
NPE
NPE
36. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 36
Paradigm Shift?
●
Paradigms connect ...
– metaphors (intuition)
– technical solution (precise semantics)
●
„Languages shape how we think about software“
– null annotations
●
not a paradigm
– functional programming
●
the shift happened before my time
●
Object-oriented programming
– a paradigm shift in the 1980s
– is this the end of evolution?
37. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 37
Reconsider Inheritance
+1
– Derive a new concept from an existing one
– Describe only the differences
– May coincide with subtyping
-1
– Doesn't scale
– Cannot model changes over time
38. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 38
Scale
Player Token
Move Rule validate(Move m)
Player Token
Move Rule validate(Move m)
BoardGame
Chess
≙ Chess.Move
≙ BoardGame.Move
Token
Move Rule
39. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 39
Introducing Object Teams
●
team class Chess
– package (namespace) & class (instances)
●
team class Chess extends BoardGame
– aka Family Polymorphism
●
propagating specialization
●
typesafe covariance
40. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 40
Change
Person
name
Employee
salary
41. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 41
Change
●
Properties
– Dynamism:
roles can come and go
(same base object)
– Multiplicities:
one base can play several roles
(different/same role types)
playedBy Relationship
Person
name
Employee
salary
«playedBy»
name=”joe”
joe: Person
:Student
matr=0815
«base»
:Employee
salary=100
«base»
:Employee
salary=2000
«base»
Employee
salary
Role Base
Person
name
42. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 42
Introducing Object Teams
●
team class Chess
– package (namespace) & class (instances)
●
team class Chess extends BoardGame
– aka Family Polymorphism
●
class Student playedBy Person
– „inheritance“ among instances
●
sharing of common properties
●
overriding
Arbitrary mix of language features?
Synergy?
Arbitrary mix of language features?
Synergy?
43. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 43
Roles & Teams
●
Roles depend on context
– contexts are reified as Teams
●
Each team instance can be (de)activated
– active team instances contribute to the system state
– dispatch considers system state
:Person
phoneNo
getPhoneNo()
c :Companyc :Company
name
hire(Person p)
name
hire(Person p)
:Employee
officePhoneNo
getPhoneNo ← getPhoneNo
«playedBy»
getPhoneNo()
Off On
if (c.isActive())
getPhoneNo()
44. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 44
Contribution
●
Ingredients
– years of research (since 1999)
– years of engineering
– new paradigm?
●
powerful new metaphors
●
precise underpinning
●
Move the world?
– big step
– few adopters
46. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 46
Goals
●
Separation of concerns …
– … can we identify the pure business logic?
– … how do you port your app to a new platform?
●
Software product line
– Many mechanisms to offer extensibility
– Shortage of extensibility on demand
47. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 47
Business Logic
●
Domain Objects
– Entities
●
attributes
●
references
●
Flow / Processes
– States / Steps
– Transitions
●
event
●
condition
●
action
48. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 48
Domain Specific Languages
●
Textual modeling languages (9)
– syntax
●
grammar
– semantics
●
name resolution, validation
– IDE functions
●
navigation, outline, search, hover, quick fix, …
●
Separate but connected
– Inter-language integration
– Diagrams are derived
– Light-weight documentation
●
tightly integrated with Mylyn WikiText
Mix-n-match plug-in integration
50. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 50
Safe for any Future
●
Generate source code
– for new target platforms
●
Interpret models @ runtime
– cool for monitoring, debugging …
●
Migrate existing models
– to new versions of the language
●
Thanks to EMF underpinning!
51. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 51
Draw from Experience
●
Full type checking
– all types are nonnull by default
– optional types are marked, e.g., Item?
●
Customization on demand
– all models can be specialized
– propagating specialization
Player Token
Move Rule
Player Token
Move Rule
BoardGame
Chess
Token
Move Rule
NPE
52. Stephan Herrmann: Innovation through languages and tools? - Eclipse Day India 2015 # 52
Move the World?
spec
ecjjavac
It's the taking part that counts
Resolving the tiniest,
most embarrassing problem in Java
Big progress,
at a low multiplication factor.
Mix-n-match paradigm shift,
for one mid-sized company.
NPE