1 / 37

Thoughts on Programming Language Books

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.

mele
Download Presentation

Thoughts on Programming Language Books

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Thoughts on Programming Language Books by Magnus Madsen

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

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

  4. The Three Books

  5. The Books (1)

  6. The Red Book • Martin Odersky • Lex Spoon • Bill Venners • Published 2011 (2nd)

  7. The Green Book • Larry C. Paulson • Published 1996(2nd)

  8. The Blue Book • Harold Abelson • Gerald Jay Sussman • Published 1996(2nd)

  9. An Inspiring Example (1) def widthOfLength(s: String) = s.length.toString.length val lines = Source.fromFile(args(0)).getLines.toList val 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) }

  10. An Inspiring Example (2) uniform access type inference higher-order function defwidthOfLength(s: String) = s.length.toString.length val lines = Source.fromFile(args(0)).getLines.toList val 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) } if expression implicit conversion operator-named functions

  11. Example 1 (p. 76)

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

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

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

  15. Example 2 (p. 145)

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

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

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

  19. Example 3 (p. 241)

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

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

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

  23. A pattern emerges...

  24. 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!

  25. Programming in Scala, page 217 • Chapter: Traits • Topic: How traits work traitdef Philosophical { def philosophize() { println("I consume memory, therefore I am!") } }

  26. A technical issue

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

  28. Topics

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

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

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

  32. Conclusion

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

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

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

  36. Thank You! thoughts?

More Related