1.08k likes | 1.2k Views
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.
E N D
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
Textual output in a Python console can be difficult to understand(DEMO)
Source code in a text editor is not interactive enoughConsoles are only good for a few lines at a time
Textual source code can be difficult to understand and comprehend(think the vertices of a polygon in code form)
How do we do that? • Visual object presentation • Programming environment • Visual console • Worksheets • Visual programming via embedded objects
What design pattern do we commonly use for developing GUI apps?
MVC Architecture Model View Controller
Our approach:Type coercionType coercion: coerce an object to another type.
The Larch Environment:Use type coercion for visual presentation
Define the following method:def __present__(self, fragment, inherited_state)
Label( ‘Hello’ ) Hello Button Button.buttonWithLabel( ‘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 moreFlow layouts, mathematical fractions, superscriptRich text, other utilitiesWrite your own by combining existing ones!P.S. Appearance controlled with style sheets
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 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.BufferedImage objects
The one I have talked about (__present__, Presentable, etc) is the ‘Default perspective’
Everything in Larch is an object being presented (via type coercion)
Its a structured editorCode is represented as an abstract syntax tree (AST)