how not to design a scripting language
play

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

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


  1. Introduction How not to design a scripting language How not to Design a Scripting Language 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. Introduction How not to design a scripting language About me • PhD candidate, Trinity College Dublin • Topic: Compilers, optimizations, scripting languages. How not to Design a Scripting Language Paul Biggar

  3. Introduction How not to design a scripting language About me • PhD candidate, Trinity College Dublin • Topic: Compilers, optimizations, scripting languages. 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. Introduction How not to design a scripting language How not to design a scripting language • Compilers • Scripting Languages How not to Design a Scripting Language Paul Biggar

  5. Introduction How not to design a scripting language How not to design a scripting language • Compilers • Scripting Languages • Speed How not to Design a Scripting Language Paul Biggar

  6. Introduction How not to design a scripting language What is a scripting language? • Javascript • Lua • Perl • PHP • Python • Ruby How not to Design a Scripting Language Paul Biggar

  7. Introduction How not to design a scripting language What is a scripting language? • Javascript • Lua • Perl • PHP • Python • Ruby Common Features: • Dynamic typing • Duck typing • Interpreted by default • FFI via C API How not to Design a Scripting Language Paul Biggar

  8. Introduction How not to design a scripting language Language implementation • Interpreters: Easy, portable How not to Design a Scripting Language Paul Biggar

  9. Introduction How not to design a scripting language Language implementation • Interpreters: Easy, portable • Compilers: Not too hard, sometimes portable, optimizations How not to Design a Scripting Language Paul Biggar

  10. Introduction How not to design a scripting language Language implementation • Interpreters: Easy, portable • 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. Introduction How not to design a scripting language Language implementation • Interpreters: Easy, portable • 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. Introduction How not to design a scripting language What’s right with scripting languages? How not to Design a Scripting Language Paul Biggar

  13. Introduction How not to design a scripting language What’s right with scripting languages? 1 Elegant and well designed, How not to Design a Scripting Language Paul Biggar

  14. Introduction How not to design a scripting language What’s right with scripting languages? 1 Elegant and well designed, 2 High level of abstraction, How not to Design a Scripting Language Paul Biggar

  15. Introduction How not to design a scripting language What’s right with scripting languages? 1 Elegant and well designed, 2 High level of abstraction, 3 Dynamic typing (and duck typing). How not to Design a Scripting Language Paul Biggar

  16. Introduction How not to design a scripting language What’s wrong with scripting languages? Symptoms: Speed, Portability How not to Design a Scripting Language Paul Biggar

  17. Introduction How not to design a scripting language What’s wrong with scripting languages? Symptoms: Speed, Portability Problem: Language designed for interpreters • Run-time source code execution How not to Design a Scripting Language Paul Biggar

  18. Introduction How not to design a scripting language What’s wrong with scripting languages? Symptoms: Speed, Portability 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. Introduction How not to design a scripting language FFI FFI Foreign Function Interface based on CPython interpreter • Access to C libraries • Script C applications using Python scripts • Rewrite hot code in C How not to Design a Scripting Language Paul Biggar

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

  21. Introduction How not to design a scripting language FFI FFI (bad) implications • Language is allowed to be slow • Must break out of Python for speed. How not to Design a Scripting Language Paul Biggar

  22. Introduction How not to design a scripting language FFI FFI (worse) implications • Legacy issues How not to Design a Scripting Language Paul Biggar

  23. Introduction How not to design a scripting language FFI FFI (worse) implications • Legacy issues • Reimplementations How not to Design a Scripting Language Paul Biggar

  24. Introduction How not to design a scripting language FFI FFI solution Don’t expose yourself! • Importing functions into Python with a Domain Specific Language is good How not to Design a Scripting Language Paul Biggar

  25. Introduction How not to design a scripting language FFI FFI solution Don’t expose yourself! • Importing functions into Python with a Domain Specific Language is good • Only one way of FFI is better How not to Design a Scripting Language Paul Biggar

  26. Introduction How not to design a scripting language FFI FFI solution Don’t expose yourself! • Importing functions into Python with a Domain Specific Language is good • Only one way of FFI is better • Declarative is best How not to Design a Scripting Language Paul Biggar

  27. Introduction How not to design a scripting language FFI FFI solution Don’t expose yourself! • Importing functions into Python with a Domain Specific Language is good • Only one way of FFI is better • Declarative is best • Any reimplementation can reuse the same libraries without any modifications • CPython itself can change without hassle How not to Design a Scripting Language Paul Biggar

  28. Introduction How not to design a scripting language Compiled and interpreted models Dynamic source code generation • eval and dynamic include / import How not to Design a Scripting Language Paul Biggar

  29. Introduction How not to design a scripting language Compiled and interpreted models Dynamic source code generation • eval and dynamic include / import • meta-programming eval (mysql_read (...)[0]); How not to Design a Scripting Language Paul Biggar

  30. Introduction How not to design a scripting language Compiled and interpreted models Dynamic source code generation • eval and dynamic include / import • meta-programming • .rc files username = "myname" password = "mypass" server = "srv.domain.com" How not to Design a Scripting Language Paul Biggar

  31. Introduction How not to design a scripting language Compiled and interpreted models Dynamic source code generation • eval and dynamic include / import • meta-programming • .rc files • localization $lang = ....; include ("localisation/locale. $lang .php"); How not to Design a Scripting Language Paul Biggar

  32. Introduction How not to design a scripting language Compiled and interpreted models Dynamic source code generation We don’t even know the full program source!! How not to Design a Scripting Language Paul Biggar

  33. Introduction How not to design a scripting language Compiled and interpreted models So they can’t be compiled (ahead-of-time) Downsides: • Must use FFI for speed • Static analysis • Cool optimizations can’t happen How not to Design a Scripting Language Paul Biggar

  34. Introduction How not to design a scripting language Compiled and interpreted models So they can’t be compiled (ahead-of-time) Downsides: • Must use FFI for speed • Static analysis • Cool optimizations can’t happen t = ...; for (i = 0; i < strlen(t); i++) { s[i] = t[i]; } How not to Design a Scripting Language Paul Biggar

  35. Introduction How not to design a scripting language Compiled and interpreted models So they can’t be compiled (ahead-of-time) Downsides: • Must use FFI for speed • Static analysis • Cool optimizations can’t happen t = ...; _temp = strlen(t); for (i = 0; i < _temp; i++) { s[i] = t[i]; } How not to Design a Scripting Language Paul Biggar

  36. Introduction How not to design a scripting language Compiled and interpreted models So they can’t be compiled (ahead-of-time) Downsides: • Must use FFI for speed • Static analysis • Cool optimizations can’t happen alert ($(’li’).get(0).nodeName); How not to Design a Scripting Language Paul Biggar

  37. Introduction How not to design a scripting language Compiled and interpreted models So they can’t be compiled (ahead-of-time) Downsides: • Must use FFI for speed • Static analysis • Cool optimizations can’t happen alert ($(’li’)[0].nodeName); How not to Design a Scripting Language Paul Biggar

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