Thoughts on Programming Language Books by Magnus Madsen.

Post on 19-Dec-2015

220 views 2 download

Tags:

Transcript of Thoughts on Programming Language Books by Magnus Madsen.

Thoughts on Programming Language Books

by Magnus Madsen

Dear listener,

• Please take two minutes to think of the best programming language book that you have ever read (but don't tell anyone just yet)

Motivation

• I have recently (in the last few years) read a lot of programming language books

• Today, I will talk about three of them

• Disclaimer: My talk is not about books that teach people to program for the first time.

The Three Books

The Books (1)

The Red Book

• Martin Odersky• Lex Spoon• Bill Venners

• Published 2011 (2nd)

The Green Book

• Larry C. Paulson

• Published 1996 (2nd)

The Blue Book

• Harold Abelson• Gerald Jay Sussman

• Published 1996 (2nd)

An Inspiring Example (1)

def widthOfLength(s: String) = s.length.toString.lengthval lines = Source.fromFile(args(0)).getLines.toListval longestLine = lines.reduceLeft( (a, b) => if (a.length > b.length) a else b ) val maxWidth = widthOfLength(longestLine)for (line <- lines) { val numSpaces = maxWidth - widthOfLength(line) val padding = " " * numSpaces print(padding + line.length +" | "+ line)}

An Inspiring Example (2)

def widthOfLength(s: String) = s.length.toString.lengthval lines = Source.fromFile(args(0)).getLines.toListval longestLine = lines.reduceLeft( (a, b) => if (a.length > b.length) a else b ) val maxWidth = widthOfLength(longestLine)for (line <- lines) { val numSpaces = maxWidth - widthOfLength(line) val padding = " " * numSpaces print(padding + line.length +" | "+ line)}

higher-order function

implicit conversion

type inference

operator-named functions

if expression

uniform access

Example 1 (p. 76)

Programming in Scala, page 76

• Chapter: Basic Types and Operations• Topic: Floating point literals

"Floating point literals are made up of decimal digits, optionally containing decimal point, and optionally follow by an E or e and an exponent. Some examples of floating-point literals are..."(Examples follow)

ML for the Working Programmer, page 76

• Chapter: Lists• Topic: Some fundamental list functions

"...The length of a list can be computed by naïve recursion... (example in code)... Much better is an iterative version of the function that accumulates the count in another argument..."

Structure and Interpretation of Computer Programs, page 75

• Chapter: Building Abstractions with Procedures

• Topic: Abstractions and first-class procedures

"...We've seen two ways to express the square-root computation as instance of a more general method, once as a fixed-point search and once using Newton's method..."

Example 2 (p. 145)

Programming in Scala, page 145

• Chapter: Functions and Closures• Topic: First-class functions

"Scala has first-class functions. Not only can you define functions and call them, but you can write down functions as unnamed literals and then pass them around as values..."

ML for the Working Programmer, page 145

• Chapter: Trees and Concrete Data• Topic: Enumerating the contents of a tree

"Consider the problem of making a list of a tree's labels. The labels must be arranged in some order. Three well-know orders, preorder, inorder and post-order, can be described by a recursive function over trees..."

Structure and Interpretation of Computer Programs, page 145

• Chapter: Building Abstractions with Data• Topic: Example: Symbolic Differentation

"As an illustration of symbol manipulation and a further illustration of data abstraction, consider the design of a procedure that performs symbolic differentation of algebraic expressions..."

Example 3 (p. 241)

Programming in Scala, page 241

• Chapter: Packages and Imports• Topic: Concise access to related code

"Second, a package itself can be accessed from its containg package without needing a prefix. In listing 13.4, look at how class Navigator is instantiated. The new expression appears in package bobsrockets.navigation. Thus, it can access package bobsrockets.navigation as simply navigation."

ML for the Working Programmer, page 241

• Chapter: Reasoning About Functional Programs

• Topic: Computing Normal Forms

"The computation of distrib(p, q) may make recursive calls affecting either p or q. It terminates because every call reduces the value of nodes(p) + nodes(q)."

Structure and Interpretation of Computer Programs, page 241

• Chapter: Modularity, Objects, and State• Topic: The Rules for Evaluation

"Finally, we specify the behaviour of set! ... Evaluating the expression (set! (variable) (value)) in some environment locates the binding of the variable in the environment and changes that binding to indicate the new value..."

A pattern emerges...

Wait a minute ...

• Scala has tons of cool stuff, e.g.:– Traits– Case Classes & Pattern Matching– Implicit Conversions– etc. etc.

– OK, let's see them in action!

Programming in Scala, page 217

• Chapter: Traits• Topic: How traits work

trait def Philosophical { def philosophize() { println("I consume memory, therefore I am!") } }

A technical issue

How is the topic of equality and identity handled?

• Programming in Scala– 1 chapter

• ML for the Working Programmer– 1 page

• Structure and Interpretation of Computer Programs– 5 lines

Topics

Programming in Scala

• Classes & Objects• Basic Types & Operations• Functional Objects• Built-in Control Structures• Functions & Closures• Composition & Inheritance• Traits• Case Classes & Pattern Matching• Abstract Members• Implicit Conversions• For Expressions

• Working with XML• Actors & Concurrency• Combinator Parsing• GUI Programming• The SCells Spreadsheet

ML for the Working Programmer

• Mathematics– Complex Numbers– Binary Arithmetic– Matrix Arithmetic– Polynomial Addition & Multiplication

• Sorting Algorithms– Insertion sort– Quicksort– Merge sort

• Graph Algorithms– BFS, DFS– topological sorting

• Propositional Logic– Negational Normal Form

• Data Structures– Binary Trees– Priority Queues– Functional Arrays

• Formal Reasoning– Structural Induction– Program Verification

• Interpreters for the -Calculus– Lexing– Parsing– Evaluation

• Tactical Theorem Provers– First-order predicate logic– Unification

Structure and Interpretation of Computer Programs

• Mathematics– Newton's Method– Order's of Growth– Prime Numbers– Symbolic Differentation– Eight Queens Problem– Logic Circuits

• Data Structures– Hierarchical Structures– Lists– Infinite Data Structures– Queues

• Interpreters– Representing Expressions– Environments– Lazyness– Non-determinism

• Logic Programming– Query Languages

• Register Machines– Assembly Language– Implementing Recursion

Conclusion

A Good PL Book (1)

• Is not a language specification– I don't care about floating point literals– I don't care about packages– ...– But it does describe common pitfalls / traps• e.g. negative integers are prefixed with ~ in ML• e.g. misspellings in pattern matching can be fatal• e.g. if = is omitted from a function declaration in Scala

then the return type becomes Unit

A Good PL Book (2)

• Is not a project walk-through– I don't care about building:• a sudoku game• a web-shop• a spreadsheet• ...

– And remember, everyone hates GUI programming

A Great PL Book

• Demonstrates the power of the language by:

• Solving real problems– both classical and contemporary

• Solving hard problems– even if the details are messy– the sky is the limit

Thank You!

thoughts?