Is python for me?

M

Magnus Lycka

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...

Have fun!
 
D

Danny Milosavljevic

Hi,

Yes of course python can handle of these things, but have you actually
compared them to something written in C? Even if the app was converted
into bytecode, it's still not as fast as an executable, that's all I am
saying.

I used to routinely write gui programs (data entry and such) in python
first and then ported them down to C for speed. I stopped the downporting,
isn't worth it, I just stay in python.

Make no mistake, python itself is slow enough. Its just that with today's
CPUs, no, even with CPUs 3 years old (mine is an Athlon XP), most
of the time slow is still faster than needed.

Once you start to do heavy-lifting in python, the picture becomes bleak,
though (I tried to write a Truetype Font Repacker
http://www.scratchpost.org/hacks/truetype-font-repacker/ without using any
external font libraries and its dog slow).

That said, most programming (for me also at work) consists of glue code.

And there still is that python to C++ converter, what was it called?
And python for dotnet. And Jython.
Those should help with speed a bit.

cheers,
Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top