views:

1222

answers:

21

I have to make a presentation at work to convince everyone why they should try coding in Python. So, I thought of taking a poll here...

What is it about Python (features, etc) over other languages that you love?

The reason I usually give is that in Python you forget about the complexities and frills of programming languages and can just focus on producing code that works... What do you think?

A: 

well, python is a high level languange.. many things are much easier to code with python.. xml parsing etc just a few rows of code.. in many other languages you would write many more rows and more complex code... python make coders life easy :)

darkdog
A: 

Monkey patching!

and list comprehension.

shoosh
+8  A: 

Its syntax and idioms are intuitive. Once you've grasped the basics, more often than not you'll guess how something should work (in terms of how it should be expressed in code), and be right. That's a sign of a beautiful language: you can express yourself in code with ease.

That's clearly not an objective differentiator, though it means that it's easy to be incredibly productive in Python.

Jason Etheridge
+14  A: 

My reasons are here:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Oh and the interactive terminal is great too.

Adam J. Forster
you could edit your answer and enclose the whole output "The Zen…of those" into a <pre></pre> pair to avoid coloring.
ΤΖΩΤΖΙΟΥ
How does this answer the question "why python"? I can think of several dynamic languages to which your answer applies.
Bryan Oakley
+22  A: 
  • Python forces you to write easily understandable code due to the indentation.
  • Python has 'batteries included'. (Huge standard library)
  • Python supports multiple programming paradigms.
  • Python has a fully dynamic type system.
  • Python has automatic memory management.
  • Python has an open, community-based development model.
  • Python is stable and mature.
  • Python is highly scalable, suitable for large projects as well as small ones.
  • Python is portable and cross-platform.
  • Python is just cool!
Gary Willoughby
@ #1 - Never knew indentations are powerful enough to make bad programmers write easily understandable code.
Baddie
@Baddie - agreed! Good programmers don't have to be forced to indent, and for bad programmers... well, indentation alone can't protect us from bad programmers.
Bryan Oakley
+4  A: 

Python makes coding easier, and more fun. Here's just a few ideas off the top of my head:

  • You don't have to worry so much about memory management because of the built-in garbage collection.
  • The dynamic nature means you don't have to have a code/compile/debug cycle; you can immediately see the results of your code.
  • The syntax is like pseudo-code, so even non-programmers can have an idea of what it's supposed to do.
  • If the interpretive nature of the language is too slow, just code the necessary sections in C/C++ and import them. For example, the pickle method vs. cPickle.
  • Simple yet powerful language can be used for simple scripts to full-blown applications. Prototypes are easily changed into working programs, even if a different language is ultimatley desired.
  • Useful in multiple situations using only one language, such as web apps (Django) or game development (PyGame).
  • NASA, Google, Industrial Light and Magic, et al. all use Python. If it's good enough for them, it should be good enough for you.
crystalattice
and if you want a good C++ integration, use boost::pythom which makes life very easy indeed.
gbjbaanb
+1  A: 

To me the genius of Python language lies in the simple syntax used to group statements. Actually, there is no difference between a one statement group and a multi-statement groups. Other languages force you to use curly braces {} or begin/end.

It doesn't seem much but when you do programming it relieves you from a lot of typing.

bernardn
+3  A: 

High readability (once you get used to it).

Also, it looks very much like how many people would intuitively write pseudo code, meaning that going from pseudo code to a (mock-up) Python implementation can often be very fast.

Anders Sandvig
A favorite quote from a friend of mine is 'python is a pseudo-code interpreter with a standard library'.
Dan Udey
How is python any more readable than many other dynamic languages?
Bryan Oakley
+7  A: 

I recently began learning python by playing the python challenge and what most surprised me was that once I knew what libraries to import it was very easy to write moderately complex programs, none of my solutions to the challenge riddles was bigger than 20 lines and most of them were a couple of lines, and very rarely I found myself fixing stupid errors: once you write the code, if the logic is correct, the program works as expected the first time. Much, much less wrestling with syntax, casting, indirection, conversion, etc, in comparison to Java, C or C#.

They don't exaggerate when they say Python is close to executable pseudocode.

Sergio Acosta
The Python Challenge was enormously fun and taught me a lot! I have to go back and finish it some time.
Todd
+3  A: 

And if I may quote the martinbot:

  • python does not support buffer overflows

Of course, if you search this deeper, it does; however, you have to code out of your usual way (use carelessly ctypes or buffer objects) to make it overflow a buffer, which is in contrast to most lower-level languages, where you have to code carefully and specifically to avoid buffer overflows.

ΤΖΩΤΖΙΟΥ
+2  A: 
  • dynamic typing (unlike java)
  • strong typing (unlike PHP)
  • forced indentation makes almost every code readable (no curly braced or do..end)
  • garbage collection
  • heavily script-oriented (meaning files handling and stuff like that are made easy)
  • almost everything made explicit
