augmenting dynamic typing with static analysis
play

Augmenting Dynamic Typing with Static-Analysis Reid Draper - PowerPoint PPT Presentation

Augmenting Dynamic Typing with Static-Analysis Reid Draper @reiddraper Reid Draper @reiddraper takeaways tl;dr JUST USE HASKELL JUST USE IDRIS several modern functional languages have optional type systems they are mature enough to be


  1. Augmenting Dynamic Typing with Static-Analysis Reid Draper @reiddraper

  2. Reid Draper @reiddraper

  3. takeaways

  4. tl;dr

  5. JUST USE HASKELL

  6. JUST USE IDRIS

  7. several modern functional languages have optional type systems

  8. they are mature enough to be useful

  9. they find real bugs

  10. and improve documentation

  11. with some work, you can integrate them into your CI system

  12. motivation

  13. %% Return a list of locators, in our case, we'll use cluster names %% that were saved in the ring cluster_mgr_sites_fun() -> %% get cluster names from cluster manager Ring = riak_core_ring_manager:get_my_ring(), Clusters = riak_repl_ring:get_clusters(Ring), [{?CLUSTER_NAME_LOCATOR_TYPE, Name} || {Name, _Addrs} <- Clusters].

  14. static-typing has many benefits

  15. prevents many errors during compile-time

  16. enhanced documentation

  17. %% @doc Return a list of all manifests in the %% `active' or `writing' state active_and_writing_manifests(Dict) -> orddict:to_list(filter_manifests_by_state(Dict, [active, writing])).

  18. %% @doc Return a list of all manifests in the %% `active' or `writing' state -spec active_and_writing_manifests(orddict:orddict()) -> [{binary(), lfs_manifest()}]. active_and_writing_manifests(Dict) -> orddict:to_list(filter_manifests_by_state(Dict, [active, writing])).

  19. -spec f(orddict:orddict()) -> [{binary(), lfs_manifest()}]. �

  20. a guide for structuring programs

  21. (potentially) better performance

  22. there are many popular dynamically-typed languages in industry

  23. JavaScript Java PHP C# Python � C++ Ruby C Objective-C CSS Perl Shell Scala Haskell R Matlab Clojure CoffeeScript Visual Basic Groovy http://redmonk.com/sogrady/2014/01/22/language-rankings-1-14/

  24. so what do we do?

  25. can we add a type-system?

  26. Retrofitting a type system into a language not designed with typechecking in mind can be tricky; ideally, language design should go hand-in-hand with type system design. Benjamin C. Pierce, Types and Programming Languages p. 9

  27. history

  28. an incomplete and likely wrong history

  29. 1989 adding dynamic types to a statically-typed language M. Abadi, L. Cardelli, B. Pierce, G. Plotkin, statically-typed language

  30. 1991 Cartwright and Fagan introduce Soft-Typing Robert Cartwright, Mike Fagan,

  31. 1991 "The key concept of soft typing is that a type checker need not reject programs containing statically 'ill typed' phrases" Robert Cartwright, Mike Fagan,

  32. 1994 Soft-Types implemented with Scheme Andrew K. Wright , Robert Cartwright,

  33. 1997 Marlow and Wadler add static- types to Erlang* * with some caveats… Andrew K. Wright , Robert Cartwright,

  34. 2004 Bracha introduces optional types in Pluggable Type Systems Gilad Bracha,

  35. 2004 "In contrast, optional type systems are neither syntactically nor semantically required, and have no effect on the dynamic semantics of the language." Gilad Bracha,

  36. 2006 Erlang's Dialyzer becomes viable Lindahl, Sagonas,

  37. 2004 overcomes many of the issues Marlow and Wadler had Lindahl, Sagonas,

  38. 2006 Gradual typing for functional languages Siek, Taha,

  39. 2008 The design and implementation of typed scheme now called Typed Racket Tobin-Hochstadt, Felleisen,

  40. 2008 inspiration for typed Clojure Tobin-Hochstadt, Felleisen,

  41. 2008 introduces Occurrence typing Tobin-Hochstadt, Felleisen,

  42. (: flexible-length (-> (U String (Listof Any)) Integer)) (define (flexible-length str-or-lst) (if (string? str-or-lst) (string-length str-or-lst) (length str-or-lst)))

  43. state of the art

  44. Dialyzer for Erlang

  45. Typed Racket

  46. Typed Clojure

  47. Dart

  48. Dialyzer at Basho

  49. we write a distributed database in Erlang: Riak

  50. correctness and fault-tolerance are import

  51. bugs are inevitable

  52. sometimes embarrassing

  53. avoid preventable bugs

  54. we use Dialyzer for this

  55. recently hooked it up with CI

  56. takeaways

  57. tl;dr

  58. several modern functional languages have optional type systems

  59. they are mature enough to be useful

  60. they find real bugs

  61. and improve documentation

  62. with some work, you can integrate them into your CI system

  63. Questions? @reiddraper

Recommend


More recommend