Developing large-scale Applications in Python

Similar documents
Developing large-scale Applications in Python

Designing largescale applications. in Python. EuroPython 2013 Florence, Italy. Marc-André Lemburg

Zope and RDBMS. A beginner's guide to working with relational databases from Zope. EuroPython Conference 2007 Vilnius, Lithuania.

Automatic Conference Scheduling with PuLP

Fast Queue Data-Type for Python. Version 3.2

5. Application Layer. Introduction

Applying Code Generation Approach in Fabrique Kirill Kalishev, JetBrains

Introduction to User Stories. CSCI 5828: Foundations of Software Engineering Lecture 05 09/09/2014

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Sitecore E-Commerce Cookbook

ODBC Database Interface for Zope. Version 2.0

X-S Framework Leveraging XML on Servlet Technology

Quick Web Development using JDeveloper 10g

Brief introduction of SocketPro continuous SQL-stream sending and processing system (Part 1: SQLite)

3 Continuous Integration 3. Automated system finding bugs is better than people

Database Developers Forum APEX

DOT NET Syllabus (6 Months)

Why is it Difficult to Find a Good Free Web Host

Ruby on Rails Welcome. Using the exercise files

Seminar report Google App Engine Submitted in partial fulfillment of the requirement for the award of degree Of CSE

BI-09 Using Enterprise Guide Effectively Tom Miron, Systems Seminar Consultants, Madison, WI

CS 575: Software Design

COMP390 (Design &) Implementation

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Add Your Product to Clickbank

Successful Test Automation without Coding. Marc J. Balcer Chief Architect Model Compilers

INTRODUCTION. 2

TU Dresden: A Large-Scale Plone Deployment Case Study

Rocking with Racket. Marc Burns Beatlight Inc

Execution Architecture

Two Phase Commit Protocol. Distributed Systems. Remote Procedure Calls (RPC) Network & Distributed Operating Systems. Network OS.

SOA Distilled. Udi Dahan The Software Simplist..NET Development Expert & SOA Specialist Microsoft Solutions Architect MVP

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

J2EE Interview Questions

Software Architecture With ColdFusion: Design Patterns and Beyond Topics Outline Prepared by Simon Horwith for CFUnderground 6

Beyond Query/400: Leap into Business Intelligence with DB2 Web Query

Microservice Splitting the Monolith. Software Engineering II Sharif University of Technology MohammadAmin Fazli

General mapp Solutions FAQ

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Welcome to Python! If you re the type of person who wants to know

UNITE 2003 Technology Conference

Android App Development for Beginners

CS 111. Operating Systems Peter Reiher

Oracle Applications Cloud User Experience Strategy & Roadmap

Tzunami Deployer Lotus Notes Exporter Guide

EG 4.1. PC-SAS users. for. I C T EG 4.1 for PC-SAS Users. Thursday - May 7 th, 2009

Lecture 4: Design Concepts For Responsibility- Driven Design Kenneth M. Anderson January 20, 2005

Science-as-a-Service

MuseKnowledge Source Package Building

Incident Response Tools

Hello everyone, how are you enjoying the conference so far? Excellent!

Test Your XAML-based Windows Store Apps with Visual Studio 2013 Benjamin Day

Oracle Forms and Oracle APEX The Odd Couple

Seven proven ways to ruin your Test Automation

Test Driven Development TDD

1. I NEED TO HAVE MULTIPLE VERSIONS OF VISUAL STUDIO INSTALLED IF I M MAINTAINING APPLICATIONS THAT RUN ON MORE THAN ONE VERSION OF THE.

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Case study on PhoneGap / Apache Cordova

Software Design COSC 4353/6353 D R. R A J S I N G H

Manipulating Web Application Interfaces a New Approach to Input Validation Testing. AppSec DC Nov 13, The OWASP Foundation

COMP390 (Design &) Implementation

Write for your audience

Web Host. Choosing a. for Your WordPress Site. What is web hosting, and why do you need it?

Digital Marketing Manager, Marketing Manager, Agency Owner. Bachelors in Marketing, Advertising, Communications, or equivalent experience

What s new in SketchUp Pro?

