ruby go and haskell
play

Ruby, Go and Haskell Matt Walston University of North Florida Ruby - PowerPoint PPT Presentation

Ruby, Go and Haskell Matt Walston University of North Florida Ruby Everythings an object Dynamic reflection and meta programming Duck typing Blocks and Iterators Fibers Everything an Object All inherit from BasicObject


  1. Ruby, Go and Haskell Matt Walston University of North Florida

  2. Ruby • Everything’s an object • Dynamic reflection and meta programming • Duck typing • Blocks and Iterators • Fibers

  3. Everything an Object • All inherit from BasicObject • Ancestor chains can be long • Examples? • nil.class # => NilClass • 3.class # => FixNum • 4.method(:abs).class # => Method • Fixnum.ancestors 
 # => Integer, Numeric, Comparable, Object, Kernel, BasicObject

  4. Metaprogramming Features • eval • const_set • instance_eval • const_get • class_eval • Class.new • class_variable_set • binding • class_variable_get • send • class_variables • remove_method • instance_variable_set • undef_method • define_method • method_missing

  5. Reflection Examples • Pretty Print • Sinatra • ActiveRecord

  6. Type System • No primitives • Dynamic • Duck • Type conversion

  7. Iteration • Avoid loops, create iterator and pass block • each method, each_with_index • Enumerators

  8. Blocks, Proc and lambda • Blocks • Reusability • Syntax • Proc vs lambda • Example?

  9. Fibers • Lightweight alternative to threads • Low level • EventMachine adds capability • Example?

  10. Killer App?

  11. Go • Based on C • Simple and concise by design • Goroutines and channels • Garbage collection • Type checking

  12. Based on C • Google’s knowledge base and on-boarding • Curly braces • Simple programs are easy to port, 
 Complex programs are difficult • Use features you know and like

  13. Simple and Concise • Only one loop— for • Type inference— count:= 9 • Go range iterate arrays, slices, strings and maps • Anonymous functions • Multiple returns

  14. Goroutines • Concurrency mechanism, not parallelism • Multiple processors = parallel execution • Not distributed, same OS, same address space • Much simpler than threads • Simple call function with go keyword

  15. Channels • Important for go routines • Ability to pass messages back • Example?

  16. Garbage Collection • Early source of problems • Not constant time • Beats JVM— hands down with dynamic langs

  17. Types • Statically typed, appears dynamic • Interfaces are not explicitly typed to class, 
 Similar to duck typing • Type safety through no direct pointer access

  18. Haskell • Purely functional, functions lack side effects • Type classes • Pattern matching • Lazy evaluation • List comprehension

  19. Purely Functional • Lack of side effects • Concurrency • Recursion • Complete referential transparency • Accepted programs will always terminate

  20. Lazy Evaluation • Vital to a functional language • Infinite lists

  21. List Comprehension • Improved readability through syntactic sugar • Generators expand into lists • May lazily evaluate for countably infinite lists

  22. Recursion • Tail call optimization less important • Minimal call stack frame size • Important due to pure functional nature • Example?

  23. Quicksort in Haskell qs :: Ord a => [a] -> [a] 
 qs [] = [] 
 qs (p:xs) = (qs l) ++ [p] ++ (qs g) 
 where 
 l = filter (< p) xs 
 g = filter (>= p) xs

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend