Thoughts on Programming Language Books by Magnus Madsen.

37
Thoughts on Programming Language Books by Magnus Madsen
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    220
  • download

    2

Transcript of Thoughts on Programming Language Books by Magnus Madsen.

Page 1: Thoughts on Programming Language Books by Magnus Madsen.

Thoughts on Programming Language Books

by Magnus Madsen

Page 2: 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)

Page 3: Thoughts on Programming Language Books by Magnus Madsen.

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.

Page 4: Thoughts on Programming Language Books by Magnus Madsen.

The Three Books

Page 5: Thoughts on Programming Language Books by Magnus Madsen.

The Books (1)

Page 6: Thoughts on Programming Language Books by Magnus Madsen.

The Red Book

• Martin Odersky• Lex Spoon• Bill Venners

• Published 2011 (2nd)

Page 7: Thoughts on Programming Language Books by Magnus Madsen.

The Green Book

• Larry C. Paulson

• Published 1996 (2nd)

Page 8: Thoughts on Programming Language Books by Magnus Madsen.

The Blue Book

• Harold Abelson• Gerald Jay Sussman

• Published 1996 (2nd)

Page 9: Thoughts on Programming Language Books by Magnus Madsen.

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)}

Page 10: Thoughts on Programming Language Books by Magnus Madsen.
Page 11: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 12: Thoughts on Programming Language Books by Magnus Madsen.

Example 1 (p. 76)

Page 13: Thoughts on Programming Language Books by Magnus Madsen.

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)

Page 14: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 15: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 16: Thoughts on Programming Language Books by Magnus Madsen.

Example 2 (p. 145)

Page 17: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 18: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 19: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 20: Thoughts on Programming Language Books by Magnus Madsen.

Example 3 (p. 241)

Page 21: Thoughts on Programming Language Books by Magnus Madsen.

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."

Page 22: Thoughts on Programming Language Books by Magnus Madsen.

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)."

Page 23: Thoughts on Programming Language Books by Magnus Madsen.

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..."

Page 24: Thoughts on Programming Language Books by Magnus Madsen.

A pattern emerges...

Page 25: Thoughts on Programming Language Books by Magnus Madsen.

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!

Page 26: Thoughts on Programming Language Books by Magnus Madsen.

Programming in Scala, page 217

• Chapter: Traits• Topic: How traits work

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

Page 27: Thoughts on Programming Language Books by Magnus Madsen.

A technical issue

Page 28: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 29: Thoughts on Programming Language Books by Magnus Madsen.

Topics

Page 30: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 31: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 32: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 33: Thoughts on Programming Language Books by Magnus Madsen.

Conclusion

Page 34: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 35: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 36: Thoughts on Programming Language Books by Magnus Madsen.

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

Page 37: Thoughts on Programming Language Books by Magnus Madsen.

Thank You!

thoughts?