Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What classes of applications or problems do you prefer Python to strictly OO Languages?

I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading Programming Collective Intelligence. I understand that Python can solve any problem that C# can, and vice-versa. But I am curious to know from those who use both regularly, when they choose one over the other. Removing other factors, like coworkers experience, etc.

When do you choose to create an application in Python instead of a static typed, purely OO language like C# or Java?

Edit:

I was afraid we were going to get off topic a bit with this question. Python is an object oriented language. But, as is stated below it may not be the preferred language when your application will have a very heavy business domain, etc. I am aware that Python uses objects extensively, and that even functions are objects, something that is not true in all of the "OO" languages I brought up earlier.

Despite my poor choice of words in the question (almost no languages fit nicely into two or three word descriptions, and it is really difficult to point out differences in languages without it appearing that you are talking down to a certain class of developer.), I am still very interested in what you have to say about when you prefer Python to other languages.

like image 291
Matthew Vines Avatar asked Dec 01 '22 12:12

Matthew Vines


2 Answers

My motto is (and has long been) "Python where I can, C++ where I must" (one day I'll find opportunity to actually use Java, C#, &c &C, in a real-world project, but I haven't yet, except for a pilot project in Java 1.1, more tha ten years ago...;-) -- Javascript (with dojo) when code has to run in the client's browser, and SQL when it has to run in the DB server, of course, but C++ and Python are my daily bread on the "normal" servers and clients I develop, and that's the case in all parts of Google I've been working in in 4+ years (there are many parts using Java, too, I just never happened to work there;-). Hmmm, there's pure C when I'm working on the Python core and related extensions, too, of course;-).

Neither Python nor C++ are "strictly OO" -- they're multi-paradigm, and therein lies a good part of their strength in the hands of programmers who are highly skilled at OO and other paradigms, such as functional, generic, declarative, and so forth. I gather C# has pulled in some of each of these too (sometimes surpassing C++, e.g. by offering lambdas), and even Java has had to succumb to some (at least generic) to a tiny extent, so surely it's clear that "one size fits all" doesn't -- multi-paradigm programming is alive and well!-)

C++ (like C) forces me to control all memory carefully (our internal c++ style guide forbids the use of "smart pointers" that amount to poor implementations of garbage collection!-), which multiplies my work a lot, but helps ensure I'm not using one bit of memory more than strictly needed at any time: so, C++ (or C when needed) is the choice when memory is tight and precious. Otherwise, the extremely high productivity of Python (and Ruby or Javascript aren't all that different, if that's what you are used to) makes it preferable.

I'm sure there IS a niche in-between for a language that's garbage collected but mostly static, like Java (or C# before it started piling on more and more features, including dynamic ones in 4.0, I hear), or else those languages and cognate ones wouldn't be so widespread -- I've just never found myself inhabiting that peculiar niche, as yet.

like image 158
Alex Martelli Avatar answered Dec 05 '22 03:12

Alex Martelli


I select Python as often as possible. It is the most useful and productive programming environment that I know of.

If I run into projects where Python cannot be used directly or for the entire project (for instance a .NET-based app. server) my approach is usually to do as much with Python as possible. Depending on the situation that might mean:

  • Embed a python interpreter
  • Use Jython
  • Use IronPython
  • Use some IPC mechanism (usually http or sockets) to call an external python process
  • Export data - process using python - import data
  • Generate code using Python

From my answer to a previous question: I know C#. Will I be more productive with Python?


In my experience, what makes me more productive in Python vs. C#, is:

  • It is a dynamic language. Using a dynamic language often allows you to remove whole architectural layers from your app. Pythons dynamic nature allows you to create reusable high-level abstractions in more natural and flexible (syntax-wise) way than you can in C#.
  • Libraries. The standard libraries and a lot of the open-source libraries provided by the community are of high quality. The range of applications that Python is used for means that the range of libraries is wide.
  • Faster development cycle. No compile step means I can test changes faster. For instance, when developing a web app, the dev server detects changes and reloads the app when the files are saved. Running a unit test from within my editor is just a keystroke away, and executes instantaneously.
  • 'Easy access' to often-used features: lists, list comprehensions, generators, tuples etc.
  • Less verbose syntax. You can create a WSGI-based Python web framework in fewer lines of code than your typical .NET web.config file :-)
  • Good documentation. Good books.

like image 34
codeape Avatar answered Dec 05 '22 05:12

codeape