RasperryPi

Multiple inheritance/composability

Act 1: meet the people

  • "Composability"
  • "Compositionality" - unix pipe being the obvious example
  • "Quality"

Act 2: Rising Action

  • a.mro() - method resolution order
  • "The diamond problem" class AB(A, B)
    • order is defined as linear in order of how the base classes are declared in the inheritance
    • in deep inheritance it appears to be a DFS
Cooperative Inheritance
  • use super (duh)
  • but... we have to accept keyword arguments regardless, if we think that they're going to be used as components.
  • but... **kwargs results in terribly ugly code
  • It works, but it still behaves differently than explicit __init__ example
  • If you are going to use multiple inheritance
    • don't omit super() even if your base class is an object
    • don't assume you know the args you will get or what you should pass
  • if you mix .__init__ and super() you're going to have a bad time
Mixins
  • Not meant for instantiation on their own
  • enhance class with independent functionality
  • Not specialisation but collection of functionality
  • like interfaces...
  • Always place mixins 1st
Polymorphism
  • Liskov substitution principle (class S can be substituted T)

Act 3: The Climax

  • lck.django
  • kiddicraft actually invented legos

Q & A

  • Q: what if you have two multiple inheritors that take the same named argument
  • A: It falls apart. Silently. Awesome. Unless you are consuming en route.
  • Q: How do you describe their usage?
  • A: Python3. Wat? Everything I want to use, I define explicitly.

The End Of Object Inheritance & The Beginning Of A New Modularity

Intro

These should be uncontroversial. Believed to be true, and are virtuous (ought to be true)

  1. We use types for nouns
  2. We express ourselves structurally (in code)
    • choose to use visibility etc.
    • could use goto... choose not to
  3. most porgramming is parametric programming (unless you are scientists)
    • behaviour depends on arguments

The rest

class Abstract()
  def Orange()
  def Green() raise NotImplementedError
  def Blue()

class ClientSubclass(Abstract):
  def Green():
    do something

This sucks, because we have to tell our clients about all stages of the implementation. Can't even hide the Orange and Blue methods. Have to annotate "Do not call OrangeMethod() in your implementation. That's dumb.

"Reminds us of American Politics" (butterfly ballot). "If your explaining, you're loosing"

  • Violating premises 1 and 2 to satisfy 3.
  • Stages are nouns. The implementation states are structure! So... let's switch it up.
  • So what's a way that is compatible with our premises to accomplish the same task?
  • Composition ("favor composition over inheritance")
  • Instead of inheriting, we're going to pass one layer into another
  • attributes on self are not what you want... there's a bidirectional communication and it's based on side-effects

Classic Inheritance Model

class Blue(object):

class ImplementedBlue(Blue):
  def BlueMethod(self):

Client

implement one class
ImplementedGreen(Green):
  def __init__(self, blue):
    self._blue = blue
  def GreenMethod(self):
    ...
  • Interfaces overlap, not always disjoint
  • Delegation is explicit
  • In the latter solution, we're not explaining.

Fault Tolerance

  • equally performant... same algorithm complexity. Personal choice?
  • Not fault tolerance of the running system. Fault (In)Tolerance for software architecture. Don't want an error silently passing through.
  • Object Inheritance fails to be fault intolerant.
  • Might get silent state corruption
  • Might get in infinite loop... sometimes
  • Might get perfect behaviour until a year later with when your superclass's library is upgraded

Better to:

  • "Make Illegal States Unrepresentable"
  • "Make Illegal Behavioral Interactions Impossible"
  • Breaking up code
    • break all bidirectional relationships
    • relationships are minimized amoung the resulting pieces
  • You'll define types everywhere: (Interfaces... especially at public API boundaries, Completely abstract classes)
  • classes will start to stick out in your API
  • Constructors will turn into factory functions (just means that your module is responsible for instantiation)
  • modules will transform into collections of types and functions
  • May seem like degenerancy...
  • May wind up with a few very powerful functions
  • Value Types

