55

Other than being annoyed at whitespace as syntax, I'm not a hater, I just don't get the fascination with Python.

I appreciate the poetry of Perl, and have programmed beautiful web services in bash & korn, and shebang gnuplot. I write documents in troff and don't mind REXX. Didn't find tcl any more useful years ago, but what's the big stink about Python? I see job listings and many candidates with this as a prize & trophy on their resumes.


I guess in reality, I'm trying to personally become sold on this, I just can't find a reason.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
Jé Queue
  • 3,937
  • 2
  • 29
  • 37
  • 81
    I never understand why people get annoyed at Python's required indenting. I *hope* you were going to indent your code anyway, right? – Greg Hewgill Sep 20 '10 at 03:46
  • 10
    @GregH, of course, but shall my syntax be mandated by it? Kind of like Makefiles? – Jé Queue Sep 20 '10 at 03:47
  • 5
    @Xepoch: But Makefiles don't just require indenting, they require a specific kind of indenting that's usually indistinguishable from the other kind. If Makefiles needed *any* whitespace indent instead of specifically `0x09`, you probably wouldn't object and would probably use consistent indenting in your preferred indent width. This is the same thing Python allows. – Greg Hewgill Sep 20 '10 at 03:55
  • 31
    Poetry of Perl? Seriously? If you have had the honor of maintaining other people's Perl code, you would understand why Perl has fallen in terms popularity. – grokus Sep 20 '10 at 14:03
  • 6
    @Greg, I agree with you. I said this before and I will say it again, whoever complains about Python's indentation rule should be asked to maintain poorly indented code. Just sayin... – grokus Sep 20 '10 at 14:05
  • 3
    Sounds to me like you and I have a lot in common: I'm a Unix guy and although I tried to get into Python and OOP, I just didn't get it: http://trashbird1240.wordpress.com/2010/07/08/object-oriented-programming-i-just-dont-get-it/ – Joel J. Adamson Sep 23 '10 at 12:36
  • @JoelA, I don't mind OOP, and love Java (Java and Unix share many roots). That said I used to cringe at PHP but use it regularly now. – Jé Queue Sep 23 '10 at 14:41
  • @Joel: If you ask that blog post as a question on here, I believe I can (at least attempt to) answer your question satisfactorily. – Chinmay Kanchi Sep 23 '10 at 15:42
  • @Joel && @Kanchi, yes it would be another good Q. I'm pretty old-school green-screen but I even find real use in OO. – Jé Queue Sep 23 '10 at 15:58
  • @Xepoch: I thought about it, but that was before I knew about Programmers.SE. I will try to come up with a summary and post it as a new question. – Joel J. Adamson Sep 24 '10 at 16:18
  • @grokus, Perl's big downfall is maintaining code from others, and (gasp) I find mandated syntactical style a necessity on larger Perl projects. But Perl is an extraordinarily powerful tool that gets a bad rap for allowing programmers to express how to do things their own way. I am getting a lot of bad feelings though on Perl6, /not/ liking the new syntax which should have been seriously much cleaner and I'm annoyed at unicode chars as tokens. – Jé Queue Oct 23 '10 at 05:58
  • 1
    @Xepoch - so you find mandating a style necessary for large Perl projects but object to Python implementing the only way of actually making sure it happens (essentially have the language enforce it)? – Jon Hopkins Jan 19 '11 at 10:22
  • @Jon Hopkins - almost any company will have some code style guidelines and even mandate them, Perl, SQL, C, Java. The important part of these is that that style can be your own. Yes, Python dictates style for you, it feels like a new-age, out-of-the-box school yet where all pupils have the same dress code. – Jé Queue Jan 19 '11 at 15:14
  • 2
    @Xepoch: Python does not mandate the number of spaces or tabs, so you can still have company guidelines. And all good style guideline will require you to indent according to control structure anyway. And if you ever want to write indent for logical grouping of related statements, you can write an `if True:` or even better is to use use whitespaces or refactor them into a function. – Lie Ryan Sep 25 '11 at 12:10
  • Did you choose the `bash` tag in your question because you wanted to bash Python? – Giorgio Mar 17 '14 at 13:00

16 Answers16

77

I've found Python to be the most natural programming language that I've ever written code in. I've coded in a lot of languages before and after Python, and to a greater or lesser extent, you have to fight the language to get it to do what you want. Python reduces this struggle massively. Eric S Raymond said it much better than I can in Why Python?

