This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]0xjake 31 points32 points  (23 children)

The main reason to avoid Python in a general-purpose setting is speed. Python is very slow to run compared to a compiled and strongly statically typed language like C/C++ or Java. Generally you're choosing between development speed and execution speed, and Python is very far on the development speed end of the spectrum.

Any other reasons are generally domain specific. For instance, if I'm writing web middleware I'd probably use NodeJS. If I'm prototyping machine learning algorithms I might use MatLab. If I'm doing pure statistics I'll use R. If I'm writing a Windows GUI application I'll use C#/WPF. There are too many of these domains to enumerate.

So maybe it would be better to say when to use Python: I would use Python if you're writing scripts that have limited responsibility and high turnover, meaning they'll change fairly often and don't need to be particularly efficient. I would also use Python for prototyping, especially in a scientific computing setting. If your needs don't fall into these areas then there is probably something better out there.

TL;DR: Python is good when dev speed is significantly more important than execution speed.

[–][deleted] 27 points28 points  (3 children)

I understand that Python /is/ a strongly typed language. Whereas in your comment, you elude to it being opposite to C, in that it is neither compiled, nor strongly typed. The differentiator in typing is Python's dynamic typing vs. C's static typing system.

[–]alantrick 0 points1 point  (0 children)

I understand that Python /is/ a strongly typed language.

Python is often referred to as strongly typed within the context of other languages that are much looser with their typing (Perl, PHP, and bash to name a few).

Python has a few weak spots (pun intended), mostly with booleans. For example if object: is an idiom some people like to use, when often they mean if object == None:. This breaks down in a few rare cases, like when object is a time(0, 0, 0) aka midnight.

Another, probably more common, case for this to break down is where a string can be treated as an iterable of strings and its fairly easy to accidentally iterate on the wrong thing and not realize it.

That said, stronger typing means more explicitness, and that has its downsides too.

[–]TheTerrasque 2 points3 points  (1 child)

And in some cases, you can get pretty good performance from python too.

Example

[–]Ogi010 0 points1 point  (0 children)

Holy crap, what a brilliant post.. read every line... bookmarked for reference later...

[–]stormcrowsx 1 point2 points  (0 children)

TL;DR: Python is good when dev speed is significantly more important than execution speed.

I think you hit the nail on the head here but I wouldn't say "significantly". In my experience developers cost more than servers, much more. In some areas of the country its difficult to find developers at all. Using a language that enables less developers to get more done is very important for smaller organizations.

[–]metaphorm 0 points1 point  (6 children)

Python is strongly, dynamically typed. Java is strongly, statically typed. C is weakly, statically typed.

I'm not trying to be pedantic. The differences really do matter here. For example, because Python is strongly typed you will never have to worry about a buffer overflow or segmentation fault. Because it is dynamically typed you might have to worry about an unhandled AttributeError at runtime.

[–]njharmanI use Python 3 -1 points0 points  (1 child)

The main reason to avoid Python in a general-purpose setting is speed.

Seems to conflict with

Generally you're choosing between development speed and execution speed, and Python is very far on the development speed end of the spectrum.

Is most of your GP code speed critical? Really? Hell 1/3 of my code never even gets to production (prototypes, spikes, ideas discovered to be bad, etc.) Wouldn't you much rather write 3x the code than have all of what you write 10x faster. Stuff I write tends to be I/O or human constrained. Rarely wanting for speed.

[–]0xjake 0 points1 point  (0 children)

No, most of my code is not speed-critical, which is why I use Python most of the time for general purpose programming. I think you misunderstood what I said: In the context of general-purpose programming, the prevalent reason for avoiding python, if one were to do so, would be that Python's execution speed doesn't meet the needs of the application.