44
ŻYWE JĘZYKI PROGRAMOWANIA LIVING IT UP WITH A LIVE PROGRAMMING LANGUAGE Sean McDirmid Ecole Polytechnique Fédérale de Lausanne (EPFL) [email protected] 5/24/2010 MARCIN HAGMAJER 1

Żywe języki programowania Living it up with a Live Programming Language

  • Upload
    niyati

  • View
    47

  • Download
    1

Embed Size (px)

DESCRIPTION

Żywe języki programowania Living it up with a Live Programming Language. Sean McDirmid Ecole Polytechnique Fédérale de Lausanne (EPFL) [email protected]. Agenda. Dynamiczne języki programowania. Programowanie wysokopoziomowe Dynamiczne typowanie Spadek wydajności Lisp Smalltalk - PowerPoint PPT Presentation

Citation preview

ywe jzyki programowania

ywe jzyki programowaniaLiving it up with a Live Programming LanguageSean McDirmidEcole Polytechnique Fdrale de Lausanne (EPFL)[email protected]

5/24/2010Marcin Hagmajer1A dynamic language improves programmer productivity through flexible typing, a focus on high-level programming, and by streamlining the edit-compile-debug cycle. Live languages go beyond dynamic languages with more programmer-centric features. A live language supports live programming that provides programmers with responsive and continuous feedback about how their edits affect program execution. A live language is also based on declarative programming constructs such as rules or data-flow connections so that programmers can write less code. A live language should also provide programmers with responsive semantic feedback to enable time-saving services such as code completion. This paper describes the design a textual live language known as SuperGlue. SuperGlue is based on reactive values known as signals that are supported with declarative data-flow connections and dynamic inheritance. Through signals and dynamic inheritance, SuperGlue supports live programming, declarative programming, and responsive semantic feedback. We demonstrate live programming in SuperGlue with a working prototype.1Agenda5/24/2010Marcin Hagmajer2Dynamiczne jzyki programowania5/24/2010Marcin Hagmajer3Programowanie wysokopoziomoweDynamiczne typowanieSpadek wydajnoci

LispSmalltalkErling

Programowanie na ywo5/24/2010Marcin Hagmajer4Jzyki wizualne5/24/2010Marcin Hagmajer5SUperGlueTekstowy, ywy jzyk programowania5/24/2010Marcin Hagmajer6SuperGlue5/24/2010Marcin Hagmajer7Dane zmienne w czasieSygnay dynamicznie dziedzicz po klasachPrzykad pocztkowy

5/24/2010Marcin Hagmajer8As an opening example, consider the following SuperGluecode that defines the Ghost class, three ghost signals,and connects the fill color of all ghost signals.

The first line of this code defines a Ghost class with a memberfill signal that extends the Color class.

The second line defines three signals, blinky, clyde, and bashful, which extend the Ghost class.

The third line is a rule that connects the fill signal of all ghosts, including blinky, clyde, and bashful, to the color blue.

When used in expressions, class identifiers are variable that quantify over all signals that extend the identified class.

Unlike imperative assignments, connection rules havedeclarative meaning that is unrelated to statement executionorder; e.g., on line three, blue is continuously connected torather than discretely assigned to the ghosts fill color.

8SygnayWartoci w grafie przepywu danych, ktre uatwiaj komunikacj pomidzy komponentami.S to obiekty dziedziczce po klasach, poczone z innymi sygnaami i zawierajce sygnay zdefiniowane w ich nadrzdnych klasach.Definiuje si je jako elementy klasy uywajc sowa kluczowego port5/24/2010Marcin Hagmajer9KlasyDefiniuj zachowanieNie s wartociami i mog by rozszerzone jedynie przez sygnayDefiniowane w najwyszej warstwie programu lub jako elementy inncyh klasy z wykorzystaniem sowa kluczowego class5/24/2010Marcin Hagmajer10PoczeniaDefiniuj zaleno pomidzy sygnaami, dziki czemu ich warto jest jednakowaS reguami podobnymi do prostych, jednokierunkowych ogranicze.Okrelany przy uyciu operatora =5/24/2010Marcin Hagmajer11Rozszerzenia (extensions)Sprawiaj, e sygnay rozszerzaj klasyReguy wycelowane w sygnay poza ich definicjDefiniowane z wykorzystaniem operatora / :5/24/2010Marcin Hagmajer12Warunki (conditions)Okrelaj kiedy reguy pocze i rozszerze mog by zastosowane.Odpytuj istniejce poczenia i rozszerzenia za pomoc tych samych operatorw (= i ), ktrych uywa si do ich stworzeniaTworzeone przez konstrukcje if otaczajce reguy pocze i rozszerze5/24/2010Marcin Hagmajer13Cel: uproszczony PacMan5/24/2010Marcin Hagmajer14Rysunek (1/4)