Cloud Programming. Programming Environment Oct 29, 2015 Osamu Tatebe

How Can a Tester Cope With the Fast Paced Iterative/Incremental Process?

Small is Beautiful Building a flexible software factory using small DSLs and Small Models

7 Sure- fire Ways to Ruin Your Test Automation

Keyword Driven Test Automation Framework for Web Based Applications

MAPLOGIC CORPORATION. GIS Software Solutions. Getting Started. With MapLogic Layout Manager

Going SOA with CA Plex and Websydian

Page design and working with frames

A Better MVC. 300 line view controllers or bust. Dave A guy who thinks too deeply about stuff

REPORT MICROSOFT PATTERNS AND PRACTICES

Design Principles that Make the Difference

CO Java EE 7: Back-End Server Application Development

Creating An Online Survey Using Zope & QSurvey: Introduction. A Step by Step Introduction Download this Document as PDF. Zope

Driven by a passion to develop our customers, SuperOffice has become one of Europes leading providers of CRM solutions.

Exsys RuleBook Selector Tutorial. Copyright 2004 EXSYS Inc. All right reserved. Printed in the United States of America.

Contractors Guide to Search Engine Optimization

Website Design Article by Michele Jennings, Netmajic, Inc.

Computing and compilers

UNITE 2006 Technology Conference

Analysis of the Test Driven Development by Example


Effective Support for 512 byte Emulation in 4 K Sector Drives. The Customer Viewpoint.

Mail & Deploy Reference Manual. Version 2.0.5

Chapter 2.6: Testing and running a solution

Le nouveau Morfik est arrivé (The new Morfik has arrived)

NordiaSoft SCA Architect 2016

Igniting QuantLib on a Zeppelin

Java Enterprise Edition

Our initial reason for creating a CMS was for accessibility reasons.

My malloc: mylloc and mhysa. Johan Montelius HT2016

CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. CaptainCasa & Java Server Faces

Meet our Example Buyer Persona Adele Revella, CEO

Telerik Training for Mercury 3

Semester 2, 2018: Lab 1

Lifehack #1 - Automating Twitter Growth without Being Blocked by Twitter

Transcription:

Developing large-scale Applications in Python Lessons learned from 10 years of Python Application Design EuroPython Conference 2005 Göteborg, Sweden Marc-André Lemburg EGENIX.COM Software GmbH Germany

Speaker Introduction: Marc-André Lemburg Large-Scale Applications in Python CEO egenix.com and Consultant More than 20 years software experience Diploma in Mathematics Expert in Python, OOP, Web Technologies and Unicode Python Core Developer Python Software Foundation Board Member (2002-04) Contact: mal@egenix.com egenix.com Software GmbH, Germany Founded in 2000 Core business: Consulting: helping companies write successful Python software Product design: professional quality Python/Zope developer tools (mxodbc, mxdatetime, mxtexttools, etc.) International customer base 2

Introduction 1. Introduction 2. Application Design 3. At work... 4. Discussion 3

Python2EE: Large-scale applications What is considered large-scale in Python? Large-Scale Applications in Python Server application: >30 thousand lines of Python code Client application: >10 thousand lines of Python code Third-Party code: >10 thousand lines of code Typically a mix of Python code and C extensions Examples: Zope / Plone egenix Application Server egenix projects: e.g. Web Service Application Server, XML Database, ASP Trading System 4

Snake bites: Why write large-scale applications in Python? Highly efficient small teams can scale up against large companies very competitive turn-around times small investments can result in high gains Very flexible allows rapid design, refactoring and rollout highly adaptive to new requirements and environments no lock-in Time-to-market develop in weeks rather than months 5

Application Design 1. Introduction 2. Application Design 3. At work... 4. Discussion 6

Path to success: Application Design Large-Scale Applications in Python Python makes it very easy to write complex applications with very little code It s easy to create bad designs fast Rewriting code is fast as well Application design becomes the most important factor in Python projects Here s a cookbook approach to the problem 7

Breaking it down: The Design Concept Zen approach to application design Large-Scale Applications in Python Keep things as simple as possible, but not simpler (KISS). There s beauty in design. Before doing things twice, think twice. If things start to pile up, management is needed. If management doesn t help, decomposition is needed. Structured approach to application design Divide et Divide et Impera (divide and conquer) Lots and lots of experience 8

