Programming Language Properties – Execution Model – Type Systems



Programming Language Properties – Execution Model – Type Systems

0 0


programming_language_properties


On Github pbrisbin / programming_language_properties

Programming Language Properties

Topics

  • Execution model: Interpret vs Compile
  • Type system: Dynamic vs Static
  • Paradigm: Object-oriented vs Functional

Execution Model

Interpret

              
              $ ruby -e 'puts "Hello"'
              Hello
              
            

Benefits

  • Immediate feedback
  • [Re]execute [new] code while running

Compile

              
              $ echo 'main = putStrLn "Hello"' > main.hs
              $ ghc -o main main.hs
              $ ./main
              Hello
              
            

Benefits

  • Performance
  • Catch errors are compile time
  • Closed source*

Type Systems

What is a Type

  • Concrete: String
  • Abstract: Enumerable

Dynamic

  • Types are "checked" at runtime
  • Duck typing
  • ⇒ NoMethodError

Benefits

  • Objects can change type at runtime
  • Patterns are easier: Dependency injection, Decorator, etc
              
              def current_user
                User.find(session[:user_id]) || Guest.new
              end
              
            

Static

  • Types are checked before runtime (usually at compile)
  • Many ways to do this (weak vs strong)

Benefits

  • Catch programmer error
  • Clarify implicit intentions
  • Requires a good type system
              
              detect :: (a -> Bool) -> [a] -> Maybe a
              detect = -- ...
              
            

Type Inference

  • Best of both words
  • No need to explicitly say what things are
  • Type system infers what type things are
              
              -- I never said what table to select from
              users <- runDB $ selectList [] []

              -- but because `userName` can only operate on Users, the
              -- system will *infer* that I wanted Users
              map userName users
              
            

Paradigms

Object Oriented Programming

Construct programs as a composition of Objects

Objects

  • State and behavior together
  • Encapsulation
  • Inheritance
              
                p = Person.new("Pat", 28)
                p.age
                # => 28

                p.grow
                p.age
                # => 29
              
            

Benefits

  • Fits with our conceptual model of the world
  • Everyone* is doing it

Functional Programming

the new hotness

Construct programs as a composition of Functions

Functions

  • Black box: Value in ⇒ value out
  • Pure: No side effects
  • Convert between immutable values
              
                let p  = Person "Pat" 28
                    p' = grow p
                in (age p, age p')
                -- => (28, 29)
              
            

Benefits

  • Performance
  • Concurrency / parallelism
  • Clarity
  • You get to sound smart by tossing around words like thunk, Functor and Monad

Thanks!

  • Pat Brisbin
  • http://pbrisbin.com
  • @patbrisbin
  • https://github.com/pbrisbin/programming_language_properties