Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Is Python turning into Java? PyData 2017 Berlin Lightning Talk

153 views

Published on

Lightning talk I held at PyData Berlin 2017. A sarcastic look at Python 3's "Java-esque" features, and how they're actually great for the language.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Is Python turning into Java? PyData 2017 Berlin Lightning Talk

  1. 1. Is Python turning into Java? <SARCASM>… Steffen from TrustYou @tyengineering Lightning talk @ PyData Berlin 2017
  2. 2. Generators FTW function* idMaker() { var index = 0; while (true) yield index++; } You’re welcome, ECMAScript!
  3. 3. Whitespace Indentation if has_too_many_braces: print("hard to read") You’re welcome … uh, CoffeeScript? (Also, RIP CoffeeScript)
  4. 4. from enum import auto, Enum from functools import singledispatch from typing import Any class Things(Enum): kind_of_thing = auto() another_kind = auto() @singledispatch def handle(data: Any): print(f"Dunno what this is: {data}") @handle.register(Things) def handle(data: Things): print(f"Called with a thing! {data}")
  5. 5. It all started with enums … class Things(Enum): kind_of_thing = auto() another_kind = auto() What’s wrong with strings or module-level variables? … Granted, this is nice: >>> list(Things) [<Things.kind_of_thing: 1>, <Things.another_kind: 2>] >>> 1 in Things False >>> Things.kind_of_thing in Things True
  6. 6. Dict’s for data – Python ♥ dictionaries, right?? def summarize_hotel(hotel): print(f"Name: {hotel['name']}") print(f"Name: {hotel['reviews_conut']}") # Uh … what else is in ‘hotel’ anyways? ArgumentParser … ConfigParser … all act as dicts/mappings. As do classes and objects, actually.
  7. 7. Python would never look like this … class Hotel: name: str reviews_count: int score: float Wait, what the … – this is in Python 3.6!!
  8. 8. Well, granted, this is pretty nice …
  9. 9. Single dispatch. Ugh! @singledispatch def handle(data: Any): print(f"Dunno what this is: {data}") @handle.register(Things) def handle_thing(data: Things): print(f"Called with a thing! {data}") handle("stuff") # goes to first handle(Things.kind_of_thing) # goes to second
  10. 10. Wait … Are we not doing duck typing any more?
  11. 11. Well, if it says it’s a duck …
  12. 12. </SARCASM> ● Python 3 is growing up! ● Very useful (optional!) features for … ○ Code that is read more often than written ○ Large projects ● Use Python 3.6!

×