First step: Choose a suitable application model Large-Scale Applications in Python Client-Server Client application / Server application Web client / Server application Multi-threaded stand-alone Stand-alone GUI application Single process GUI Client Server Event Handler Business Logic etc. Command-line application Batch job application Input Processor Output 9

Bytes in action: Identify the processing model Large-Scale Applications in Python Identify the processing scheme: Single process Multiple processes Multiple threads Asynchronous processing A mix of the above Identify the process/thread boundaries: Which components (need to) share the same object space? Where is state kept? What defines an application instance? Process 1 Interface Logic Process 2 Server Logic Application Interface Logic Logic Process 3 Storage Server Logic Logic Application Interface Logic Logic Storage Server Logic Logic Application Logic Storage Logic 10

Looking closer: Application layers Large-Scale Applications in Python Every application can be divided into layers of functionality defined by the flow of data through the application Top layer: interface to the outside world Intermediate layers: administration and processing Bottom layer: data storage Layers are usually easy to identify given the application model but often hard to design Application Interface Logic Administration Logic Application Logic Storage Logic 11

Vertical design: Find the right application layer model GUI / Application Logic / Storage Logic Network / Apache / SCGI / Server Logic / Application Logic / Storage Logic File I/O / Application Logic / Storage Logic Client Web Browser Server Interface Logic Server Logic Application Logic Storage Logic Custom model 12

Example: Web Client + Server Application Large-Scale Applications in Python Setup: Client is a standard web-browser Server needs to take a lot of load and will have to do all the calculation work Server needs to be fail-safe Solution: Multiple process model Application server layers Client Web Browser Server Process Interface Logic Server Logic Application Logic Storage Logic Client Web Browser Apache Web Server Multiple Process Broker SCGI Server Process Interface Logic Server Logic Application Logic Storage Logic Client Web Browser Server Process Interface Logic Server Logic Application Logic Storage Logic Database 13

The next step: Breaking layers into smaller pieces Layers provide a data driven separation of functionality Problem: The level of complexity is usually too high to implement these in one piece of code Solution: build layers using a set of loosely coupled components 14

Plug & play: Component design Components should encapsulate higher level concepts within the application, e.g. provide the database interface implement the user management implement the session management provide caching facilities interface to external data sources provide error handling facilities enable logging management etc. 15

On the loose: Advantages of components Large-Scale Applications in Python Components provide independent building blocks for the application They should be easily replaceable to adapt the application to new requirements, e.g. porting the application to a new database backend, using a new authentication mechanism, etc. If implemented correctly, they will allow switching to different processing model should the need arise Loose coupling of the components makes it possible to refine the overall application design, refactor parts of the layer logic or add new layers without having to rewrite large parts of the application code 16

Hitchhiker s guide to: Component implementation Each component is represented by a component object One system component object (representing the application instance): All component objects are created and managed by the system object Components can access each other through the system object (circular references!) Component interfaces must be simple and high-level enough to allow for loose coupling Internal parts of the components are never accessed directly, only via the component interface Note: Component objects should never keep state across requests (ideally, they should be thread-safe) 17

Horizontal design: Split the layers into components General approach: One system component that manages the application instance At least one component per layer Process Boundary (Multiple Process Model) Interface Layer Application Instance Layer RequestComponent ResponseComponent SystemComponent Server Layer SessionComponent UserComponent Request Context Application Layer Object HandlerComponent PresentationComponent Data management: Global data is only used for configuration purposes ImportExportComponent Storage Layer DatabaseComponent Components don t store per-request state! ValidationComponent FilesystemComponent ErrorComponent LogComponent DebugComponent Per-request global data is stored and passed around via Request Context Objects 18

The big picture: Layers and components Large-Scale Applications in Python Process Boundary (Multiple Process Model) Interface Layer Application Instance Layer RequestComponent ResponseComponent SystemComponent Server Layer SessionComponent Application Layer HandlerComponent ImportExportComponent Storage Layer UserComponent PresentationComponent ValidationComponent ErrorComponent LogComponent All Component Objects are connected to the SystemComponent object DatabaseComponent FilesystemComponent DebugComponent 19

