Why I Still Program in Smalltalk Outline Summary
Total Page:16
File Type:pdf, Size:1020Kb
Why I still program Outline in Smalltalk •Introduction, Background •What do Programmers Need? Musings on Software Development •Some History •What Is Smalltalk? Stephen Travis Pope • Language, Libraries, Tools, Methodology [email protected] Relationship to Other Languages, IDEs, etc. UCSB MAT Colloquium • January 14, 2012 •Why I Still Use Smalltalk http://HeavenEverywhere.com/WISPiST.pdf •A Call to Revolutionary Action 1 2 Summary (spoiler alert) NeXT ad from 1992 3 4 My Background What I Develop (& biases) Complex projects (music, AI, high-level tools) Training: EE, CS, Music • • Media-rich (A/V) •HW Development Projects • • Analog Synths, Eventide •DB-rich (large volumes, complex queries) • Vienna, Salzburg jobs •Wide-area distributed Programming • Cross-platform • Low-level, lots of tool-building, then LISP • • Visits to MIT and SAIL in 1976/77 •Performance-critical (compute-bound) • UNIX & C starting in 1976 •Back-end servers and front-end GUIs Graphics starting in 1979 • • C/C++, Python, MATLAB, SuperCollider, SQL • IRCAM, [email protected] 5 6 MODE, 1990-92 Context: 1983 Culture “Girls just want to have fun” “Puttin’ on the Ritz” 7 8 Context: 1983 Context Computing STP & CB in 1984 (photos by CR) 9 10 What do Programmers Need? What do Programmers Need? •Software Development Processes • Edit code • Compile, link •Software development tools! • Run, debug • Test • Document • Share, manage multi-programmer teams • Package, deliver • Maintain, upgrade 11 12 What do Programmers Need? Requirements Analysis •Great Overviews of the 1980s • Why Pascal is Not My Favorite Programming Language (BWK, 1981) ‣ Requirements for an Experimental Programming Environment (LPD, 1982) • The Organization of Expert Systems (1982) • An OO Approach to Multimedia Databases (1986) • Programmer as Reader (AG, 1986) • Requirements for an Experimentation Environment for Composers (STP, 1988) 13 14 Req_Exp_Prog_Env (lang) * Req_Exp_ * * * Prog_Env * * * * * * * * 15 16 Req_Exp_Prog_Env (L2) Req_Exp_Prog_Env (Tools) * * * * * * * * * 17 18 Req_Exp_Prog_Env (Libs) Req_Exp_Prog_Env * * * * * * 19 20 Programmer as Reader •Rules of Reuse: 1: If you can’t find it, you can’t reuse it •Insight: Software engineers spend more time 2: If you don’t trust it, you won’t reuse it reading than writing; therefore code reading •Ease of learning via high-level concepts tools are really important. • As in real life •Later insight: Code rewriting, refactoring, ... •Encourage good design & coding style by use •“Reading and writing are partners” of templates • Should use same/similar tools •Design of Smalltalk Browsers • E.g., not emacs and google • Find, test, reuse 21 22 Summary On-going Debates Language Issues Smart people have thought long and hard • • Uniform vs hybrid OO (is everything an object?) about how to improve programmer ‣ • Kinds of sharing of state and behavior productivity and code quality • Classes vs prototypes • Language issues • Single/multiple inheritance (composition, traits) • Library issues • Interfaces, protocols, abstract classes Development tool issues • Type declarations (vs type inferencing) • Performance/reusability/LoE trade-offs Operating system and environment • • Preferred syntax (many variants) Support for OOP & rapid prototyping and ‣ • ‣ Coding style and enforcement incremental refinement (refactoring, agileP) •Library/Tool/Environment issues? 23 24 Programming Languages A Brief History •Maximal (complex, •Minimal (simple, multi-paradigm, single paradigm) kitchen sink) •Scheme LISP •ALGOL •PASCAL •CS landmarks leading up to 1983 •PL/1 •Smalltalk •CommonLISP •Lua •ADA •MathLangs •C++ •APL, FP, Prolog, ... •Scripting (?) 25 26 1970s SMALLTALK-72 INSTRUCTION MANUAL ADELE GOLDBERG AND ALAN KAY, EDITORS History 1968: Englebart’s “Mother of all Demos” • DynaBook 1972: Kay’s “A Personal Computer for • \ Children of All Ages” \ \ •1976: Kay & Goldberg’s “Personal Dynamic Media” \ •1970s Xerox/MIT Hardware Development • Xerox Alto, MIT LISP Machines •Unix OS (open-source, licensed) 27 28 Interim Dynabook 29 30 OOP History IDE History •1960s •Smalltalk • Simula-67 (Augment/NLS, Sketchpad, ...) •LISP •1970s (uniform languages) • MIT Smalltalk-72, -76, -80 (i.e., V3) • • Xerox • FlavorsLISP • InterLISP-D & LOOPS •Others • Actor • Mesa/Cedar (PARC) •1980s (hybrid languages) • Maestro (PET) 1975 • Objective-C, C++ (1983) • UCSD Pascal, 1978 • ObjectPascal (1985) • TurboPascal (Borland), 1981 • Eiffel, ADA •Barstow, Shrobe & Sandewall, 1984 31 32 UCSD So, like, what is Smalltalk? Pascal •“The Smalltalk Programming System” •Language •(Class) Libraries •(Integrated) Development Environment •Delivery Mechanism •Methodology •Book series •Operating system? •Look-and-feel? PARC Learning Research Group 33 34 Smalltalk History NoteTaker 35 36 Early 1981 Smalltalk PR Smalltalk’s Design Principles 1977 •(See Byte, 8/81) •Reuse of Personal Mastery (OO Models) •Language • Available to developer and user alike • Model of Communicating (Concurrent) Objects • Objects, Storage Mgmnt, Messages/Methods • Organization • Modularity, Classification • Polymorphism, Factoring, Leverage (reuse) 37 38 Smalltalk’s Design Principles Smalltalk-as-OS •User Interface •Operating system: “A collection of the objects • “Language in which most of the communication is that didn’t fit into the language, i.e., there visual” shouldn’t be one” (Dan I) • Reactive Principle (all objects have GUIs) •OS components in the library • All windows, tools and apps are objects • Storage mgmnt, File system, Networking, Threads, • Any text can be executed (no shell) Scheduler, Display handling, User I/O •System • ST can run without/instead of an OS “When Smalltalk was little, she thought she • Everything is open (lots of rope, but there are nets • -- code DB and crash recovery) was an operating system.” 39 40 Smalltalk Language •Truly minimal syntax • One best way to write any given expression • Keyword syntax (rather than algebraic syntax) • Very few reserved words, no adjectives •Everything is an object •Objects only interact by message-passing •Instance and class messages •Control structures are messages (extensible) •Objects and classes are reflective • isKindOf:, understands:, allInstances Complete BNF of Smalltalk - Learning, coding, compiling 41 42 Everything is an object? Is this really so important? •Really? •Java argument (types vs classes) •Yes! •No stand-alone functions •Class creation (msg to superclass[es]) •No passive data structures •Control structures (aBool ifTrue: []) •“Evolutionary rather than revolutionary” •Low-level arithmetic (3 + 4) •Promotes Exception-handling ([] on: anExc handle: []) • Learning, finding • Reuse Debugging print (Transcript show: aValue) • • • Extensibility •Files, Sockets, Threads, Error conditions • Code management •Compiler, Browser, ... •Example: aList := aString asPath: sepChar 43 44 Keyword Syntax Control Structures •(As opposed to algebraic syntax) •Blocks, Booleans and Intervals are objects •To get an item out of an array Smalltalk: cl := [ :x :y | x + y ]. ‣ item := anArray at: 1 C++ 0x: auto cl = [&] (int x, int y) { return x + y; }; •To assign into an array •If/then/else ‣ anArray at: 1 put: anObject z > 0 ifTrue: [ “do this block” ] To construct a new Rectangle ifFalse: [ “otherwise, do this block” ] • For loops ‣ aRectangle := Rectangle left: 0 right: 4 top: 0 bottom: 4 • ‣ aRectangle := Rectangle left: 0 top: 0 width: 4 height: 4 1 to: 5 do: [ :num | • Always alternate keyword/argument Transcript show: (num * num) printString; cr] Also: do/while, switch, catch/throw, ... • Never have a list of arguments without keyword • • No operator precedence rules - 3 + 4 * 2 = 14 ! • Extensible control structures (!) 45 46 Smalltalk Libraries Smalltalk Libraries •Single root class (Object) •Protocol of Object •All classes can be extended (!) • Messages understood by all objects •Heavy use of polymorphism •Important high-level abstractions Mostly single inheritance • Magnitudes (number, point, date, character) • Collections (array, string, set, dictionary) Use composition and forwarding by default • • • Streams (file, socket, producer, server) Other sharing mechanisms (species, MI, generic • • Model, View, Controller classes behaviors, traits, interfaces, passing blocks, etc.) • Graphics classes • “Core” = ~1000 classes; VW 7.9 = ~3300 classes • Event classes 47 48 Class Hierarchies Special Features •Infinite-precision math •Metanumerics •Many graphical models •Several flavors of schedulers •ChangeSets, Namespaces, Packages •OO design patterns • Adaptor, Visitor, Singleton, Observer, Factory, Prototype, Composite, Decorator, Facade, Proxy, ... 49 50 Events Magnitudes & and Sequenceable Collections Views 51 52 The Smalltalk Pluggable GUI Look and Feel •Graphics rendering •BitBLT, SPIM, OpenGL •Window Manager •Was the OS •Can use host OS windows •MVC Classes •Widgets, wrappers, Look&Feel •Multi-screen, multi-desktop, multi-user GUIs •Standard tools (B-I-E) 53 54 Smalltalk IDE Code Browsers •Browsers •Uniform access to all system source code in • Browse collections of objects (e.g., classes) a hypertext browser with full-text search • Organization of set •Unit of change (compilation) is a method • Operations on inner nodes & leaf nodes •Many kinds •Inspectors • Package, Namespace, Hierarchy, Refactoring • Low-level access to an object’s properties • Cross-referencing (reflection & code DB) • May violate encapsulation •Code editing aids •Editors • Formatter, spelling, auto-complete, explainer • Customized inspector • Templates for classes, methods, documentation