The Larch Environment A VISUAL INTERACTIVE PROGRAMMING ENVIRONMENT

  • Slides: 108
Download presentation
The Larch Environment A VISUAL INTERACTIVE PROGRAMMING ENVIRONMENT http: //sites. google. com/site/larchenv G. FRENCH

The Larch Environment A VISUAL INTERACTIVE PROGRAMMING ENVIRONMENT http: //sites. google. com/site/larchenv G. FRENCH J. R. KENNAWAY A. M. DAY EUROPYTHON 2011 Image by alcomm, flickr. com

Motivation

Motivation

We look at three problems

We look at three problems

Textual output in a Python console can be difficult to understand (DEMO)

Textual output in a Python console can be difficult to understand (DEMO)

Source code in a text editor is not interactive enough Consoles are only good

Source code in a text editor is not interactive enough Consoles are only good for a few lines at a time

Textual source code can be difficult to understand comprehend (think the vertices of a

Textual source code can be difficult to understand comprehend (think the vertices of a polygon in code form)

What is ‘The Larch Environment’?

What is ‘The Larch Environment’?

A visual interactive programming environment

A visual interactive programming environment

The goal is: To make programming more visual

The goal is: To make programming more visual

How do we do that? • Visual object presentation • Programming environment – Visual

How do we do that? • Visual object presentation • Programming environment – Visual console – Worksheets • Visual programming via embedded objects

Visual object presentation

Visual object presentation

“Pictures are pretty” DEMO Visual console

“Pictures are pretty” DEMO Visual console

What design pattern do we commonly use for developing GUI apps?

What design pattern do we commonly use for developing GUI apps?

MVC Architecture Model View Controller

MVC Architecture Model View Controller

MVC requires: Model class, View class, Controller class

MVC requires: Model class, View class, Controller class

Our approach: Type coercion: coerce an object to another type.

Our approach: Type coercion: coerce an object to another type.

Type coercion used throughout Python

Type coercion used throughout Python

Examples: repr(), str() __index__() etc

Examples: repr(), str() __index__() etc

Its simple

Its simple

The Larch Environment: Use type coercion for visual presentation

The Larch Environment: Use type coercion for visual presentation

Coerce objects to something visual (a Pres)

Coerce objects to something visual (a Pres)

HOWTO: The simplified version

HOWTO: The simplified version

Define the following method: def __present__(self, fragment, inherited_state)

Define the following method: def __present__(self, fragment, inherited_state)

For Java objects: Implement Presentable interface

For Java objects: Implement Presentable interface

Presentations constructed using a combinatorial API

Presentations constructed using a combinatorial API

Label( ‘Hello’ ) Button. button. With. Label( ‘Button’ ) Hello Button a = Label(

Label( ‘Hello’ ) Button. button. With. Label( ‘Button’ ) Hello Button a = Label( ‘A’ ) b = Label( ‘B’ ) c = Label( ‘C’ ) d = Label( ‘D’ ) Row( [ a, b, c, d ] ) ABCD Column( [ a, b, c, d ] ) A B C D

Presentation combinators: Many more Flow layouts, mathematical fractions, superscript Rich text, other utilities Write

Presentation combinators: Many more Flow layouts, mathematical fractions, superscript Rich text, other utilities Write your own by combining existing ones! P. S. Appearance controlled with style sheets

“Type coercion is easy” DEMO: __present__()

“Type coercion is easy” DEMO: __present__()

Can also handle objects in the Java or Python standard libraries

Can also handle objects in the Java or Python standard libraries

Create an ‘object presenter’. Register it for the relevant class. When asked to present

Create an ‘object presenter’. Register it for the relevant class. When asked to present an instance of the class, Larch finds the appropriate presenter and uses it. (no monkeypatching required)

Thats how the images were shown; they are java. awt. Buffered. Image objects

Thats how the images were shown; they are java. awt. Buffered. Image objects

Perspectives

Perspectives

Different perspectives present an object in different ways

Different perspectives present an object in different ways

Like different views in MVC

Like different views in MVC

The one I have talked about (__present__, Presentable, etc) is the ‘Default perspective’

The one I have talked about (__present__, Presentable, etc) is the ‘Default perspective’

There are other perspectives

There are other perspectives

E. g. The inspector perspectives

E. g. The inspector perspectives

“Visual Introspection” DEMO: INSPECTOR PERSPECTIVE

“Visual Introspection” DEMO: INSPECTOR PERSPECTIVE

Programming Environment Visual console

Programming Environment Visual console

You’ve seen most of it

You’ve seen most of it

So lets look at some of the more ‘esoteric’ features

So lets look at some of the more ‘esoteric’ features

Model dragging

Model dragging

Everything in Larch is an object being presented (via type coercion)

Everything in Larch is an object being presented (via type coercion)

The home page Projects The console itself!

The home page Projects The console itself!

What if we want to manipulate an object that we can see?

What if we want to manipulate an object that we can see?

CTRL+ALT +drag it!

CTRL+ALT +drag it!

“I see something: how does it work? ” DEMO: inspect a project

“I see something: how does it work? ” DEMO: inspect a project

An interesting side fact!

An interesting side fact!

Our source code editor does not edit text

Our source code editor does not edit text

Its a structured editor Code is represented as an abstract syntax tree (AST)

Its a structured editor Code is represented as an abstract syntax tree (AST)

A perspective is used to present is as something that looks and behaves (mostly)

A perspective is used to present is as something that looks and behaves (mostly) like text

It means our code is in tree form

It means our code is in tree form

We can write our own refactorings!

We can write our own refactorings!

“Change your code fast!” DEMO: Refactoring

“Change your code fast!” DEMO: Refactoring

Programming Environment Worksheets

Programming Environment Worksheets

Interactive consoles are great. Caveat: gets difficult when working with more than a few

Interactive consoles are great. Caveat: gets difficult when working with more than a few lines of code at a time E. g. Whole modules

For complete programs we turn to a text editor We lose the interactivity

For complete programs we turn to a text editor We lose the interactivity

What if we could blend the two?

What if we could blend the two?

“Python modules. With pictures. ” DEMO: WORKSHEET (with cellular automata)

“Python modules. With pictures. ” DEMO: WORKSHEET (with cellular automata)

Act as modules Can import code from other worksheets within the project

Act as modules Can import code from other worksheets within the project

You can divide your module code into a number of blocks

You can divide your module code into a number of blocks

Each block can show a result – a step along the path of a

Each block can show a result – a step along the path of a computation

To refresh results: hit F 5

To refresh results: hit F 5

Rapid Edit-Run-Debug cycle: Alter code F 5 Repeat

Rapid Edit-Run-Debug cycle: Alter code F 5 Repeat

“Code faster!” DEMO: Edit-Run-Debug cycle (cellular automata)

“Code faster!” DEMO: Edit-Run-Debug cycle (cellular automata)

Visual Programming

Visual Programming

Quite a rich history in the research community

Quite a rich history in the research community

Circuit diagrams, data-flow diagrams, etc

Circuit diagrams, data-flow diagrams, etc

Nice for small simple programs

Nice for small simple programs

Large programs look like rat’s nests Not practical

Large programs look like rat’s nests Not practical

Text remains the dominant medium for source code

Text remains the dominant medium for source code

Diagrams are still appropriate in certain circumstances

Diagrams are still appropriate in certain circumstances

Lets use diagrams (or visual layout) where we need them!

Lets use diagrams (or visual layout) where we need them!

“Play God. ” DEMO: Orrery Sub-demos: Table editors Embedded table

“Play God. ” DEMO: Orrery Sub-demos: Table editors Embedded table

“Drawings. Inside code. ” DEMO: Polygon

“Drawings. Inside code. ” DEMO: Polygon

Embedded objects can use a protocol to customise their behaviour

Embedded objects can use a protocol to customise their behaviour

__py_eval__ Act like an expression - return the result of evaluating __py_evalmodel__ Act like

__py_eval__ Act like an expression - return the result of evaluating __py_evalmodel__ Act like an expression - return an AST __py_exec__ Act like a statement – called at runtime __py_execmodel__ Act like a statement – return an AST

AST Generation What does this sound like?

AST Generation What does this sound like?

AST Generation ~= Visual LISP macros

AST Generation ~= Visual LISP macros

Crosses compile-time / run-time barrier

Crosses compile-time / run-time barrier

Compile-time (edit-time) objects available at run time

Compile-time (edit-time) objects available at run time

Run-time objects / values can modify or be modified by compile-time objects

Run-time objects / values can modify or be modified by compile-time objects

“LISPy Smalltalky goodness” DEMO: LZW compressor

“LISPy Smalltalky goodness” DEMO: LZW compressor

Conclusions

Conclusions

Visual object presentation by typecoercion

Visual object presentation by typecoercion

Encourages a functional approach to UI composition

Encourages a functional approach to UI composition

State changes: Just throw UI elements away and re-create. DON’T MUTATE

State changes: Just throw UI elements away and re-create. DON’T MUTATE

Visual representation of values is a BIG EPIC WIN

Visual representation of values is a BIG EPIC WIN

Even if you use only visual cues (e. g. borders around text)

Even if you use only visual cues (e. g. borders around text)

Visual console and worksheets

Visual console and worksheets

Worksheets expand on the rapid edit-run cycle of the console

Worksheets expand on the rapid edit-run cycle of the console

Allow for rapid development of visual interactive applications

Allow for rapid development of visual interactive applications

Visual programming by embedded objects

Visual programming by embedded objects

Visual programming where you need it

Visual programming where you need it

Allows you to visually extend the syntax of the language

Allows you to visually extend the syntax of the language

No need to alter the compiler – its just embedded object references

No need to alter the compiler – its just embedded object references

References to objects you implement yourself

References to objects you implement yourself

Embedded object references Can cross compile-time / run-time barrier

Embedded object references Can cross compile-time / run-time barrier

LISPy / Smalltalky stuff IN PYTHON

LISPy / Smalltalky stuff IN PYTHON

PROJECT STATUS

PROJECT STATUS

Research Prototype (not ready for real use )

Research Prototype (not ready for real use )

TODOs: Documentation Bug fixes Too much more. . . .

TODOs: Documentation Bug fixes Too much more. . . .

Acknowledgements

Acknowledgements

Academic supervisory team Dr. Richard Kennaway Prof. Andy Day University of East Anglia, Norwich,

Academic supervisory team Dr. Richard Kennaway Prof. Andy Day University of East Anglia, Norwich, UK

The Jython team Developing The Larch would have been very difficult without Jython

The Jython team Developing The Larch would have been very difficult without Jython

IF TIME ALLOWS: DEMO: KD-Tree

IF TIME ALLOWS: DEMO: KD-Tree

IF TIME ALLOWS: DEMO: SIMPLE COMPILER

IF TIME ALLOWS: DEMO: SIMPLE COMPILER

THANK YOU! G. FRENCH J. R. KENNAWAY A. M. DAY http: //sites. google. com/site/larchenv

THANK YOU! G. FRENCH J. R. KENNAWAY A. M. DAY http: //sites. google. com/site/larchenv Image by alcomm, flickr. com