Breaking down complexity: Management objects Management objects help simplify component object implementations work on or with groups of data/task objects: Data objects Task objects interaction with multiple objects I/O on collections of objects delegating work to other management objects interfacing to component objects etc. The distinction between management objects and component objects is not always clear If in doubt, use a component object that delegates work to a management object 20

Drill-down: Management objects at work Large-Scale Applications in Python SystemComponent Application Layer HandlerComponent TaskManager Management Object Object Access Path PresentationComponent ValidationComponent Edit Store Export Data/Task Object ImportExportComponent ImportManager ExportManager CSVImport XMLImport XLSImport CSVExport XMLExport XLSExport 21

Managing responsibilities: Who s in charge? Use component objects to represent logical units / concepts within the application without going into too much detail Use management objects to work on collections of data/task objects to simplify component implementations to avoid direct interfacing between the data/task objects Large-Scale Applications in Python Never mix responsibilities 22

Reality check: All this sounds familiar Application design is in many ways like structuring a company: Large-Scale Applications in Python Divisions need to be set up (component objects) Responsibilities need to be defined (management vs. data/task objects) Processes need to be defined (component/management object APIs) Applications work in many ways like companies: Customer interaction (user interface) Information flow (application interface) Decision process (business logic) Accounting and data keeping (storage interface) 23

Intermezzo: There s beauty in design Large-Scale Applications in Python 24

At work... 1. Introduction 2. Application Design 3. At work... 4. Discussion 25

Before you start: Structuring your modules First some notes on the import statement: Keep import dependencies low; avoid from import * Large-Scale Applications in Python Always use absolute import paths (defeats pickle problems among other things) Always layout your application modules using Python packages Import loops can be nasty; import on demand can sometimes help 26

Some guidelines: Finding the right package structure Use one module per management/component class group of object classes managed by the same management class keep modules small; if in doubt, split at class boundaries Group components and associated management modules in Python packages (directories) Use the application model as basis for the package layout 27

Finding the right mix: Data, classes and methods Use data objects for data encapsulation instead of simple types (tuples, lists, dictionaries, etc.) Use methods even for simple tasks but don t make them too simple Use method groups for more complex tasks e.g. to implement a storage query interface Use mix-in classes if method groups can be deployed in more than class context If you need to write the same logic twice, think about creating a mix-in class to encapsulate it, or put it on a base class Avoid using mix-in classes if only one class makes use of them 28

Make mistakes and learn from them: Refactoring If an implementation gets too complicated, sit down and reconsider the design often enough a small change in the way objects interact can do wonders Be daring when it comes to rewriting larger parts of code! It sometimes takes more than just a few changes to get a design right It is often faster to implement a good design from scratch, than trying to fix a broken one 29

Often forgotten: Documentation Always document the code that you write! Use doc-strings, inline comments and block logical units using empty lines doc-strings represent your method s contracts with the outside world Document the intent of the methods, classes and logical code units not only their interface Use descriptive identifier names even if they take longer to type 30

Five minutes that make a difference: Quality Assurance Use extreme programming techniques whenever possible: Always read the code top to bottom after you have made changes or added something new to it Try to follow the flow of information in your mind (before actually running the code) Write unit tests for the code and/or test it until everything works as advertised in the doc-strings Typos can easily go unnoticed in Python: use the editor s auto-completion function as often as possible Use tools like PyChecker to find hidden typos and possibly bugs Always test code before committing it to the software repository 31

Discussion 1. Introduction 2. Application Design 3. At work... 4. Discussion 32

Developing large-scale applications in Python Questions Large-Scale Applications in Python Has anyone worked on large-scale Python applications? What tools / features are (still) missing in the tool chain? Would you be prepared to pay for components or frameworks? 33

And finally... Thank you for your time. 34

Contact egenix.com Software, Skills and Services GmbH Marc-André Lemburg Pastor-Löh-Str. 48 D-40764 Langenfeld Germany email: mal@egenix.com Phone: +49 211 9304112 Fax: +49 211 3005250 Web: http://www.egenix.com/ 35