Bartosz Radaczyński
The cpython implementation, which is what most people use, uses reference counting and not garbage collection. Jython and IronPython use GC because of the behavior of the underlying VM.
Dan Udey
@Dan Udey: CPython has GC since 2.0 http://docs.python.org/lib/module-gc.html http://arctrix.com/nas/python/gc/
J.F. Sebastian
@Dan Udey: you need to check on your terminology. "Uses reference counting and not garbage collection" is contradictory, since reference counting is a form of garbage collection. You probably meant "…and not a tracing garbage collection."
ΤΖΩΤΖΙΟΥ
+5  A: 

Without any order:

Torsten Marek
+9  A: 

The thing I love most about Python is that most code I write works the first time!

In so many other languages I'll spend much more time debugging all sorts of odd issues.

Python seems to save me from shooting myself in the foot due to its clarity and clean design.

Yay Python!

hexsprite
+5  A: 

As I said before.

A quick example with performing a HTTP GET resquest. (from http://coreygoldberg.blogspot.com/2008/09/python-vs-java-http-get-request.html) :

Java :

import java.net.*;
import java.io.*;

public class JGet {
    public static void main (String[] args) throws IOException {
        try {
            URL url = new URL("http://www.google.com");

            BufferedReader in = 
                new BufferedReader(new InputStreamReader(url.openStream()));
            String str;

            while ((str = in.readLine()) != null) {
                System.out.println(str);
            }

            in.close();
        } 
        catch (MalformedURLException e) {} 
        catch (IOException e) {}
    }
}

Python :

import urllib
print urllib.urlopen('http://www.google.com').read()
e-satis
In Java's defense, you're not doing any exception handling in your Python script. Also, is it entirely necessary in Java to read line by line?
Dan Udey
True, but java just won't run if I don't put this try/catch blocks. And for the line by line, I believe that for a stream, you have to do it that way (no file like object). But I can be wrong, I am better in Python that Java :-)
e-satis
I think the Java was a small bit extra, but a perfect illustration of some the strengths of Python, perfect.
David
it's like doing `a = sqrt(2.0)` vs implementing square root in assembly manually (for a processor that doesn't have a built-in instruction for it)
hasen j
A: 

Yep!

I'm able to prototype an app within hours - nothing like proving your idea/concept without investing a great deal of development time.

I only started using Python about 3 months ago, and I honestly can't wait to use it again.

d2kagw
+1  A: 

I use Python in a CS0 course that I teach. Most of the students are in a two-year associates program, and this may be the only formal programming course they take in this program. Using Python makes it easy to teach text file I/O (which is really useful for text file conversion), and more advanced topics like XML parsing (using xml.sax). The final project involves parsing an XML file and writing the output to HTML with CSS. The simplicity of the Python language allows the students to learn about simple ways to provide formatted text (that can be opened in Word or OpenOffice Writer) without having to learn about Rich Text Format (RTF).

In short, I like Python because its simplicity allows me to cover a number of practical applications even if it is the student's only formal programming course. If you are trying to convince a group of people who seldom program a programming language, choosing Python allows them to do some practical things with a relatively flat learning curve. This might (as it does for some of my students) encourage them to learn other programming languages.

A: 

All the standard great reasons make Python wonderful to work in. What has made Python most useful to me is the combination of this environment with SciPy and Cython.

I love SciPy because it brings a ton of speedy, useful math to the table, along with verbose exceptions. I've worked with Maple and Mathematica in the past, and have really struggled with them when something would go wrong - but (usually) with Python and SciPy the problems are easy to diagnose.

Cython is great because of the way it opens up the speed of C without having to learn the sticky points of C (like pointers, eww). It allows you to keep the convenience of Python, but fix the bottlenecks where having a big fancy interpreted language makes things slow.

assortedslog
A: 

Python is best for web development, because of its similarities to JavaScript that reduce the context-switch overhead going from serverside to clientside. Similarities include:

  • Identical hash literal syntax, i.e. { "name": "John Simons", "age": 31 }
  • Same concept of truthiness, i.e. 0, "", [], {} are all considered false
  • Call function references just by appending parenthesis, instead of having to use "call" like ruby does.
+1  A: 

I dont "like python" in general - no one language is good for all tasks. I like it very much for rapid prototyping, glue scripts (that tie together other large programs) and probably other kinds of things that escape my mind at the moment. What kinds of programs do your fellow programmers write?

Lous39
A: 

These points must be mentioned:

  • named for Monty Python
  • makes me think of breakfast food whenever I work in it
  • anti-gravity
Todd
apparently not popular with humor-deprived individuals
Todd
Yes, you have to watch out for them.
zaf
A: 

Maybe this is stating the obvious, but I like it because of the fact that the language is object oriented. There are some very fine scripting languages out there -- some with some definite advantages over python -- but the fact that objects and classes are cheap and first-class is a huge selling point.

For example, I think Tcl outshines Python in many ways, and is Python's equal in many others. After using Python for the better part of a year however, I now believe that Tcl's lack (*) of an object system is a detriment. I didn't always feel that way, but being able to easily create classes in Python is a big win. While I know how to encapsulate code and data in Tcl with object-like namespaces, it was always more difficult than it needed to be.

The other thing I like about Python, as has been mentioned in other answers, is the standard library that it comes with. There's a whole lot of good stuff there.

(* yes, I know Tcl now has a OO package, and yes I know about [incr tcl] and other object packages. )

Bryan Oakley