As a related point, Python maintains its cleanness even while evolving rapidly. In most languages I've worked with, introduction of new language features introduces a lot of wrinkles. But with Python, even major language features (decorators come to mind) are added all the time, without feeling like ugly hacks.

Chinmay Kanchi
  • 6,173
  • 2
  • 39
  • 51
61

Python is a well-designed language with a reasonably clean syntax, a comprehensive standard library, excellent included and third party documentation, widespread deployment, and the immediacy of a "scripting" style language (ie. no explicit compile step).

Greg Hewgill
  • 10,181
  • 1
  • 46
  • 45
  • I don't think it is totally cool exactly because it has been hacked along the history to get fresh. Python would be almost perfect if the language get really clean forgetting legacy syntax or semantics. P3 got better but much less than it needs. I don't remember a language that hurts more one of its rules, "one way to do things". – Maniero Sep 20 '10 at 12:45
  • 37
    Well-designed? Ever noticed that you have a global function called `len`? – alternative Sep 23 '10 at 23:55
  • 66
    what is wrong with len? I get the impression you only read about python for 5 minutes – Kugel Nov 21 '10 at 02:56
  • @bigown: Read the Zen of Python (http://www.python.org/dev/peps/pep-0020/) again, and you'll see it says "there should be only one" and not there is only one. This just means "go the easy and obvious path" and don't do fancy stuff. – naeg Sep 26 '11 at 08:40
  • 5
    Personally, the language structure was so simple to grasp that it gave me a better understanding of how languages in general work internally. It's the little things. First class functions, ability to import only the relevant parts of a external module into the current, list comprehensions, tuples, the inclusion of self as a method parameter helped me understand the difference between functions and methods (other languages just hide behind sugar). It pains me to use languages like C# now because I know intuitively that the code isn't teaching me how anything about how it's working internally. – Evan Plaice Jan 17 '12 at 07:01
  • 4
    How can python be a well designed language? It uses weird `__double_underscore_names__`, it mixes `alllowercasefunctionames` with `mixed_underscore` and `mixedCamelCase` names. It requires a `:` at the end of `def` or loops. It uses a lot of odd abbreviation `str`, `dict`, `islice`. It looks like there was no convention at all. It's a pure chaos. Peps, pips, zens... it's more like a python-religion then a language. It might have a few nice features but it doesn't explain why so many people are so over exited about it. There is nothing special about pyhon. Just another poorly designed product. – t3chb0t Feb 12 '18 at 12:29
  • 1
    And what the hack is `def`? Why do I define a function with a `def` and not a `func`? There is no other languague that is as unintuitive as python. – t3chb0t Feb 12 '18 at 12:33
  • Not to mention that there are a ton of third-party libraries that are very well-maintained, like numpy and scipy. – Auden Young Jul 18 '18 at 19:38
26

I hope this doesn't sound too cynical, but IMO Python is so popular for the exact same reason Java, C# and Objective-C are. Not because there's anything spectacular about the languages themselves, but because they've each got a magacorporate sponsor that's able to produce a lot of hype, a lot of advertising, and a lot of libraries and support for their preferred language.

Mason Wheeler
  • 82,151
  • 24
  • 234
  • 309
11

My experience is that the people who find true joy in programming often seek a language that fits them better than what they learned at school or university. Basically this means that they will move from the default PHP / Visual Basic / C++ / Java / C# to something more exotic (business/careerwise) such as Python, Ruby, Haskell and even perl (because of it's enormous hack value and obscurity).

Don't get me wrong, there are very experienced C# / VB.net programmers who take great pride and joy in their work and code (the StackOverflow guys are a very good example), but you don't become a python programmer just because that's what they taught you in school; it has to be your own decision.

I think Jeff Atwoord had a blog post on this, but I can't find it. If I find it I'll update this comment.

Ivo van der Wijk
  • 659
  • 4
  • 13
8

Compared to Ruby, which is really cool and produces amazing Code Golf-offs, Python has this core philosophy that "There should be one - and preferably only one - obvious way to do [things]," meaning the idiomatic Python way. I have found this to be a huge advantage compared to Ruby.

Dan Rosenstark
  • 2,344
  • 1
  • 20
  • 20
  • 4
    ..or compared to Perl with an seemingly infinite # of ways? – Jé Queue Oct 23 '10 at 05:53
  • @Xepoch - actually, there's very often a lot less than infinity of **good/correct** ways of doing things in Perl, and most people with a clue will easily be able to tell you without TOO much disagreement what top 1 (or at most 2) are. if you don't believe me, look at Perl questions on SO. Yes, some quetsions have 10 distinct solutions. But most have a clearly agreed upon "most correct for circumstances" solution. – DVK Jan 13 '11 at 18:56
  • @DVK, I know, but looking at it from a design goal. – Jé Queue Jan 13 '11 at 20:31
8

I started to love Python for the same reason that Eric S. Raymond describes: the act of writing programs in Python is conceptually very similar to thinking the act of designing code in my head.

Learning to be a good Python programmer made me a much better C# programmer. It made understanding LINQ much easier, for one. I might never have embraced a type like Dictionary<string, Func<T>>, or gotten comfortable using yield return, if I hadn't used classes and generators in Python. AOP is a lot easier to understand now that I've used Python decorators. The list goes on.

Robert Rossney
  • 271
  • 1
  • 6
6

The philosophy that the Benevolent Dictator should enforce his idea of good style[1], his idea of good programming, his idea of how to program frustrates me regularly. I don't think like van Rossum. However, his language resists attempts to express non-van Rossum thoughts. His thinking works really well for many (most?) programmers. But I seem to not fit into his model of how to program.

That is why I believe Perl is a superior language.

[1] See his blog about removing reduce.

Paul Nathan
  • 8,560
  • 1
  • 33
  • 41
  • can you please expound on your reasoning with the thought process, would like to hear more. – Jé Queue Oct 23 '10 at 05:54
  • 3
    @Xepoch - a programming language serves as means of expression. Idioms and styles of thought can be expressed in a continuum of thought from 'fits' to 'very hard to fit'. For instance, I do not think in terms of list comprehensions. They are alien to how I think about problem solutions. But Common Lisp's reduce is something that flows without significant difficulty out of my mind. However, van Rossum evidently is the opposite. Java requires all things to be in objects. So it becomes very difficult to create non-object-oriented solutions in Java. And so on - – Paul Nathan Oct 23 '10 at 15:04
6

Firstly, trifling language quirks like forced indentation in Python matters little if the language itself is powerfully expressive and useful. I was also turned away at first due to it, but soon learnt to look past it and now don't even feel it as a hindrance, because the language is so much easier for me to work in. Its like sigils in variables in Perl, its a harmless language quirk and anyone comfortable in the language don't feel bothered by it.

To understand the reasons why so many people think Python is great, just try and learn the language. The reasons are mostly the same as Perl. I find I like the syntax in Python (e.g. list comprehensions, OOP syntax, etc.), but that is really subjective and your opinion might differ. I prefer Python for larger projects, while I still use Perl for smaller scripts.

And that is the answer to your question. You compare Python to Perl, bash and tcl. The thing is that is that is not a fair comparison. Languages like bash was designed for writing small scripts to automate common tasks. Some people think Perl also gets unwieldy if the code gets sufficiently large (well written Perl does not, but well written code is hard to come by in a large project). IMHO Python differs from other 'scripting' languages in that it scales very well to large projects as well as small one-off scripts. I think Ruby also has that same quality.

MAK
  • 1,093
  • 8
  • 14
5

Since 2004, I've used Python to develop:

  • GUIs
  • Scripting ray tracer scenes with Python to C++ bindings
  • Cross platform automated build systems
  • Test scripts
  • General purpose tools to solve your everyday issues
  • Web sites and web apps

Back in 2004, Python was the language of choice because Python scripts are portable across Windows, Linux and Mac with very little modifications.

Thierry Lam
  • 1,108
  • 2
  • 11
  • 17
  • 4
    To quote a comment from different answer: "Not doubting Python here, but I think Perl fits your description above quite well if not better". – DVK Jan 13 '11 at 19:00
5

I think to some degree Python is the only programming language you'll ever need, unless you want to write an OS kernel. It is suitable for the interactive use, random hacks, system administration, scientific applications, operating system tools, web applications, GUI applications, embedding, etc. etc., it's portable, free, and widely used. No other programming language really covers all those fields in practice. It's a really good strategic investment for a person and a company.

  • 4
    Not doubting Python here, but I think Perl fits your description above quite well if not better. – Jé Queue Sep 23 '10 at 14:41
  • Ruby does very well at this too. – ocodo Sep 26 '11 at 00:07
  • 1
    As of 2015, Python is the de facto general purpose language of scientific computing. Everything else is either the classical low-level stuff (C, C++, FORTRAN), competitive in a few niches (MATLAB, Mathematica, R, Julia, Lua), used for libraries and infrastructure only (Java), random scripting tools (bash, Perl) or.... well... none of the above. – Paul Dec 28 '15 at 00:40
4

It's elegant and really easy to learn, and once you're familiar with its basic types (especially lists) your productivity has no limit. It's perfect for prototyping algorithms, or for writing them in a pseudocode-like language that can eventually put directly on a machine, and it's really good as a scripting language for doing repetitive jobs or perform annoying operations on files. I use it as a glue language for making subprocesses communicate with each other: not as powerful as bash for some easy tasks, but WAY easier if you need to do more than just a single line of code.

And then it doesn't distinguish between functions and subroutines, you know what I mean.

Lorenzo Stella
  • 259
  • 1
  • 4
4

To me Python has been a dear friend. It's a decent scripting and prototyping language. The key things I can think of are:

  • Clean syntax, very simplistic and easy to understand
  • Multi-paradigm, use it as a imperative language? Sure. OOP? No problem. It also has some light functional language features, e.g. lambda, list comprehensions, etc.
  • For basic computing needs, it has native support for the essential data structures, array, tuple, dictionary (associative array), set, etc.
  • Other features can make a programmer very productive, e.g. duck-typing, reflection, meta-programming, decorators, generators, etc.
  • Rich library support
grokus
  • 7,536
  • 4
  • 31
  • 46
3

Many Python lovers I see just switched from C surroundings and were impressed with stuff like "Hello "+ "World" is "Hello World". So I would say this is the first scripting language that does not gathered esoteric/specific tag and so spread around among martyred people like fire in a dried forest. And so created fashion now lives on its own.

mbq
  • 1,210
  • 10
  • 20
2

Reapproaching the question now that I'm a little less tired:

Python is a language I've found particularly well suited for scientific programming tasks, which is one of the places where its popularity is growing pretty strongly. A few reasons why:

  • Fairly strong community support means there's some strong libraries in place, and Python works as a decent replacement for MATLAB and some of the other popular languages in that field.
  • It plays well with C when you do need speed, but often speed isn't really that necessary, so Python's interpreted nature isn't all that big of a deal.
  • I've found it to be a fairly approachable language without a huge number of what, to outsiders, feel like weirdly arbitrary syntax rules. It's pretty swift to translate between pseudo-code and Python.
  • "Take it or leave it OOP". A lot of scientific programming projects don't benefit all that heavily from extensive OOP. Some do. It's nice to have a language that can hop between the two easily.
  • Strong cross-platform support. Especially as what I work with rarely involves GUIs, I can pretty much rely on being able to send off a Python program to someone else without worrying about what OS they're running.

It's not the end-all, be-all of programming languages, but its a decent "Yeah, I probably have a tool to solve whatever problem comes up" language, which is probably why it's enjoying popularity at the moment.

Fomite
  • 2,616
  • 6
  • 18
  • 20
  • Besides all other items you listed, I think one of the most important items was "I can pretty much rely on being able to send off a Python program to someone else without worrying about what OS they're running.". This is also very favorable when you don't want to get stuck with type of operating system. – Tarik May 01 '14 at 17:40
1

Python is a very 'webby' language in both the frameworks available (Django, Zope etc) and in the easily importable libraries, which again cover many web functions.

For web developers making the move from just a HTML, CSS + JS skillset (anecdotally a large source of new programmers over the past few years), I think this makes it a very attractive proposition (ditto Ruby).

Also, Google isn't Microsoft....

Jon Hadley
  • 110
  • 5
  • Java isn't MS, so if your reasoning is correct, they would be moving to Java not python. There must be a different reason. – rox0r Dec 18 '10 at 07:09
0

I think one of the main reasons is that 90% google is made from Python.

However, Python is also an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, http://www.python.org/, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation.

The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications.

ocodo
  • 2,948
  • 3
  • 23
  • 31
blackhat
  • 11
  • 1