5/24/2010Marcin Hagmajer15The programmer types port pacMan . Figure to definea pacMan signal that extends the games Figure classso pacMan is drawn on the games canvas. Because ashape for pacMan has not been specified, it is drawn bydefault as a rectangle.15Rysunek (2/4)

5/24/2010Marcin Hagmajer16The programmer types the extension pacMan . Pie,which causes pacMan to extend the Pie class and bedrawn as a circle. The shape of pacMan is updated onscreen as soon as the programmer types the e in Pie.16Rysunek (3/4)

5/24/2010Marcin Hagmajer17The programmer types the connection pacMan.fill =yellow, causing this circle to be immediately coloredyellow. Through type inference, code completion cancomplete typing for .fill in pacMan.17Rysunek (4/4)

5/24/2010Marcin Hagmajer18The programmer types pacMan.extent = 330. As theprogrammer types each character in 330, pacMans appearsrespectively as a 357, 327, and finally a 30 degreeslice. The programmer than finishes this line with+ (time % 30), which causes pacMans mouth to closecontinuously in a 30 degree motion.18Rysunek - animacja

5/24/2010Marcin Hagmajer19Dodatkowe techniki5/24/2010Marcin Hagmajer20Stany stae i zmienne traktowane jednakowo

5/24/2010Marcin Hagmajer21Graf przepywu danych jest reaktywny. W ten sam sposb s traktowane stae i zmienne stany.

The last line of this code connects pacMans extent signalto an expression that continuously increases from 330 until360 degrees, causing pacMans mouth to shut continuously ina 30 degree motion. Such behavior occurs because the timesignal is a periodically incrementing number; e.g., it is connectedto 1042 and, after ten milliseconds, it is re-connectedto 1043.21Dynamiczne dziedziczenie

5/24/2010Marcin Hagmajer22For the duration that pacMan overlaps with some figure,pacMans overlaps signal is bound to the hit signal of thisfigure. The condition on line four is then only true for durationswhere the figure that pacMan overlaps with is a ghost.During these durations, pacMan extends the Damaged class,inheriting all the behavior of this class and being subject torules that target signals of this class. For example, the connectionof red to a damaged figures fill color would applyto pacMan while it overlaps with a ghost. As soon as pacManno longer overlaps with a ghost, it unextends the Damagedclass and the special damaged behavior no longer applies.22Typowanie zalene

5/24/2010Marcin Hagmajer23Consider this code that creates ten ghosts.On line nine, the inferredtype of ghosts.get contains the following classes:ghosts.get by definition, Duplicator.get because theghosts prefix extends Duplicator on line five, ghosts.Tbecause of the extension on line four and by a binding ofDuplicator to ghosts on line five, Duplicator.T by linefive again, and finally, Ghost and Figure by the extension online six. On line nine, the fill signal can be accessed andconnected because ghosts.get signals extend Figure.23Mediatory typw

5/24/2010Marcin Hagmajer24

Independently-developed or differently-purposed componentswill often not agree on the types of their non-primitivesignals. For this reason, SuperGlue permits connections betweentype-incompatible signals where additional rules candefine compatibility.

In this code the pacMans position is connected to a keyboard.The signal types involved in the connection on line five areincompatible: the type of pacMan.position contains onlythe Position class while the type of game.keyboard containsonly the Keyboard class. The programmer intends theposition of pacMan to be controlled by the keyboard. Suchintent can be realized with code that defines what it meansfor a signal to extend the otherwise unrelated Position andKeyboard classes.24Wnioskowanie typw

5/24/2010Marcin Hagmajer25On line four, the inferred type of Position includesonly the Position class because the type of a class identifieralways contains itself. On line six, Positions inferredtype also contains the PositionCell class because of thesurrounding extension-querying condition on line five. Asa result, the connection on line six, which targets the type(Position,PositionCell), overrides the connection on linefour, which targets the type (Position). Because Positionsinferred type on line six contains the PositionCell class, themember signal xc can be accessed through Position and islisted by code completion.25Wnioskowanie typw w Ide5/24/2010Marcin Hagmajer26Wnioskowanie typw w Ide (1/4)

