Upload
gsroma
View
4.792
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Bruce Eckel
Citation preview
Why I Love Python…with some essential questions about computing
© 2008 Bruce EckelMindView, Inc.www.mindviewinc.com
Write questions on paper
Why I Love Python ©2008 www.MindView.net
Alas, I’ve spent years of my life here…
The language you speak affects what you can thinkBy learning multiple languages, I can think more broadly and create better designs
Reduces rigid thinking
Does Language Matter?
Why I Love Python ©2008 www.MindView.net
Fundamental Question
How much safety can we build into a language? What can you actually get? What does it cost?
Why I Love Python ©2008 www.MindView.net
Directing vs. Enabling
Why I Love Python ©2008 www.MindView.net
More static typing is betterIt’s a belief
Why I Love Python ©2008 www.MindView.net
From “Sway”:Fear of loss -> Playing “not to lose”Commitment
Why I Love Python ©2008 www.MindView.net
Static analysis is very useful
But it should be decoupled from the languageAllows more experiments; faster addition of new testsPython benefits from more static analysis tools
Why I Love Python ©2008 www.MindView.net
Optional Static TypingScott Meyers: Static typing is for development tools and code generation.ActionScript (the Flex language) is a dynamic language with optional static typing
FlexBuilder gives code hinting when you provide type informationBut you can turn it off whenever you wantSomething like what Python 3 allows
ActionScript
package com.mindviewinc.functional {public function reduce(a:Array, reducer:Function):* {
var result:* = a[0]for each(var item:* in a.slice(1, a.length))
result = reducer(result, item)return result
}}
Is Programming Art or Engineering?
ManyCompanies Desperately Want it to be Engineering
Replaceable You
Why I Love Python ©2008 www.MindView.net
Why I Love Python ©2008 www.MindView.net
The Concurrency Problem
Processor speed increases replaced by multiple coresHow do we use them?
Why I Love Python ©2008 www.MindView.net
Why I Love Python
Why I Love Python ©2008 www.MindView.net
What I love most: Python is about ME
As if Guido said: “Bruce, what can we do to make your programming experience as easy as possible?”No compromises: it’s all about making me more productive
Why I Love Python ©2008 www.MindView.net
A ‘Bout’ of PerlAfter C++ and Java, seemed amazingPython is executable pseudocode. Perl is executable line noise.Perl is like vice grips. You can do anything with it, and it's the wrong tool for every job (Leaves teeth marks everywhere)Perl is worse than Python because people wanted it worse. Larry Wall, 14 Oct 1998
I would actively encourage my competition to use Perl. Sean True, 30 Mar 1999
Why I Love Python ©2008 www.MindView.net
Python Reduces ClutterPrograms are read more than they are writtenConsistent formatting really is important
Readability and compactnessConservation of complexity: Simplicity really does make a difference
Consistent use of programming idioms improves understandability
Rapid understandingThe opposite of “more than one way to do it”
Why I Love Python ©2008 www.MindView.net
It doesn’t value performance over my productivity
C++: can’t let go of C performanceBetter than C, sure, but still takes forever
to get something working; memory leaks are almost impossible to design out
Java: Primitive types require awkward coding (primitives “necessary” for speed)
As opposed to Python: everything is an object; escape mechanism for speed: ctypes
Why I Love Python ©2008 www.MindView.net
It doesn’t treat me like I’m stupid“Operator overloading is bad because you can make ugly code with it”“finalize( ) does something”“We reviewed Java designs before putting them into the language”AWT & EJB are great, Swingis easy, JavaFX will be great!“Every new feature makes it better! Generics! Closures!”
Pro
Garbage collection is now mainstreamVirtual machines/bytecodeinterpreters are now mainstreamUnified error handling vs. C++
Con
Dumb naming. Java 2 is 1.2, Java 5 is 1.5. Also nio and nnio. Naming is important.Classpath (enough said)Bad invention in generalAdded-on features to compensate for bad language designNever admitting that the design was bad in the first placeChecked exceptions. Sound good, don't scale
Why I Love Python ©2008 www.MindView.net
Con
Primitives (but they like to call the language "pure”)Knee-jerk threading, which is confusing and too hard to get right. Subtle threading bugs until Java 5They *had* to rush it out, now they're monkeypatching the languageFaked properties and events (JavaBeans)
Con
Assertions: they're off by default; you have to turn them on via a command-line flagGenerics (so-called) w/ erasure. Not really generics, just support for collection typing. Even one of the architects has reversed position.Now closures! But this has rapidly become a mess with lots of push-back, no doubt because of generics.
Why I Love Python ©2008 www.MindView.net
Con
The EJB fiasco (many billions lost)The JCP: Panders to every special interest and pushes the results on us (you get 10 days to comment)
Con
AWT was too simple & bad. Swing is too complex, but Sun has a deathgrip on it (sunk cost model). Now we have JavaFX instead of playing well with, say, Flex which has already solved the problems.I could go on.
Why I Love Python ©2008 www.MindView.net
Con
SelfGIL is unavoidable, but we need a pythonicconcurrency model (don't just use threads because everyone else does).Need a one-click installer as part of the distribution. An easy_install type of service should also be built in.
Pro
(Everything else)Biggest: I trust Guido, the team, and the community. Choices that seem weird at first turn out to be good (comprehensions).Things that are broken get fixed (XML library, refactoring in Python 3).I'd like to just work with Python and Flex. Currently, for me, that's the best of all worlds.
Why I Love Python ©2008 www.MindView.net
Why I Love Python ©2008 www.MindView.net
It doesn’t make assumptions about how we discover errors
Is static type checking really the only way to be sure?
Lack of good static typing in pre-ANSI C was certainly heaps of troubleDoesn’t mean it’s the best solution
Errors discovered with real data seem to me to be the hardest to find statically
Why I Love Python ©2008 www.MindView.net
Marketing people are not involved
“Java is flawless”Of course, Pythonisn’t immune
Spam, spam, spam, spam …
Why I Love Python ©2008 www.MindView.net
I don’t have to type so much
… And I don’t have to wade through so much code when I’m readingBut the right typing
Not obscure like APLNot endlessly inventivelike Perl or FORTH
Why I Love Python ©2008 www.MindView.net
The clean design of the language encourages clean library design:
import feedparserrss = feedparser.parse('myurl.rss')for entry in rss['entries']:
print entry['link'],entry['title'],entry['summary‘]
Why I Love Python ©2008 www.MindView.net
My guesses are usually right
Most things in Java require me to look something upI can remember many Python idioms because they’re simplerOne more reason I program faster
Why I Love Python ©2008 www.MindView.net
I can remember this:file("Myfile.txt")
I always have to look this up:import java.io.*;BufferedReader in = new BufferedReader(
new FileReader("Myfile.txt"));
Why I Love Python ©2008 www.MindView.net
#1:Python lets me focus on concepts
No stumbling through Java designs, fighting with C++ compilations or run-time bugs.
Why I Love Python ©2008 www.MindView.net
Duck (Structural) typing
Only constraints on an object that is passed into a function are that the function can apply its operations to that objectdef sum(arg1, arg2):
return arg1 + arg2
print sum(42, 47)print sum('spam', 'eggs')
If it walks like a duck, and talks like a duck…
Why I Love Python ©2008 www.MindView.net
Duck Typing in C++: Templates#include <string>#include <iostream>using namespace std;
template<class A, class B, class R>R sum(A a, B b) {
return a + b;}
int main() {string a("one"), b("two")cout << sum<string, string, string>(a, b) << endl;cout << sum<int, int, int>(1, 2) << endl;
}
Why I Love Python ©2008 www.MindView.net
Duck Typing in Java
Reflection, possibly with interfaces
interface addable { Object add(Object b);}
class X implements addable {public Object add(Object b) {
return new Object(); // Test}
}
class AddableNotFoundException extends Exception {}
public class DuckTyping {public static Object sum(Object a, Object b)
throws AddableNotFoundException {Class[] intfs = a.getClass().getInterfaces();for(int i = 0; i < intfs.length; i++)
if(intfs[i] == addable.class)return ((addable)a).add(b);
throw new AddableNotFoundException();}public static void main(String[] args) throws Exception {
X a = new X();X b = new X();Object c = sum(a, b);
}}
Why I Love Python ©2008 www.MindView.net
Duck typing isn't weak
You write what you want to do, let Python worry about howArgument against dynamic typing: “errors won’t be found”
Like in pre-ANSI C (had no rules)As long as rules are enforced sometime, you’ll find the errors
Heresy: run-time is better than compile time
Why I Love Python ©2008 www.MindView.net
Performance issuesMachine Performance vs. Programmer PerformanceMost of the time, which is really more important?Python 2.5 cytpeseasily connect to dllspp and similar solutions for multiprocessor machines and machine clusters
Why I Love Python ©2008 www.MindView.net
Life is Short(You Need Python)
Questions