Back to composability

  • "Anti-Rumsfeldian Software Design"
  • You should write the hard parts not in terms of the what you have, but in terms of what you wish you have
  • Adapters let you fit your modules together
  • "Can't define the translation layer well"
  • Defer until later, because you haven't thought about the problem well enough.
  • Type functions modules, make applications

Q & A

  • zope.iterface - haven't used in python
  • other use of interitance - unplanned reuse ... refactor it or delegate.
  • sometimes passing around objects is overkill - functional? functions are interfaces themselves, sure, do it.

API Design for Library Authors

Good talk, but it was so full that I could not take notes

Python 3.3: Trust Me, It's Better than 2.7

Features

  • io library in C
  • multiple context managers
  • future_builtins map returns an iterator and not a list
  • "new" division (float return on int division)... this is awesome and is about time!
  • numbers

minor features

  • dict views
  • Comparison against diparate types is a TypeError
  • wsgi 1.0.1
  • dict-based configuration for logging
  • super() no longer requires arguments
  • Unified integers
  • __next__() (not so much a feature as a normalization)
  • key-sharing dictionaries (10-20% memory savings)
  • nonlocal
  • extended iterable unpacking - this is super cool
  • first, *rest, = range(5)
    a, *b, c = range(5)
    
  • concurrent.futures
  • def big_calculations(num):
      return num ** 10000000
    
