from java to python

28
groningen.py / 16-01- 2012

Upload: alexandre-gonzalez-rodriguez

Post on 17-Dec-2014

2.648 views

Category:

Technology


5 download

DESCRIPTION

Ivor talk about Java and Python on the first PyGrunn monthly (Jan 2012)

TRANSCRIPT

Page 1: From Java to Python

groningen.py / 16-01-2012

Page 2: From Java to Python

ScheduleSchedule

• Input for Python meetups

• From Java to Python

Page 3: From Java to Python

MeetupsMeetups

• groningen.py (thanks Mark)

• Talk and learn about Python development

• Community

• Regular meetings

Page 4: From Java to Python

What do we need?What do we need?

• A time, space & some drinks

• Subjects / Format

• You!

• Please invite and suggest

Page 5: From Java to Python

How do you use How do you use python?python?

• For how long?

• Web development?

• As main language?

• Framework?

Page 6: From Java to Python

ContentsContents• Any subject you’d like to hear

about?

• Any subject you’d like to talk about?

django 1.4

python 3.0

data migration

performance tuning

web services

Page 7: From Java to Python

Meeting scheduleMeeting schedule

• How often?

• What day of week / time?

Page 8: From Java to Python

Let’s startLet’s start

From Java to Python

Page 9: From Java to Python

Ivor BosloperIvor Bosloper

2010200119951985

using Geodjango

Basic/Assembler C Java Python

Preferred general purpose language:

Page 10: From Java to Python

Java2pyJava2pyDisclaimer: I love Java/JVM

• Typesafe/checked references

• Garbage collection

• Object Oriented

• Huge API

• General purpose

• Security, i18n

• Great debugging (e.g. with stacktraces)

Page 11: From Java to Python

Java2pyJava2pyWhy Python? Productivity!

• Readability

• Pragmatic and language possibilities

• Development cycle

Page 12: From Java to Python

Readability mattersReadability matters

Page 13: From Java to Python

ReadabilityReadability

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); }}

Page 14: From Java to Python

ReadabilityReadability@Entitypublic class Farm { @Id @GeneratedValue private Long id;

private String name;

@ManyToOne(optional=true) private Address address;

public Long getId() { return this.id; }

public void setId(Long id) { this.id = id; }

public String getName() { return this.name; }

public void setName(String name) { this.name = name; }

public Address getAddress() { return this.address; }

public void setAddress(Address address) { this.address = address; } public String toString() { return this.name; }}

DRY

Page 15: From Java to Python

ReadabilityReadability

Page 16: From Java to Python

ReadabilityReadability

No .properties, .xml, sql (/hql)

Page 17: From Java to Python

ReadabilityReadability

XML Theory:human readable

XML Practice:Readability of a binary combined with the efficiency of flat text.

Page 18: From Java to Python

FlexibilityFlexibility

• XML or .properties configuration allows only programmed logic

• settings.py allows custom logic

Page 19: From Java to Python

ReadabilityReadability

Page 20: From Java to Python

Pragmatic APIsPragmatic APIs• APIs created for use, not for possibilities

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();Document doc = docBuilder.parse(new File("file.xml"));

XpathFactory xpf = XPathFactory.newInstance();XPath xpath = xpf.newXPath();NodeSet books = (NodeSet) xpath.evaluate("/Books/Book",doc,XpathConstants.NODESET);

Page 21: From Java to Python

Pragmatic APIsPragmatic APIs• APIs created for use, not for possibilities

InputStream imageInputStream = FileInputStream("c.jpg");

SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);((OpImage) originalImage.getRendering()).setTileCache(null);int origImageWidth = originalImage.getWidth();double scale = 220.0 / originalImage.getWidth();

ParameterBlock paramBlock = new ParameterBlock();paramBlock.addSource(originalImage); // The source imageparamBlock.add(scale); // The xScaleparamBlock.add(scale); // The yScaleparamBlock.add(0.0); // The x translationparamBlock.add(0.0); // The y translation RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);RenderedOp resizedImage = JAI.create(JAI_SUBSAMPLE_AVERAGE_ACTION, paramBlock, qualityHints); // lastly, write the newly-resized image to an output stream, in a specific encodingFileOutputStream encoderOutputStream = new FileOutputStream("c-thumb.jpg");JAI.create(JAI_ENCODE_ACTION, resizedImage, encoderOutputStream, JAI_ENCODE_FORMAT_JPEG, null);

Page 22: From Java to Python

Development cycleDevelopment cycle• Getting started (Django)

Page 23: From Java to Python

Development cycleDevelopment cycleEdit Save

Reload page

(2 seconds)

Edit Save

Reload page

(20 seconds)

Compile

Package

(war)Deploy

Restart

Page 24: From Java to Python

Missing from py?Missing from py?

• Concurrency (!)

• Learn again: Performance tuning

• Safety of jvm

• (Adoption of big companies)

Page 25: From Java to Python

Concurrency?Concurrency?• The free

lunch is over (2005)

• Azul 768-core machine (2007)

• Python GIL in 2011?

Page 26: From Java to Python

Performance tuningPerformance tuning

• Profiling

• GC options

• Memory

Page 27: From Java to Python

Safety of native codeSafety of native code

Page 28: From Java to Python

Organizational Organizational adoptionadoption

• Commercial vendors

• Developer/deployer roles