how not to design a scripting language
play

How not to Design a Scripting Language Department of Computer - PowerPoint PPT Presentation

How not to Design a Scripting Language Paul Biggar How not to Design a Scripting Language Department of Computer Science and Statistics Trinity College Dublin StackOverflow London, 28th October, 2009 Paul Biggar Department of Computer Science


  1. How not to Design a Scripting Language Paul Biggar How not to Design a Scripting Language Department of Computer Science and Statistics Trinity College Dublin StackOverflow London, 28th October, 2009 Paul Biggar Department of Computer Science and Statistics Trinity College Dublin StackOverflow London, 28th October, 2009 How not to Design a Scripting Language Paul Biggar

  2. About me About me • PhD candidate, Trinity College Dublin 1. means I just • Topic: Compilers, optimizations, scripting languages. submitted 2. So that’s what this • PhD candidate, Trinity College Dublin talk is about • Topic: Compilers, optimizations, scripting languages. How not to Design a Scripting Language Paul Biggar

  3. About me About me • PhD candidate, Trinity College Dublin 1. means I just • Topic: Compilers, optimizations, scripting languages. submitted 2. So that’s what this PhD Dissertation • PhD candidate, Trinity College Dublin talk is about Design and Implementation of an Ahead-of-time PHP Compiler 3. Not much PHP • Topic: Compilers, optimizations, scripting languages. phc (http://phpcompiler.org) PhD Dissertation Design and Implementation of an Ahead-of-time PHP Compiler phc (http://phpcompiler.org) How not to Design a Scripting Language Paul Biggar

  4. How not to design a scripting language How not to design a scripting language 1. really, this is a talk • Compilers about compilers • Scripting Languages and scripting languages • Compilers • Scripting Languages How not to Design a Scripting Language Paul Biggar

  5. How not to design a scripting language How not to design a scripting language • Compilers 1. Thats whats in the • Scripting Languages back of my head all • Speed the time • Compilers • Scripting Languages • Speed How not to Design a Scripting Language Paul Biggar

  6. What is a scripting language? 1. well, no-one What is a scripting language? • Javascript actually has a • Lua • Perl good definition of • Javascript • PHP scripting language! • Lua • Python 2. I’m not talking • Ruby • Perl about Bash or Powershell or VB, • PHP or some little • Python language you wrote last week • Ruby How not to Design a Scripting Language Paul Biggar

  7. 1. well, no-one What is a scripting language? actually has a What is a scripting language? • Javascript good definition of • Lua • Perl scripting language! • Javascript • PHP 2. I’m not talking • Lua • Python about Bash or • Ruby • Perl Powershell or VB, or some little • PHP Common Features: language you • Dynamic typing • Python wrote last week • Duck typing 3. exposing their • Interpreted by default • Ruby • FFI via C API internals Common Features: • Dynamic typing • Duck typing • Interpreted by default • FFI via C API How not to Design a Scripting Language Paul Biggar

  8. Language implementation Language implementation 1. Reads one line at • Interpreters: Easy, portable a time (kinda) 2. hence used in many scripting • Interpreters: Easy, portable langs How not to Design a Scripting Language Paul Biggar

  9. Language implementation Language implementation 1. Converts source • Interpreters: Easy, portable code into machine • Compilers: Not too hard, sometimes portable, code programs optimizations (kinda) 2. Lots of time to • Interpreters: Easy, portable optimize • Compilers: Not too hard, sometimes portable, optimizations How not to Design a Scripting Language Paul Biggar

  10. Language implementation Language implementation 1. 2 months, Joel, • Interpreters: Easy, portable Dragon • Compilers: Not too hard, sometimes portable, 2. For intermediate optimizations and advanced, NOT THE DRAGON BOOK there are also • Interpreters: Easy, portable Engineering a Compiler by Cooper/Torczon much better books Modern Compiler Implementation in X by Appel • Compilers: Not too hard, sometimes portable, optimizations NOT THE DRAGON BOOK Engineering a Compiler by Cooper/Torczon Modern Compiler Implementation in X by Appel How not to Design a Scripting Language Paul Biggar

  11. Language implementation Language implementation 1. Amazing optimizations; • Interpreters: Easy, portable Hotspot; dispatch, • Compilers: Not too hard, sometimes portable, optimizations exceptions and • Just-in-time compilers: Very difficult, unportable, fast arithmetic interpreter . • Interpreters: Easy, portable 2. Shockingly difficult to write • Compilers: Not too hard, sometimes portable, optimizations • Just-in-time compilers: Very difficult, unportable, fast interpreter . How not to Design a Scripting Language Paul Biggar

  12. What’s right with scripting languages? What’s right with scripting languages? 1. dont dwell here - I’m not here to convince you 2. the bad things dont touch these How not to Design a Scripting Language Paul Biggar

  13. What’s right with scripting languages? What’s right with scripting languages? 1. dont dwell here - I’m not here to 1 Elegant and well designed, convince you 2. the bad things dont touch these 3. Python, Ruby; JS 1 Elegant and well designed, too in a certain way How not to Design a Scripting Language Paul Biggar

  14. What’s right with scripting languages? What’s right with scripting languages? 1. dont dwell here - I’m not here to 1 Elegant and well designed, convince you 2 High level of abstraction, 2. the bad things dont touch these 3. get things done, as 1 Elegant and well designed, Joel would say 2 High level of abstraction, How not to Design a Scripting Language Paul Biggar

  15. What’s right with scripting languages? 1. dont dwell here - What’s right with scripting languages? I’m not here to convince you 2. the bad things dont 1 Elegant and well designed, touch these 2 High level of abstraction, 3. avoids many 3 Dynamic typing (and duck typing). problems inherent in Java, C# and 1 Elegant and well designed, C++: verbosity, 2 High level of abstraction, type systems 3 Dynamic typing (and duck typing). How not to Design a Scripting Language Paul Biggar

  16. What’s wrong with scripting languages? What’s wrong with scripting languages? Symptoms: Speed, Portability 1. portable to .Net, JVM, etc? 2. not fast means you Symptoms: Speed, Portability cant use it as much How not to Design a Scripting Language Paul Biggar

  17. What’s wrong with scripting languages? What’s wrong with scripting languages? Symptoms: Speed, Portability 1. portable to .Net, Problem: Language designed for interpreters JVM, etc? 2. not fast means you Symptoms: Speed, Portability • Run-time source code execution cant use it as much Problem: Language designed for interpreters • Run-time source code execution How not to Design a Scripting Language Paul Biggar

  18. What’s wrong with scripting languages? What’s wrong with scripting languages? Symptoms: Speed, Portability 1. portable to .Net, JVM, etc? Problem: Language designed for one specific interpreter 2. not fast means you Symptoms: Speed, Portability • Run-time source code execution cant use it as much • Foreign Function Interface Problem: Language designed for one specific interpreter • Run-time source code execution • Foreign Function Interface How not to Design a Scripting Language Paul Biggar

  19. FFI FFI 1. define FFI FFI 2. glue code in C; wrap things in python data Foreign Function Interface based on CPython interpreter structures; expose • Access to C libraries interpreter • Script C applications using Python scripts internals • Rewrite hot code in C Foreign Function Interface based on CPython interpreter 3. Works for all except JS - I’m • Access to C libraries using Python as example • Script C applications using Python scripts • Rewrite hot code in C How not to Design a Scripting Language Paul Biggar

  20. FFI FFI (good) implications FFI (good) implications • Libraries not that slow • Can break out of Python for slow code. • Libraries not that slow • Can break out of Python for slow code. How not to Design a Scripting Language Paul Biggar

  21. FFI FFI (bad) implications FFI (bad) implications 1. nice things about • Language is allowed to be slow python are lost • Must break out of Python for speed. (high level, elegant • Language is allowed to be slow • Must break out of Python for speed. How not to Design a Scripting Language Paul Biggar

  22. FFI FFI (worse) implications FFI (worse) implications 1. you cant change • Legacy issues the interpreter much - it cant get faster • Legacy issues How not to Design a Scripting Language Paul Biggar

  23. FFI FFI (worse) implications FFI (worse) implications 1. Jython, IronPython, PyPy, cant use the same code • Legacy issues 2. cant even • Reimplementations reimplement own language 3. by constrast, look • Legacy issues at JS • Reimplementations How not to Design a Scripting Language Paul Biggar

  24. FFI FFI solution 1. rule for life, really FFI solution 2. like pyrex, ctypes, Don’t expose yourself! etc • Importing functions into Python with a Domain Specific 3. no implementation Language is good specific code at all Don’t expose yourself! 4. import functions directly, and • Importing functions into Python with a Domain Specific access them from Language is good within Python without a line of C 5. Ruby libFFI How not to Design a Scripting Language Paul Biggar

Recommend


More recommend