the larch environment

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

Upload: lazar

Post on 25-Feb-2016

22 views

Category:

Documents


0 download

DESCRIPTION

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. We look at three problems. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Larch Environment

A VISUAL INTERACTIVE PROGRAMMING ENVIRONMENT

ht tp : / / s i t e s .goog l e . com/s i te / l a r ch env

G. FRENCHJ. R . KENNAWAY

A. M. DAY

EUROPYTHON 2011

The Larch Environment

Image by alcomm, flickr.com

Page 2: The Larch Environment

Motivation

Page 3: The Larch Environment

We look at three problems

Page 4: The Larch Environment

Textual output in a Python console can be difficult to understand

(DEMO)

Page 5: The Larch Environment

Source code in a text editor is not interactive enough

Consoles are only good for a few lines at a time

Page 6: The Larch Environment

Textual source code can be difficult to understand and comprehend

(think the vertices of a polygon in code form)

Page 7: The Larch Environment

What is‘The Larch Environment’?

Page 8: The Larch Environment

A visual interactive programming environment

Page 9: The Larch Environment

The goal is:To make programming more visual

Page 10: The Larch Environment

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

• Visual programming via embedded objects

Page 11: The Larch Environment

Visual object presentation

Page 12: The Larch Environment

“Pictures are pretty”

DEMOVisual console

Page 13: The Larch Environment

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

Page 14: The Larch Environment

Model

View Controller

MVC Architecture

Page 15: The Larch Environment

MVC requires:Model class, View class, Controller

class

Page 16: The Larch Environment

Our approach:Type coercion

Type coercion: coerce an object to another type.

Page 17: The Larch Environment

Type coercion used throughout Python

Page 18: The Larch Environment

Examples:

repr(), str()

__index__()

etc

Page 19: The Larch Environment

Its simple

Page 20: The Larch Environment

The Larch Environment:Use type coercion for visual

presentation

Page 21: The Larch Environment

Coerce objects to something visual(a Pres)

Page 22: The Larch Environment

HOWTO:The simplified version

Page 23: The Larch Environment

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

inherited_state)

Page 24: The Larch Environment

For Java objects:Implement Presentable interface

Page 25: The Larch Environment

Presentations constructed using a combinatorial API

Page 26: The Larch Environment

Label( ‘Hello’ ) Hello

Button.buttonWithLabel( ‘Button’ )

Button

a = Label( ‘A’ )b = Label( ‘B’ )c = Label( ‘C’ )d = Label( ‘D’ )

Row( [ a, b, c, d ] ) ABCD

Column( [ a, b, c, d ] ) ABCD

Page 27: The Larch Environment

Presentation combinators:Many more

Flow layouts, mathematical fractions, superscript

Rich text, other utilitiesWrite your own by combining existing ones!

P.S. Appearance controlled with style sheets

Page 28: The Larch Environment

“Type coercion is easy”

DEMO:__present__()

Page 29: The Larch Environment

Can also handle objects in the Java or Python standard libraries

Page 30: The Larch Environment

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)

Page 31: The Larch Environment

Thats how the images were shown;they are java.awt.BufferedImage

objects

Page 32: The Larch Environment

Perspectives

Page 33: The Larch Environment

Different perspectives present an object in different ways

Page 34: The Larch Environment

Like different views in MVC

Page 35: The Larch Environment

The one I have talked about (__present__, Presentable, etc) is the

‘Default perspective’

Page 36: The Larch Environment

There are other perspectives

Page 37: The Larch Environment

E.g. The inspector perspectives

Page 38: The Larch Environment

“Visual Introspection”

DEMO: INSPECTOR PERSPECTIVE

Page 39: The Larch Environment

Programming Environment-

Visual console

Page 40: The Larch Environment

You’ve seen most of it

Page 41: The Larch Environment

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

Page 42: The Larch Environment

Model dragging

Page 43: The Larch Environment

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

Page 44: The Larch Environment

The home page

Projects

The console itself!

Page 45: The Larch Environment

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

Page 46: The Larch Environment

CTRL+ALT +drag it!

Page 47: The Larch Environment

“I see something: how does it work?”

DEMO: inspect a project

Page 48: The Larch Environment

An interesting side fact!

Page 49: The Larch Environment

Our source code editor does not edit text

Page 50: The Larch Environment

Its a structured editor

Code is represented as an abstract syntax tree (AST)

Page 51: The Larch Environment

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

Page 52: The Larch Environment

