The following are slides from a seminar on Dynamic programming langauges, given at MSC Konsult, Stockholm, April 28, 2010.
Better Software with Dynamic Languages
Mikael Kindborg
2010-04-28
License: Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License
Programming background
Programming languages I have used:
ASTA 1982 Cobol 1982 Simula 1983-1984 CS4 1983 Lisp 1983-1990, 2000-2003 * Logo 1983-1984 * Prolog 1984-1985 Pascal 1985-1986 * C 1985-1999 * Scheme 1987-1988 Smalltalk 1985-1989, 2003-2010 * HyperTalk/SuperTalk 1997-1991 * Lingo 1990-1994, 1997 * C++ 1993-1999, 2006-2008 * PowerBuilder 1995-1996 * Visual Basic 1996 * Java 1995-2010 * JavaScript 1995-1999, 2009-2010 * ToonTalk 1999-2006 PHP 2001-2010 * Erlang 2002, 2004, 2008 Oz 2003-2005 Python 2003-2010 * Ruby 2005, 2008 (* = paid work)
Children's programming tools I have developed:
Concurrent Comics Magic Words
Favourite languages:
C Lisp Smalltalk Python JavaScript (CoffeScript)
Language I would like to learn:
Factor
Habits, conciousness, awareness
- Who has decided which language you are using in your project?
- Why is it used?
- What are the alternatives?
World's most popular programming environment
- Dynamic typing
- Strong typing
- Incremental
- Modeless (no build cycle)
- Visual/spatial
- Image-based
- Functional
This happens to be the spreadsheet!
Resolver - Spreadsheet in Python
This is an advanced spreadsheet that uses Python:
Prototyping vs Production
Dynamic languages are good for prototyping because they are fast to develop in.
Static languages are good for production because they are slow to develop in?
Myths
- Dynamic languages are slow (Scheme/Lisp, Erlang, Node.js (JavaScript) are fast)
- Dynamic languages cannot scale (Erlang, Smalltalk, GemStone/S scale)
- Dynamic languages are not safe (Erlang is for real-time systems)
- Dynamic languages are harder to code in, inexperienced programmers can screw up too easily
- Dynamic languages are a new trend. (Dynamic languages were big in 1980,
boosted by AI-research, Lisp, Smalltalk, Prolog, Concurrent Logic Programming, Logo)
Benchmarks: http://shootout.alioth.debian.org/
History
Modern languages and user interfaces have one big influence, Smalltalk and Alan Kay's team at Xerox PARC 1970-1980
- DynaBook
- Object-oriented programming
- Overlapping windows
- Bitmapped graphics
- Mouse interaction
- Networking (Ethernet)
- Font technology
- Printing technology
- Desktop publishing
http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html
Alan Kay Quotes
"Actually I made up the term 'object-oriented', and I can tell you I did not have C++ in mind."
"I'm not against types, but I don't know of any type systems that aren't a complete pain, so I still like dynamic typing."
"Java is the most distressing thing to hit computing since MS-DOS."
Demo of Squeak/Pharo
http://www.pharo-project.org/home
Code example:
Morph subclass: #Drawing
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'MyClasses'
initialize
super initialize.
self color: Color white.
self borderColor: Color black.
self borderWidth: 2.
self extent: 600@400.
self position: 50@50.
self clipSubmorphs: true.
self on: #mouseDown send: #createCircle: to: self.
createCircle: event
| circle |
circle := EllipseMorph new.
circle color: Color red.
circle borderColor: Color black.
circle borderWidth: 2.
circle extent: 100@100.
circle center: event position.
self addMorphFront: circle.StrongTalk and the history of the Java Jitter
To: self-interest@self.smli.com Subject: Sun buys Java compiler technology based upon Self!!! From: keith@uniteq.com (Keith Hankin) Date: Tue, 18 Feb 1997 17:38:17 -0800 Sun has just announced that they are buying Animorphic Systems, which for the last 2+ years has been developing JIT compiler technology for Java and Smalltalk. And, guess what? It's based upon the Self project!!! --- Source: http://www.merlintec.com/old-self-interest/msg01011.html
From: Dave Griswold <David.Griswold....@gmail.com> Date: Tue, 2 Sep 2008 12:14:32 -0700 (PDT) Local: Tues, Sep 2 2008 9:14 pm Subject: Chrome and V8 Hi everyone, It's been a while, but now that Google has announced Chrome and V8, I can finally make a little clearer a major reason why I haven't been pushing Strongtalk development for quite a while: Chrome's new JavaScript engine V8. The V8 development team has multiple members of the original Animorphic team; it is headed by Lars Bak, who was the technical lead for both Strongtalk and the HotSpot Java VM (as well as a huge contributor to the original Self VM). I think that you will find that V8 has a lot of the creamy goodness of the Strongtalk and Self VMs, with many big architectural improvements --- Source: http://groups.google.com/group/strongtalk-general/browse_thread/thread/40eb8f405fbd3041/0abb010f0eac18e9
http://www.strongtalk.org/history.html
On the StrongTalk Type System: It contains the first fully developed strong, static type system for Smalltalk (hence the name Strongtalk).
The type system is both optional and incremental, and operates completely independently of the compiler
technology (which means that normal untyped Smalltalk code runs just as fast as typed code).
Readability
- Shorter code is easier to read and to maintain and refactor
- Need balance between cryptic and expressive
Smalltalk:
square
^self * selfJavaScript:
function square(x) {
return x * x;
}CoffeeScript:
square: (x) ->
x * xJava:
public int square(int x) {
return x * x;
}CoffeeScript: http://jashkenas.github.com/coffee-script/
More examples
Smalltalk:
self on: #mouseDown send: #createCircle: to: self.
button on: #mouseDown send: #value to: [Object inform: 'You clicked me'].
JavaScript:
button.setOnClickListener(function (view) {
view.setText("You Clicked Me!");
});CoffeeScript:
button.setOnClickListener((view) -> view.setText("You Clicked Me!"))Java:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
(Button) view).setText(""You Clicked Me!")
}
});More CoffeeScript
CoffeeScript:
mood: greatly_improved if singing if happy and knows_it claps_hands() cha_cha_cha() date: if friday then sue else jill expensive: or do_the_math()
Compiles to JavaScript:
var date, expensive, mood;
if (singing) {
mood = greatly_improved;
}
if (happy && knows_it) {
claps_hands();
cha_cha_cha();
}
date = friday ? sue : jill;
expensive = expensive || do_the_math();Things that make life difficult
Source code analysis is clearly helpful, and optional type
declarations can add value, but in static languages that is not all you get.
You also get some less desirable things:
- Static inheritance relation - cannot be changed at runtime
- Type hierarchy lock in, not true polymorphism
- Interfaces are not protocol specifications, they are hierarchical types
- Primitive types
- Modifiers
- Generics
- Extreme line noise
- Things change, and static types, as the name implies, are not friendly to change
This:
public static final synchronized
List<Map<String, Product>> getProductList() {
List<Map<String, Product>> productList =
new ArrayList<Map<String, Product>>();
...
}Can be:
def getProductList():
productList = []
...
Strong points of dynamically typed languages
- Fast to develop
- Late binding
- Incremental development (no build cycles)
- Shorter code
- Easier to read code
- Easier to maintain/refactor code
- Aggressive Jitting possible with late binding
- Polymorphism/Duck typing
- High-level constructs, e.g. first-class functions and closures
- Syntax for data structures (tuples, lists)
- DSL-friendly
As one participant at the seminar pointed out, many of these points are also true of functional languages based on type inference, like Haskell and Ocaml.
Duck typing: "If it walks like a duck and talks like a duck, it must be a duck"
What makes Smalltalk special?
- Truly incremental development
- Late binding taken to the extreme
- Source code at your fingertips
- Innovative keyword syntax
- Succinct closure syntax
- Rich programming environment (doit, debugger, inspector, senders/implementors, refactoring browser...)
Weak points
- Type declarations serves as documentation
- Type declarations make refactoring tools more reliable
- Weak typing is a source of mistakes
- Implicit variable declarations are error prone
Cool! And thanks again for a great seminar :)
ReplyDelete@Melanie Thanks for the positive feedback!
ReplyDeleteHave updated the notes, fixed some errors and added a few items.
> "Actually I made up the term 'object-oriented', and I can tell you I did not have C++ in mind."
ReplyDeleteI think you'll find that should be a comma not a full-stop and Alan Kay continued - "... and I have many of the same feelings about Smalltalk."
OOPSLA'97 keynote
It's interesting to hear the laughter and applause after the C++ comment, and then the surprised puzzled silence after the Smalltalk comment.
@Anonymous Yes, I can imagine the puzzlement ;) I recall reading that Kay was disappointed with the direction Smalltalk-80 took, more complex than necessary and not for children anymore. I think he said something about "burning the disk packs". When I have some free time I will reread the History of Programming Languages chapters on Smalltalk.
ReplyDeleteFound this text: http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html
ReplyDelete