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

You CANt teach an old dog new tricks

You CANt teach an old dog new tricks

Python has been around for 3 decades. A moment of silence as we let that sink in...

Since Python is such an "old" language, one doesn't expect it to have certain cool features that "modern" languages have. For instance, types baked into the language.

Well, this was the case a couple of years ago but this has changed. A lot of modern languages have "types" baked into the language. Some developers say having a good type system is as good as having the language writing tests for you (I totally disagree).

For my session, I will be exploring the type system of python. I'll go through the available tools, and share snippets on how types can make one write more maintainable and safer code.

Bd5b8981a308c94b642befb656d8cf8f?s=128

Michael Bukachi

May 07, 2022
Tweet

More Decks by Michael Bukachi

Other Decks in Programming

Transcript

  1. you CANT TEACH AN OLD DOG NEW TRICKS By Michael

    Bukachi
  2. Tech Lead at Marketforce Dancer Community & Open Source Enthusiast

  3. Python is old!

  4. Javascript - 4th December 1995 - 25 years C -

    1972 - 49 years C++ - 1985 - 36 years Java - 23rd May 1995 - 26 years Python - 20th February 1991 - 30 years Ruby - 1995 - 26 years Rust - 7th July , 2010 - 11 years GoLang - 10th November , 2009 - 12 years C# - 2000 -21 years Dart - 10th October, 2011 - 10 years Elixir - 2011 - 10 years Erlang - 1986 - 35 years Kotlin - 22nd July, 2011 - 10 years PHP - 8th June, 1995 - 26 years
  5. 30 years VHS Yellow Pages Neymar was born Most of

    you weren’t born yet
  6. “I might be old but I’m not dead yet” ~

    John Liebing
  7. Is python a modern programming language?

  8. …Modern programming languages are developed to take the full advantages

    of modern computer hardware (Multi-core CPU, GPU, TPU), Mobile devices, large-set of data, fast networking etc.
  9. In a nutshell • Concise and terse code (less boilerplate)

    • Built-in support for concurrency • Null pointer safety • Type Inference • Much simpler feature set • Low cognitive load • Blend the best features of all programming paradigms
  10. None
  11. “Typing” in python

  12. —unknown “A good type system is as good as having

    the language write tests for you …”
  13. FIRST OF ALL …

  14. Javascript - 4th December 1995 - 25 years C -

    1972 - 49 years C++ - 1985 - 36 years Java - 23rd May 1995 - 26 years Python - 20th February 1991 - 30 years Ruby - 1995 - 26 years Rust - 7th July , 2010 - 11 years GoLang - 10th November , 2009 - 12 years C# - 2000 -21 years Dart - 10th October, 2011 - 10 years Elixir - 2011 - 10 years Erlang - 1986 - 35 years Kotlin - 22nd July, 2011 - 10 years PHP - 8th June, 1995 - 26 years
  15. DOES PYTHON NEED TYPE HINTS? • Mypy - Arguable the

    first, community driven • Pytype - Google • Pyright/Pylance - Microsoft • Pyre - Facebook & Instagram
  16. wHERE IT ALL STARTED? • PEP 484 - Type hints

    • 29th September 2014 • There’s a dedicated `typing` module
  17. The necessity of type hints is directly proportional to the

    size of a codebase.
  18. Show me the code

  19. Show me the code Package a.b.c.d

  20. Show me the code package a.t.l.s

  21. Show me the code

  22. Show me the code What’s the data type for variable

    `obj`?
  23. wHat devs like to do? • Spin up that debugger

    (PDB away!) • Print statement with a combination of type() - (my former favourite!) • …..
  24. Show me the code

  25. Easy peasy, right? Well, ….. yes.

  26. Type hints for dynamic languages is like adding icing to

    a cake
  27. Until recently, type hints in python were used primarily for

    static type analysis i.e • You write your code • You run static type analysis against your code • You identify any issues • Rinse and repeat
  28. Using type hints to validate data • Enter Pydantic (Samuel

    Colvin) • FastAPI •
  29. you can teach an old dog new tricks It’s just

    really difficult
  30. Difficult!

  31. CREDITS: This presentation template was created by Slidesgo, including icons

    by Flaticon, infographics & images by Freepik and illustrations by Stories thanks Questions? @michaelbukachi Please keep this slide for attribution
  32. WE are hiring!!!