Is python for me?
lycka at carmen.se
Fri Nov 17 11:17:06 CET 2006
I think Python is for you.
> Can you define 'large'? Is that large in code, or large in database? I
> don't know which database is supported. If its a external db, like
> MySql, the query is performed through the software of MySql, am I
> right? If I'm correct, the 'slowness' comes from the amount of code in
> python itself, not from the database.
I'm afraid dakman's comment wasn't really very helpful.
Size is not a problem in itself. Ok, if the code modules are very
large, you will have a larger startup time, but this is probably
even worse in lower level languages such as C/C++. The python byte
code works at a higher level of abstraction than machine code, so
the byte code files are much more compact than corresponding
executable binaries from e.g. C/C++/Delphi.
The Python programming language, with its classes, modules,
packages etc is in my experience much better for writing large
applications without causing a mess than e.g. C++. It's much
easier to make a mess with C/C++'s "#include" than with Python's
"import". The lack of static typing means that some problems that
the compiler/linker would find in e.g. C++ development won't turn
up until you test your code in Python, but you'll get to testing
much faster with Python, and if you don't test well, you'll fail
with any larger development project however clever your compiler
and linker is.
Due to Python's very dynamic nature, there are a lot of operations
that will be much slower than in e.g. C or C++. For instance, if
you write "a = b + c" in C, the compiler knows at compile time what
types a, b and c are, and if they for example are ints, the addition
will be translated into a few very simple and quick machine code
instructions. In Python, the types typically won't be know until
runtime. This means that the objects need to be inspected during
execution to figure out what + means for these kinds of objects.
Python also handles memory allocation etc.
The consequence of this is that some kinds of programs that do
millions of trivial things, such as cryptography applications
where there are a lot of repeated multiplications and additions,
would be much, much slower in pure Python than in pure C. This
doesn't mean that Python is bad for a large group of applications.
It means that for a large group of applications, there are some
parts (for instance computationally intensive or e.g. interfacing
with some kind of devices or third party products) that should be
handled by extensions written in e.g. C.
Whatever you plan to do, it's likely that the extensions you need
already exists. There are such extensions for databases, networking,
maths, cryptography, XML parsing, etc etc. I'm a programmer working
with C, C++, Python, SQL etc, and despite 10 years of Python coding
I never actually needed to code any C extension myself yet. It's
very likely that you'll get away using 100% pure Python too. Note
that large parts of your programs will be C code, but C code you
didn't have to write yourself, and as far as your programming is
concerned it could as well have been Python, it's just that things
will run faster than if it had been pure Python...
More information about the Python-list