from concurrent import futures
with futures.ProcessPoolExecutor() as executor:
  list(executure.map(...))
  • decimal module implemented in C
  • 30x-80x faster (that's times not percent)
  • __name__ and __qualname__
  • yield from
    • allows generators to be factored out and replaced with a single expression
def factored_out():
  yield 1; yield 2

def refactored_stupid():
  yield 0
  yield from factored_out()
  • The above will become key in asyncronous
  • Added virtualenv to python
  • venv
  • super lightweight

BIGGER features/themes

included traceback
  • exc.__traceback__
  • exception chaining
    • no loss of traceback data when you raise another exception during exception handling
    • explicit exception handling
    • raise NotImplementedError from exc
import lock
  • importing in a thread used to cause a deadlock
  • happened in os modules
  • now threads block until the import completes... circular imports may be partially initialized
__pycache__ directories
  • All .pyc files now kept in a __pycache__ directory
  • .pyc filenames contain the interpreter and version number so that different interpreters and version of Python to have .pyc files without overwriting each other
namespace packages
  • All directories with no __init__.py file collect __path__ for an empty module
  • If anything changes above it, it will reclculate the __path__ for the namespace package
functions
  • keyword-only arguments
  • can _only_ call them when you use their name in the function
  • function annotations
    • Can annotate any parameter and the return value with any object
    • Doesn't have to be type specific
def monty_python(a:spam, b:bacom) -> "different":
  pass
signature objects
  • object representation of calls and callable signatures
  • used for dynamic call building (Lover of R will celebrate)
unicode
  • utf-8 is the default encoding for the source code
  • non-ascii identifiers
  • all string literals are Unicode
  • u'' prefix is allowed
  • b'' prefix for bytes
  • '' native string... used ____ONLY_____ when you can guarantee that it will always remain ascii
  • biggest porting hurdle when you have not clearly delineated what is text vs. what are bytes
  • better unicode during execution in 3.3
  • one build will cover any unicode character

Performance

Who’s faster?

  • It's complicated, but...
  • They are about the same at the median.
  • decimal module makes a huge difference for numerical stuff

Loop like a native

  • iteration is everywhere
  • be direct
  • write more abstractions

Speaker claims that this talk is not necessarily for beginners... that it is "fundamental" (well... it turned out to be for beginners)

  • iterable gets to decide what value it produces
  • stdlib has other iterables which are interesting
  • re.finditer()
  • os.walk()
  • sum, min, max will take iterables
  • iterator vs. iterable (analagous to bookmark vs. book)
  • only operation is next()
  • iterator = iter(iterable)
  • making your object iterable
def __iter__(self):
  return iter(self.tasks)
ToDoList
__iter__
all
# generator expression
def done(self)
  return (t for t in self.tasks if t.done)

The SQLAlchemy Session - In Depth

Zzzzzzzzzz

Nassberry pie (lightning talk)

How to make your home NAS with a RaspberryPi

Mark Ransom

  • File Server
  • uPNP Media Server minidlna
  • web server (nginx, django)
  • torrent server (transmission-daemon)
  • ssh server
  • openvpn client (for torrenting)

Most of the above can just be apt-get installed

  • minidlna had to be compiled on the pogoplug
  • config file, just point to media directories
  • transmission-daemon
  • changed download dir and set ip_address to 'IP_ADDRESS' because connecting through open VPN run script on connect
  • another script stops transmission service and saves IP_ADDRESS to settings file
  • transmission-daemon Web interface

Awesome Big Data Algorithms

Room too full to take notes, but essentially Titus went through some cases in gene sequencing where random algorithms which are less expensive can be "good enough" to get the job done. Randomized skip lists was one example, where you can allocate as much memory as you have and get better performance per level.

Functional Programming with Python

Nothing very new here

Raymond Hettinger's keynote

One big cheerleading talk about why/what python has that other languages don't. A few things were interesting, but most things I knew pretty well already. Would be a good talk for the non-believers or not already converted.

Getting started with automated testing

Good job Carl!

Things to make writing tests easier

Ned regex jokes

  • using context managers for testing in 3.x
  • with ShouldRaise():
      # run some test
    
    with ShouldRaise(ValueError):
      # run test
      # catch exception
      # check output (because otherwise it may not be right)
    
  • Testing logging
  • Really? Do we need to? Well, you may reconsider when your app fails at 2am and you don't have enough in the logs to figure out the problem

Mobile Application Testing with Python and Selenium

  • Use Selenium WebDriver (i.e. 2)
  • Has iOS and Android drivers
  • Selenium server could be running in a browser, (or as an app on mobile)
  • Proposed as a standard to WC3.
  • Doesn't always work in a different browser. Tricky.
  • to run on iphone... just need a few more lines to set up the driver.. more complicated than webdriver.browser()
  • For iPhone... runs in XCode only on Mac... big limitiations but... better than nothing
  • Android webdriver requires android SDK and setup is really hard and annoying. It's running in a virtual environment. Emulator is slow.

Limitations

  • 'WebViews'
  • Not a real browser
  • Second class citizes
  • Hard to accurately test
  • Hard to use on real devices
  • Each mobile implementation is different

Native apps

iOS
  • UI Automation
  • js only
  • very limited set of commands
  • no interaction with tests
  • No test interoperability
Android
  • Java tests, compiled and pushed
  • No interaction with tests
Alternatives
  • Recompile app to add 3rd party code
  • various APIs
  • Mixed community and limited help
  • Forced language implementation

Test Reuse

  • Write once, test many times
  • Intro Appium: Selenium for native apps
  • But... it's not ready yet

Location Location Location

  • Julia talking about WeddingLovely, website which tries to connect people with wedding service providers "nearby"
  • Originally started encoding "location" with a long list of US cities that people could pick.
  • string list wasn't all that bad... it got them most of the way there.
  • But we want an omnibox, where people can type in where they are
  • don't need a spatial database. You can use math
  • Could just use a spatial database... will write a lot of SQL in the application
  • GeoDjango for abstration layer for location data

Let Them Configure!

Not a very exciting talk

How Import Works

Brett walked through the entire logic flow of what happens on an import statement.

"Good enough" is good enough!

Totally editorial and preaching to the choir. I wish that I had skipped this talk.

A Crash Course in MongoDB

Not interesting —–



blog comments powered by Disqus

Published

25 March 2013

Category

work

Tags