It means our code is in tree form

Page 53: The Larch Environment

We can write our own refactorings!

Page 54: The Larch Environment

“Change your code fast!”

DEMO:Refactoring

Page 55: The Larch Environment

Programming Environment-

Worksheets

Page 56: The Larch Environment

Interactive consoles are great.

Caveat: gets difficult when working with more than a few lines of code at a time

E.g. Whole modules

Page 57: The Larch Environment

For complete programs we turn to a text editor

We lose the interactivity

Page 58: The Larch Environment

What if we could blend the two?

Page 59: The Larch Environment

“Python modules. With pictures.”

DEMO: WORKSHEET(with cellular automata)

Page 60: The Larch Environment

Act as modulesCan import code from other

worksheets within the project

Page 61: The Larch Environment

You can divide your module code into a number of blocks

Page 62: The Larch Environment

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

computation

Page 63: The Larch Environment

To refresh results: hit F5

Page 64: The Larch Environment

Rapid Edit-Run-Debug cycle:

Alter codeF5

Repeat

Page 65: The Larch Environment

“Code faster!”

DEMO: Edit-Run-Debug cycle(cellular automata)

Page 66: The Larch Environment

Visual Programming

Page 67: The Larch Environment

Quite a rich history in the research community

Page 68: The Larch Environment

Circuit diagrams, data-flow diagrams, etc

Page 69: The Larch Environment

Nice for small simple programs

Page 70: The Larch Environment

Large programs look like rat’s nests

Not practical

Page 71: The Larch Environment

Text remains the dominant medium for source code

Page 72: The Larch Environment

Diagrams are still appropriate in certain circumstances

Page 73: The Larch Environment

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

Page 74: The Larch Environment

“Play God.”

DEMO: OrrerySub-demos:

Table editorsEmbedded table

Page 75: The Larch Environment

“Drawings. Inside code.”

DEMO: Polygon

Page 76: The Larch Environment

Embedded objects can use a protocol to customise their

behaviour

Page 77: The Larch Environment

__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

Page 78: The Larch Environment

AST Generation

What does this sound like?

Page 79: The Larch Environment

AST Generation

~=

Visual LISP macros

Page 80: The Larch Environment

Crosses compile-time / run-time barrier

Page 81: The Larch Environment

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

Page 82: The Larch Environment

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

time objects

Page 83: The Larch Environment

“LISPy Smalltalky goodness”

DEMO: LZW compressor

Page 84: The Larch Environment

Conclusions

Page 85: The Larch Environment

Visual object presentation by type-coercion

Page 86: The Larch Environment

Encourages a functional approach to UI composition

Page 87: The Larch Environment

State changes:Just throw UI elements away

andre-create.

DON’T MUTATE

Page 88: The Larch Environment

Visual representation of values is a BIG EPIC WIN

Page 89: The Larch Environment

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

Page 90: The Larch Environment

Visual console and worksheets

Page 91: The Larch Environment

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

Page 92: The Larch Environment

Allow for rapid development of visual interactive applications

Page 93: The Larch Environment

Visual programming by embedded objects

Page 94: The Larch Environment

Visual programming

where you need it

Page 95: The Larch Environment

Allows you to visually extend the syntax of the language

Page 96: The Larch Environment

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

Page 97: The Larch Environment

References to objects you implement

yourself

Page 98: The Larch Environment

Embedded object referencesCan cross compile-time / run-time

barrier

Page 99: The Larch Environment

LISPy / Smalltalky stuff

IN PYTHON

Page 100: The Larch Environment

PROJECT STATUS

Page 101: The Larch Environment

Research Prototype

(not ready for real use )

Page 102: The Larch Environment

TODOs:

DocumentationBug fixes

Too much more........

Page 103: The Larch Environment

Acknowledgements

Page 104: The Larch Environment

Academic supervisory team

Dr. Richard KennawayProf. Andy Day

University of East Anglia, Norwich, UK

Page 105: The Larch Environment

The Jython team

Developing The Larch would have been very difficult

without Jython

Page 106: The Larch Environment

IF TIME ALLOWS:DEMO: KD-Tree

Page 107: The Larch Environment

IF TIME ALLOWS:DEMO: SIMPLE COMPILER

Page 108: The Larch Environment

G. FRENCHJ. R . KENNAWAY

A. M. DAY

ht tp : / / s i t e s .goog l e . com/s i te / l a r ch env

THANK YOU!

Image by alcomm, flickr.com