Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dan Callahan - My Python's a little Rust-y

Dan Callahan - My Python's a little Rust-y

Rust is a new systems programming language from Mozilla that combines strong compile-time correctness guarantees with fast performance... and it plays nice with ctypes! Come learn how you can call Rust functions from Python code and finally say goodbye to hacking C!


PyCon 2015

April 18, 2015

More Decks by PyCon 2015

Other Decks in Programming


  1. My Python’s a Little Rusty Dan Callahan · [email protected] ·

  2. The Big Lie “Python’s fast enough, and I can always

    write a C extension.” But it’s not, and we never do.
  3. Why don’t we write C? 1. Other people did it

    for us.
  4. Lines of C/C++ in Projects Project # Lines % CPython

    3.5.0a2 399,387 43% NumPy 1.9.2 166,034 62% Pillow 2.7.0 22,669 52% MarkupSafe 0.23 178 21%
  5. We’re standing on their shoulders And so are they.

  6. 2. Writing C is scary.

  7. Memory management is hard. Much like the video at youtube.com/watch?v=718fskG2n34

    C has no safety belts.
  8. Heartbleed Ghost CVE-2015-0080 I’m not smarter than the glibc or

    openssl devs.
  9. But what if you need to?

  10. The Dream C’s Performance, Portability, and Embeddability. With guaranteed safety.

  11. Rust.

  12. Stack vs. Heap

  13. Stack Heap Fast but tiny Slow but huge Function locals

    Globals Managed by CPU Unmanaged Only small values of known, fixed size can go on the stack. Growable things like vectors must go on the heap.
  14. Managed vs unmanaged

  15. None
  16. None
  17. None
  18. None
  19. Ownership

  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. Enforced Statically at Compile Time No dangling pointers No use

    after free vulnerabilities No pointer arithmetic No null pointer dereferencing This is a “Zero-Cost Abstraction.”
  37. Mutability Demos!

  38. None
  39. None
  40. Python FFI Demos!

  41. Learn More rust-lang.org

  42. Questions? @callahad [email protected] github.com/callahad/pycon2015-rust rust-lang.org