More Related Content Similar to Why I Love Python V2 Similar to Why I Love Python V2 (20) Why I Love Python V21. Why I Love Python
…with some essential
questions about computing
© 2008 Bruce Eckel
MindView, Inc.
www.mindviewinc.com
Write questions
on paper
2. Alas, I’ve spent years of my life here…
Why I Love Python ©2008 www.MindView.net
6. The language
you speak affects
what you can
think
By learning
multiple
languages, I can
think more
broadly and
create better
designs
10. 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
13. More static
typing is better
It’s a belief
Why I Love Python ©2008 www.MindView.net
15. From “Sway”:
Fear of loss -> Playing “not to lose”
Commitment
17. Static analysis is very useful
But it should be
decoupled from
the language
Allows more
experiments;
faster addition of
new tests
Python benefits
from more static
analysis tools
Why I Love Python ©2008 www.MindView.net
18. Optional Static Typing
Scott 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 information
But you can turn it off whenever you want
Something like what Python 3 allows
Why I Love Python ©2008 www.MindView.net
23. The Concurrency Problem
Processor speed
increases replaced
by multiple cores
How do we use
them?
Why I Love Python ©2008 www.MindView.net
24. Why I Love Python
Why I Love Python ©2008
www.MindView.net
25. 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
26. A ‘Bout’ of Perl
After C++ and Java, seemed amazing
Python 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
27. Python Reduces Clutter
Programs are read more
than they are written
Consistent formatting
really is important
Readability and compactness
Conservation of complexity:
Simplicity really does
make a difference
Consistent use of programming idioms
improves understandability
Rapid understanding
The opposite of “more than one way to do it”
Why I Love Python ©2008 www.MindView.net
28. It doesn’t value performance
over my productivity
C++: can’t let go of C performance
Better 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
29. 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, Swing
is easy, JavaFX will be great!
“Every new feature
makes it better!
Generics! Closures!”
Why I Love Python ©2008 www.MindView.net
30. Pro Con
Garbage collection is now Dumb naming. Java 2 is
mainstream 1.2, Java 5 is 1.5. Also
Virtual nio and nnio. Naming is
machines/bytecode important.
interpreters are now Classpath (enough said)
mainstream Bad invention in general
Unified error handling vs. Added-on features to
C++ compensate for bad
language design
Never admitting that the
design was bad in the
first place
Checked exceptions.
Sound good, don't scale
Why I Love Python ©2008 www.MindView.net
31. Con Con
Primitives (but they like to Assertions: they're off by
call the language quot;pure”) default; you have to turn
Knee-jerk threading, them on via a command-
which is confusing and line flag
too hard to get right. Generics (so-called) w/
Subtle threading bugs erasure. Not really
until Java 5 generics, just support for
They *had* to rush it out, collection typing. Even
now they're one of the architects has
monkeypatching the reversed position.
language Now closures! But this
Faked properties and has rapidly become a
events (JavaBeans) mess with lots of push-
back, no doubt because
of generics.
Why I Love Python ©2008 www.MindView.net
32. Con Con
The EJB fiasco (many AWT was too simple &
billions lost) bad. Swing is too
The JCP: Panders to complex, but Sun has a
every special interest and deathgrip on it (sunk cost
pushes the results on us model). Now we have
(you get 10 days to JavaFX instead of playing
comment) well with, say, Flex which
has already solved the
problems.
I could go on.
Why I Love Python ©2008 www.MindView.net
33. Con Pro
Self (Everything else)
GIL is unavoidable, but Biggest: I trust Guido, the
we need a pythonic team, and the community.
concurrency model (don't Choices that seem weird
just use threads because at first turn out to be good
everyone else does). (comprehensions).
Need a one-click installer Things that are broken
as part of the distribution. get fixed (XML library,
An easy_install type of refactoring in Python 3).
service should also be I'd like to just work with
built in. Python and Flex.
Currently, for me, that's
the best of all worlds.
Why I Love Python ©2008 www.MindView.net
34. 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 trouble
Doesn’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
35. Marketing people are not involved
“Java is flawless”
Of course, Python
isn’t immune
Spam, spam, spam, spam …
Why I Love Python ©2008 www.MindView.net
36. I don’t have to type so much
… And I don’t have to wade through so
much code when I’m reading
But the right typing
Not obscure like APL
Not endlessly inventive
like Perl or FORTH
Why I Love Python ©2008 www.MindView.net
37. The clean design of the language
encourages clean library design:
import feedparser
rss = feedparser.parse('myurl.rss')
for entry in rss['entries']:
print entry['link'],
entry['title'],
entry['summary‘]
Why I Love Python ©2008 www.MindView.net
38. My guesses are
usually right
Most things in Java
require me to look
something up
I can remember many Python idioms
because they’re simpler
One more reason I program faster
Why I Love Python ©2008 www.MindView.net
39. I can remember this:
file(quot;Myfile.txtquot;)
I always have to look this up:
import java.io.*;
BufferedReader in = new BufferedReader(
new FileReader(quot;Myfile.txtquot;));
Why I Love Python ©2008 www.MindView.net
40. #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
41. Duck (Structural) typing
Only constraints on an object that is
passed into a function are that the
function can apply its operations to that
object
def 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
42. 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(quot;onequot;), b(quot;twoquot;)
cout << sum<string, string, string>(a, b) << endl;
cout << sum<int, int, int>(1, 2) << endl;
}
Why I Love Python ©2008 www.MindView.net
43. Duck Typing in Java
Reflection, possibly with interfaces
Why I Love Python ©2008 www.MindView.net
44. 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);
}
}
45. Duck typing isn't weak
You write what you want to do,
let Python worry about how
Argument 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
46. Performance issues
Machine Performance
vs. Programmer
Performance
Most of the time,
which is really
more important?
Python 2.5 cytpes
easily connect to dlls
pp and similar solutions for multiprocessor
machines and machine clusters
Why I Love Python ©2008 www.MindView.net