how how thinking thinking in in python made me a better
play

How How Thinking Thinking in in Python Made Me a Better Python - PowerPoint PPT Presentation

How How Thinking Thinking in in Python Made Me a Better Python Made Me a Better Soware Engineer Soware Engineer EuroPython 2019 Johnny Dude bit.ly/ThinkPy Hi, I'm Johnny Dude Hi, I'm Johnny Dude Soware Engineer at TogaNetworks


  1. void f(Object obj) // pass by value void f(Object& obj) // pass by reference void f(Object* obj) // pass by raw pointer void f(Object&& obj) // pass by rvalue void f(shared_ptr<Object> obj) // pass by shared pointer void f(unique_ptr<Object> obj) // pass by unique pointer void f(shared_ptr<Object> or unique_ptr<Object> obj) // ?? void f(const Object* obj) // object is immutable void f(Object* const obj) // pointer is immutable void f(const Object* const obj) // both are immutable void f(Object const* obj) // what is immutable?

  2. void f ( shared_ptr < Object >& obj ) // pass shared pointer // by reference void f(Object obj) // pass by value void f(Object& obj) // pass by reference void f(Object* obj) // pass by raw pointer void f(Object&& obj) // pass by rvalue void f(shared_ptr<Object> obj) // pass by shared pointer void f(unique_ptr<Object> obj) // pass by unique pointer void f(shared_ptr<Object> or unique_ptr<Object> obj) // ?? void f(const Object* obj) // object is immutable void f(Object* const obj) // pointer is immutable void f(const Object* const obj) // both are immutable void f(Object const* obj) // what is immutable?

  3. We can use shared pointers everywhere But, we cannot stop thinking about...

  4. Type Hints Type Hints

  5. Do we realy want to define types and structures before understanding the problem and the solution?

  6. Constantly task switching between: Coding and Type-defining

  7. How many bits would I like this integer to have?

  8. What happens when you are wrong?

  9. Lets just use int, and deal with it later.

  10. Prototyping Prototyping

  11. Prototype is a model built to test a concept, and to be learned from

  12. You write it once, gaining experience in both understanding the problem, and understanding a solution

  13. You write it again, with less things to worry about and attention to finer details

  14. Improved Readability Improved Maintainability Fewer Bugs

  15. Coding Prototyping Coding

  16. Coding Future Tasks Prototyping Coding Future Tasks

  17. Some things you can do only in Python

  18. Use a dictionary Define a function

  19. Think in the language you write

  20. Handle type checking, seperately

  21. Along with many other reasons.

  22. c++ Coding Future Tasks Python c++ Coding Future Tasks Prototyping An empirical comparison of c, c++, java, perl, python, ...

  23. How much of the speedup do we get from thinking faster?

  24. My Experiment My Experiment

  25. +--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+ |S | |Sooooooooooooooooooo | + +--+--+--+--+ + +--+ + + +--+--+--+--+ + o+--+ + | | | | | | | | | | ooo | | +--+ + + + +--+--+ + + +--+ + + + +--+--+o + + | | | | | | | | | | oooooo | | + +--+ +--+--+ +--+--+ + + +--+ +--+--+ o+--+--+ + | | | | | | | | | oooo| | +--+ +--+--+ +--+ + +--+ +--+ +--+--+ o+--+ +--+--+ | | | | | | ooo | | + +--+ +--+--+ +--+--+ + + +--+ +--+--+o +--+--+ + | |E | | |E | +--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+

  26. 1 # Python 2 # c++ 3 # Python 4 # Python 5 # c++

  27. 1 # Python 42 2 # c++ 3 151 # Python 22 4 # Python 14 5 # c++ 30 Work Time in Minutes

  28. #1 74 Python 42 108 #2 c++ 151 #3 54 Python 22 #4 50 Python 14 #5 64 c++ 30 Work Time in Minutes Source Lines of Code Excluding: comment, empty lines, bracelets

  29. #4 50 Python 14 #5 64 c++ 30 Work Time in Minutes Source Lines of Code Excluding: comment, empty lines, bracelets

  30. Both version have exactly the same Algorithm 50 Data Types 14 Funtions 64 Names 30 Work Time in Minutes Source Lines of Code Excluding: comment, empty lines, bracelets

  31. Both version have exactly the same Algorithm 50 Data Types 14 Funtions 64 Names 30 28 excluding extra time for typing Work Time in Minutes Source Lines of Code Excluding: comment, empty lines, bracelets

  32. set<Point> calc_path(map<Point, Point> prevs, Point point) { set<Point> results; point = prevs[point]; while (prevs.find(point) != prevs.end()) { results.insert(point); point = prevs[point]; } return results; } auto points = calc_path(prevs, end_point); def calc_path(prevs, point): point = prevs[point] while point in prevs: yield point point = prevs[point] points = set(calc_path(prevs, end_point))

  33. Why? Why?

  34. What was I Thinking About?

  35. Experiment, Experiment, it's fun it's fun

  36. #1 74 Python 42 108 #2 c++ 151 #3 54 Python 22 #4 50 Python 14 #5 64 c++ 30 Work Time in Minutes Source Lines of Code Excluding: comment, empty lines, bracelets

  37. Summary Summary Immediate Feedback Standard Representation & API Composability Prototype in Python

  38. Summary Summary Immediate Feedback Standard Representation & API Composability Prototype in Python

  39. Summary Summary Immediate Feedback Standard Representation & API Composability Prototype in Python

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