Why I Love Python

17,454 views

Published on

I love Python, but I didn't make this. It was created by someone named Bruce.

Published in: Technology, Education
3 Comments
28 Likes
Statistics
Notes
No Downloads
Views
Total views
17,454
On SlideShare
0
From Embeds
0
Number of Embeds
214
Actions
Shares
0
Downloads
380
Comments
3
Likes
28
Embeds 0
No embeds

No notes for slide

Why I Love Python

  1. 1. Why I Love Python © 2001 Bruce Eckel MindView, Inc. Training & Consulting 5343 Valle Vista La Mesa, CA 91941 [email_address] www.MindView.net ftp://www.mindview.net/pub/eckel/LovePython.zip
  2. 2. <ul><li>The language you speak affects what you can think </li></ul><ul><li>Python is what I use the most to solve my own problems (I think better) </li></ul><ul><ul><li>Including CGI/e-commerce with MySQL </li></ul></ul><ul><li>5-10 times productivity (really!) </li></ul><ul><li>I’ve been trying to figure out how to explain “why” to people </li></ul><ul><li>Top 10 reasons I’ve come up with </li></ul><ul><li>And a few other interesting topics </li></ul>
  3. 3. What I love most: Python is about ME <ul><li>As if Guido said: “Bruce, what can we do to make your programming experience as easy as possible?” </li></ul><ul><li>No compromises: it’s all about making me more productive </li></ul>
  4. 4. My Language History <ul><li>Age 13: BASIC on HP1000 (HOSRAC.BAS is invented) </li></ul><ul><li>Age 19: APL for physics. The concept of a &quot;terse language&quot;. </li></ul><ul><li>Basic again, survey courses, Pascal et al. </li></ul><ul><li>Age 21: Computer engineering, Chips + assembly language </li></ul><ul><li>Age 22: I begin to understand the value of high-level languages </li></ul><ul><li>Age 24: Database programming AppleII Basic </li></ul>
  5. 5. <ul><li>Age 25: Graduate (finally) with MS, discover C, work in embedded programming (in assembly). </li></ul><ul><ul><li>I am my own C compiler </li></ul></ul><ul><li>Age 26: Basic (again) for data analysis and control of wind-tunnel experiments </li></ul><ul><li>Age 27: Embedded C development. Program 4-bit Harvard architecture machine in assembly. </li></ul><ul><ul><li>Wrote Assembler in GNU-Lisp. Created (?) primitive C++ mode for Gnu-emacs </li></ul></ul><ul><ul><li>Start writing for Micro Cornucopia </li></ul></ul><ul><li>Age 29: University of Washington School of Oceanography with Tom Keffer. </li></ul><ul><ul><li>Chose C++ over Objective-C for openness. </li></ul></ul><ul><ul><li>Published “Computer Interfacing with Pascal & C” </li></ul></ul>
  6. 6. <ul><li>Age 32: Publish “Using C++” </li></ul><ul><ul><li>Join ANSI C++ Committee </li></ul></ul><ul><li>Later: “C++ Inside & Out”, “Black-Belt C++” (edited), “Thinking in C++” </li></ul><ul><li>Java: “easy translation from C++” </li></ul><ul><ul><li>Actually took two years </li></ul></ul><ul><li>Thinking in Python </li></ul><ul><ul><li>Research mode now, web page with notes at www.BruceEckel.com </li></ul></ul><ul><ul><li>The other books and languages wrapped around me like Jacob Marley’s chains… </li></ul></ul>
  7. 7. A ‘Bout’ of Perl <ul><li>After C++ and Java, seemed amazing </li></ul><ul><li>Python is executable pseudocode. Perl is executable line noise. </li></ul><ul><li>Perl is like vice grips. You can do anything with it, and it's the wrong tool for every job </li></ul><ul><ul><li>Leaves teeth marks everywhere </li></ul></ul><ul><li>Perl is worse than Python because people wanted it worse. Larry Wall, 14 Oct 1998 </li></ul><ul><li>I would actively encourage my competition to use Perl. Sean True, 30 Mar 1999 </li></ul>
  8. 8. Top 10 Reasons Why I Love Python
  9. 9. 10. Reduced Clutter <ul><li>Programs are read more than they are written </li></ul><ul><li>XP: Consistent formatting really is important </li></ul><ul><ul><li>Readability and compactness </li></ul></ul><ul><ul><li>Part of “conservation of complexity” </li></ul></ul><ul><li>Consistent use of programming idioms improves understandability </li></ul><ul><ul><li>Rapid understanding </li></ul></ul><ul><ul><li>The opposite of “more than one way to do it” </li></ul></ul>
  10. 10. 9. It’s not backward-compatible in exchange for pain <ul><li>C++: Backward compatible with C – its strength and its bane </li></ul><ul><li>Java: more or less with C++ syntax (not too bad, but a lot of typing) </li></ul><ul><li>Perl: compatible with every hacky syntax of every Unix tool ever invented </li></ul><ul><li>C# and .NET: backward compatible with previous Microsoft marketing campaigns </li></ul><ul><li>Javascript: not even compatible with itself </li></ul>
  11. 11. 8. It doesn’t value performance over my productivity <ul><li>C++: can’t let go of C performance </li></ul><ul><ul><li>Better than C, sure, but still takes forever to get something working; memory leaks are almost impossible to design out </li></ul></ul><ul><li>Java: Primitive types require awkward coding (primitives “necessary” for speed) </li></ul><ul><ul><li>As opposed to Python: everything is an object; escape mechanism (extension) for speed </li></ul></ul>
  12. 12. 7. It doesn’t treat me like I’m stupid <ul><li>“Operator overloading is bad because you can make ugly code with it” </li></ul><ul><li>“finalize( ) does something” </li></ul><ul><li>“We reviewed Java designs before putting them into the language” </li></ul><ul><li>“Java has an open development process” </li></ul>
  13. 13. 6. I don’t wait forever for a full implementation of the language <ul><li>Some features we invented in the C++ committee are still not implemented </li></ul><ul><ul><li>Unused features don’t get tested; circular problem </li></ul></ul><ul><li>Many C++ vendors say “it’s hard, and no one’s asking for it.” </li></ul>
  14. 14. 5. It doesn’t make assumptions about how we discover errors <ul><li>Is strong static type checking really the only way to be sure? </li></ul><ul><ul><li>Lack of good static typing in pre-ANSI C was certainly heaps of trouble </li></ul></ul><ul><ul><li>Doesn’t mean it’s the best solution </li></ul></ul><ul><ul><li>(More about this later) </li></ul></ul><ul><li>Errors discovered with real data seem to me to be the hardest to find </li></ul>
  15. 15. 4. Marketing people are not involved <ul><li>“Java is flawless” </li></ul><ul><li>Microsoft “Visual” “C++” </li></ul><ul><ul><li>Microsoft happens </li></ul></ul><ul><li>Of course, Python isn’t immune </li></ul>
  16. 16. 3. I don’t have to type so much <ul><li>… And I don’t have to wade through so much code when I’m reading </li></ul><ul><li>Conservation of complexity: simplicity really does make a difference </li></ul><ul><li>But the right typing </li></ul><ul><ul><li>Not obscure like APL </li></ul></ul><ul><ul><li>Not endlessly inventive like Perl or FORTH </li></ul></ul>
  17. 17. 2. My guesses are usually right <ul><li>I still have to look up how to open a file every time I do it in Java </li></ul><ul><li>In fact, most things in Java require me to look something up </li></ul><ul><li>I can remember many Python idioms because they’re simpler </li></ul><ul><li>One more reason I program faster </li></ul>
  18. 18. 1. Python lets me focus on concepts <ul><li>No stumbling through Java designs, fighting with C++ compilations or run-time bugs. </li></ul>
  19. 19. Python and “The Tipping Point” <ul><li>Email: possible to carry on dozens of conversations by paper mail, but you don’t. </li></ul><ul><li>Automating Everything: </li></ul><ul><ul><li>Possible to write programs to automate every task. But you don’t. </li></ul></ul><ul><ul><li>Python makes it easy enough </li></ul></ul><ul><ul><li>Great with Gnu make (my CD build system) </li></ul></ul>
  20. 20. Weak typing <ul><li>Only constraints on an object that is passed into a function are that the function can apply its operations to that object </li></ul>def sum(arg1, arg2): return arg1 + arg2 print sum(42, 47) print sum('spam', 'eggs') <ul><li>“ Weak” sounds bad </li></ul>
  21. 21. Weak Typing in C++: Templates <ul><li>#include <string> </li></ul><ul><li>#include <iostream> </li></ul><ul><li>using namespace std; </li></ul><ul><li>template<class A, class B, class R> </li></ul><ul><li>R sum(A a, B b) { </li></ul><ul><li>return a + b; </li></ul><ul><li>} </li></ul><ul><li>int main() { </li></ul><ul><li>string a(&quot;one&quot;), b(&quot;two&quot;) </li></ul><ul><li>cout << sum<string, string, string>(a, b) << endl; </li></ul><ul><li>cout << sum<int, int, int>(1, 2) << endl; </li></ul><ul><li>} </li></ul>
  22. 22. Weak Typing in Java <ul><li>Reflection, possibly with interfaces </li></ul>
  23. 23. 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); } }
  24. 24. Why weak typing isn't weak <ul><li>Upcasting becomes meaningless </li></ul><ul><li>You write what you want to do, let Python worry about how </li></ul><ul><li>Argument against weak typing: “errors won’t be found” </li></ul><ul><ul><li>Like in pre-ANSI C (had no rules) </li></ul></ul><ul><li>As long as rules are enforced sometime , you’ll find the errors </li></ul><ul><ul><li>Heresy: run-time is better than compile time </li></ul></ul>
  25. 25. Performance issues <ul><li>Machine performance vs. Programmer Performance </li></ul><ul><li>Most of the time, which is really more important? </li></ul><ul><li>C++ is naturally faster -- or is it? </li></ul><ul><ul><li>with IOStreams, not always </li></ul></ul>
  26. 26. Future Impact <ul><li>Programmer productivity is the most important thing </li></ul><ul><ul><li>Python excels at rapid creation of maintainable code </li></ul></ul><ul><li>To increase performance, throw hardware at the problem </li></ul><ul><ul><li>Multiprocessor machines & stackless </li></ul></ul><ul><ul><li>Seems like an important direction, even to the point of justifying core language changes </li></ul></ul>
  27. 27. Other Languages <ul><li>C# bores me. Removes the interesting/useful features of both Java & C++. I’d use one of those languages first. </li></ul><ul><li>Ruby. I’ll wait and see, but my impression is that it doesn’t do more for me than Python (or not more enough). </li></ul>
  28. 28. NerdsOnBicycles.com <ul><li>On the New Zealand bike trip, Bill Venners & I decided it would be a good idea to host technically-themed bike tours </li></ul><ul><ul><li>Run by a professional company with all the amenities, the “sag wagon” etc. </li></ul></ul><ul><li>We thought a Python-themed trip might be an interesting beginning </li></ul><ul><ul><li>Grand Tetons? Send email if interested </li></ul></ul>
  29. 29. Life is Short (You Need Python) OR: No Warrantee Not Fit for Any Particular Purpose (You Need Python)

×