Why I Love Python

29
Why I Love Python ©2001 www.BruceEckel Why I Love Python © 2001 Bruce Eckel MindView, Inc. Training & Consulting 5343 Valle Vista La Mesa, CA 91941 [email protected] www.MindView.net ftp://www.mindview.net/pub/eckel/ LovePython.zip

Transcript of Why I Love Python

Page 1: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Why I Love Python© 2001 Bruce EckelMindView, Inc.Training & Consulting5343 Valle VistaLa Mesa, CA [email protected]://www.mindview.net/pub/eckel/LovePython.zip

Page 2: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

The language you speak affects what you can thinkPython is what I use the most to solve my own problems (I think better)

Including CGI/e-commerce with MySQL

5-10 times productivity (really!)I’ve been trying to figure out how to explain “why” to peopleTop 10 reasons I’ve come up withAnd a few other interesting topics

Page 3: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

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

Page 4: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

My Language History

Age 13: BASIC on HP1000(HOSRAC.BAS is invented)Age 19: APL for physics. The concept of a "terse language".Basic again, survey courses, Pascal et al.Age 21: Computer engineering, Chips + assembly languageAge 22: I begin to understand the value of high-level languagesAge 24: Database programming AppleII Basic

Page 5: Why I Love Python

Age 25: Graduate (finally) with MS, discover C, work in embedded programming (in assembly).

I am my own C compiler Age 26: Basic (again) for data analysis and control of wind-tunnel experimentsAge 27: Embedded C development. Program 4-bit Harvard architecture machine in assembly.

Wrote Assembler in GNU-Lisp. Created (?) primitive C++ mode for Gnu-emacsStart writing for Micro Cornucopia

Age 29: University of Washington School of Oceanography with Tom Keffer.

Chose C++ over Objective-C for openness.Published “Computer Interfacing with Pascal & C”

Page 6: Why I Love Python

Age 32: Publish “Using C++”Join ANSI C++ Committee

Later: “C++ Inside & Out”, “Black-Belt C++” (edited), “Thinking in C++”Java: “easy translation from C++”

Actually took two years

Thinking in PythonResearch mode now, web page with notes at www.BruceEckel.comThe other books and languages wrapped around me like Jacob Marley’s chains…

Page 7: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

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 everywherePerl 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

Page 8: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Top 10 Reasons Why I Love Python

Page 9: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

10. Reduced Clutter

Programs are read more than they are writtenXP: Consistent formatting really is important

Readability and compactnessPart of “conservation of complexity”

Consistent use of programming idioms improves understandability

Rapid understandingThe opposite of “more than one way to do it”

Page 10: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

9. It’s not backward-compatible in exchange for pain

C++: Backward compatible with C – its strength and its baneJava: more or less with C++ syntax (not too bad, but a lot of typing)Perl: compatible with every hacky syntax of every Unix tool ever inventedC# and .NET: backward compatible with previous Microsoft marketing campaignsJavascript: not even compatible with itself

Page 11: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

8. 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 (extension) for speed

Page 12: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

7. 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”“Java has an open development process”

Page 13: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

6. I don’t wait forever for a full implementation of the language

Some features we invented in the C++ committee are still not implemented

Unused features don’t get tested;circular problem

Many C++ vendors say “it’s hard, andno one’s asking for it.”

Page 14: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

5. It doesn’t make assumptions about how we discover errors

Is strong 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(More about this later)

Errors discovered with real data seem to me to be the hardest to find

Page 15: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

4. Marketing people are not involved

“Java is flawless”Microsoft “Visual” “C++”

Microsoft happensOf course, Pythonisn’t immune

Page 16: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

3. I don’t have to type so much

… And I don’t have to wade through so much code when I’m readingConservation of complexity: simplicity really does make a differenceBut the right typing

Not obscure like APLNot endlessly inventivelike Perl or FORTH

Page 17: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

2. My guesses are usually right

I still have to look up how to open a file every time I do it in JavaIn fact, most things in Java require me to look something upI can remember many Python idioms because they’re simplerOne more reason I program faster

Page 18: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

1. Python lets me focus on concepts

No stumbling through Java designs, fighting with C++ compilations or run-time bugs.

Page 19: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Python and “The Tipping Point”

Email: possible to carry on dozens of conversations by paper mail, but you don’t.

Automating Everything:Possible to write programsto automate every task. But youdon’t.Python makes it easy enoughGreat with Gnu make (myCD build system)

Page 20: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Weak 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')

“Weak” sounds bad

Page 21: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Weak 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;}

Page 22: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Weak Typing in Java

Reflection, possibly with interfaces

Page 23: Why I Love Python

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 WeakTyping { 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); }}

Page 24: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Why weak typing isn't weak

Upcasting becomes meaninglessYou write what you want to do, let Python worry about howArgument against weak 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

Page 25: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Performance issues

Machine performance vs. Programmer PerformanceMost of the time, which is really more important?C++ is naturally faster -- or is it?

with IOStreams, not always

Page 26: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Future Impact

Programmer productivity is the most important thing

Python excels at rapid creation of maintainable code

To increase performance, throw hardware at the problem

Multiprocessor machines & stacklessSeems like an important direction, even to the point of justifying core language changes

Page 27: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Other Languages

C# bores me. Removes the interesting/useful features of both Java & C++. I’d use one of those languages first.Ruby. I’ll wait and see, but my impression is that it doesn’t do more for me than Python (or not more enough).

Page 28: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

NerdsOnBicycles.com

On the New Zealand bike trip, Bill Venners & I decided it would be a good idea to host technically-themed bike tours

Run by a professional company with all the amenities, the “sag wagon” etc.

We thought a Python-themed trip might be an interesting beginning

Grand Tetons? Send email if interested

Page 29: Why I Love Python

Why I Love Python ©2001 www.BruceEckel.com

Life is Short(You Need Python)

OR:

No WarranteeNot Fit for Any Particular Purpose

(You Need Python)