5/24/2010Marcin Hagmajer27The programmer types port clyde . Ghost, where Ghostis underlined with red jaggies because it cannot be resolvedto a symbol.27Wnioskowanie typw w Ide (2/4)

5/24/2010Marcin Hagmajer28As soon as the programmer defines the Ghost class, thereference to Ghost in clydes definition becomes valid.The programmer then tries to access clydes positionsignal, which is underlined with red jaggies becauseposition is not a member of clyde.28Wnioskowanie typw w Ide (3/4)

5/24/2010Marcin Hagmajer29As soon as the programmer causes the Ghost class to extendthe MyFigure class, the access to clydes positionsignal becomes valid.29Wnioskowanie typw w Ide (4/4)

5/24/2010Marcin Hagmajer30Because the position signal in all Ghost signals extendsthe Position class, the x and y position signals show upin code completion on clydes position signal.30Wnioskowanie typw w Ide

5/24/2010Marcin Hagmajer31Realizacja jzyka5/24/2010Marcin Hagmajer32przetwarzanie kodu5/24/2010Marcin Hagmajer33Parsowaniez pierwszestwem

Damage and repairZmiany w kodzieZmiany stanu wywoane sygnaem

Zmiana grafu przepywu danych

Bdy czasu wykonania5/24/2010Marcin Hagmajer34bdy reportowane jako wartoci sygnaw w osobnym oknieprogram kontynuujez wartociami domylnymi

implementacja5/24/2010Marcin Hagmajer35Sygnay

5/24/2010Marcin Hagmajer36

A signal provider implements the Signal interfaces evalmethod to provide a signals current value and ensure that anObserver is notified when that value changes.

The SuperGlue runtime produces and consumes signalsaccording to the Signal Java interfaces based on the therules of a SuperGlue program. For example, the connectionperiod = 100 causes the SuperGlue runtime to createa Java Signal object that returns 100 when its eval methodis called. As we discuss in Section 3, edits to code will notifyobservers of the signals derived from the edited code;e.g., when the 100 token is changed through editing, the SuperGlueruntime will notify all observers that the periodseval method was called with. It is through the implementationand routing of signals via declarative rules that Super-Glue adds its value to the program; i.e., SuperGlue acts as amiddle man between components that do the real work.

The time signals eval method schedules a timer task tonotify the caller that the time has changed, which occursin period milliseconds. A signal consumer calls the Signalinterfaces eval method to access a signals value, and canprovide an observer so that it is notified of changes in thevalue. For example, the time signal calls the eval methodon the clocks period signal to obtain the clocks period.The time signals implementation passes its called observerdirectly into the period signal. As a result, when a clocksperiod signal change, its time clients are notified directly.

36Rozszerzenia

5/24/2010Marcin Hagmajer37

The enter and exit methods of a class extension are calledwhen a signal starts or stops extending a class, which occurswhen the signal is created, destroyed, or when the guardof an extension changes. The enter and exit methods ofa class extension are responsible for managing the signalsstate with respect to the class.

37PacmanDokoczenie gry5/24/2010Marcin Hagmajer38PacMan (1/4)

5/24/2010Marcin Hagmajer39pacMans position is bound to the keyboard of the canvasit is displayed in. So that pacMans orientation correspondsto the direction it is moving in, its rotationsignal is bound to its position. pacMan then moves asexpected in a video game.39PACMAN (2/4)

5/24/2010Marcin Hagmajer40Ghosts for the game are created by defining a ghostssignal that extends the Duplicator class. Initially twoghosts are created, which are drawn as ghost shapes onthe canvas by extending the Figure and Ghost classes.Because both ghosts occupy the same default position,only one ghost is visible.40PACMAN (3/4)

5/24/2010Marcin Hagmajer41The Ghost class is defined as an open extension to theghosts.get class. In this class, the position and fillsignals of each ghost extend the Random class, causingeach ghost to have a random color and motion.41PACMAN (4/4)

5/24/2010Marcin Hagmajer42Finally, the number of ghosts is changed from two toeight, causing six more ghosts to appear after aroundthree seconds of edit latency.42pacman

5/24/2010Marcin Hagmajer43Dzikuj5/24/2010Marcin Hagmajer44