473,721 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic features used

I often use Python to write small programs, in the range of 50-500
lines of code. For example to process some bioinformatics data,
perform some data munging, to apply a randomized optimization
algorithm to solve a certain messy problem, and many different things.
For that I often use several general modules that I have written, like
implementation of certain data structures, and small general "utility"
functions/classes, plus of course several external modules that I keep
updated.

Compared to other languages Python generally allows me to write a
correctly working program in the shorter time (probably because of the
Python shell, the built-in safeties, the doctests, the clean and short
and handy syntax, the quick write-run-test cycle, the logical design,
its uniformity, the availability of standard data structures and many
standard or external modules, and the low number (compared to other
languages) of corner cases and tricky semantic corners).

Today Python is defined a dynamic language (and not a scripting
language, a term that few languages today seem to want attached to
them) but being dynamic isn't a binary thing, it's an analog quality,
a language can be less or be more dynamic. For example I think Ruby is
more dynamic than Python, Python is more dynamic than CLisp, CLips
seems more dynamic than C#/Java, Java is more dynamic than D, and D is
more dynamic than C++. Often such differences aren't sharp, and you
can find ways to things more dynamically, even with a less nice syntax
(or creating less idiomatic code). (In C#4 they have even added a
dynamic feature that may make languages like IronPython/Boo faster and
simpler to write on the dotnet).

In the last two years I have seen many answers in the Python
newsgroups, and I have seen that some of the dynamic features of
Python aren't much used/appreciated:
- Metaclasses tricks
- exec and eval
- monkey patching done on classes
- arbitrary cmp among different types removed from Python 3
While some new static-looking/related features are being introduced:
- ABCs and function signatures added
- More tidy exception tree

So it seems that while C#/D are becoming more dynamic, Python/
JavaScript are becoming a little less dynamic looking (and this I
think this is positive, because too much dynamism turns code into a
swamp, and too much rigid systems lead to bloat and other problems.
Note that there are another orthogonal solution: to use an advanced
flexible and handy static type system, as in Haskell).

I have seen that in lot of those little programs of mine, or in a
significant percentage of their lines, I often don't use the dynamic
features of Python (this means that the same code can be written with
static types, especially if you can use templates like in C++/D, or a
flexible type system like in Haskell, and it also means that lot of
those small programs can be compiled by ShedSkin/Cython, with usually
a sharp decrease of running time).

What are the dynamic features of Python more used in your programs?
(From this set try to remove the things that can be done with a
flexible static template system, like the D one, that for some things
is more handy and powerful than the C++ template system, and for other
things less powerful).

If very little or no dynamic features are used in a program it may
seem a "waste" to use Python to write the code, because the final
program may be quite slow with no gain from the other features of
Python. (I think in such situations Python can be a good choice
anyway, because it's good to write working prototypes in a short
time). (The large number of solution of this page shows how a certain
class of Python programmers want more speed from their programs:
http://scipy.org/PerformancePython and note that page misses many
other solutions, like SIP, Boost Python, ShedSkin, Cinpy, Cython,
RPython, and so on).

In the last year I have found two situations where exec/eval is a way
to reduce a lot of the complexity of the code, so if used with care
the dynamic features can be quite useful.

Before ending this partially incoherent post, I'd also like to briefly
remind how the dynamic features are used in the Boo language: Boo
programs are generally statically typed, but duck types are used once
in a while to reduce the "pressure" of the static type system. You can
find more info on this on the Boo site. (Note that I have never seen a
good set of speed benchmarks to compare the performance of CPython to
Boo).

Bye,
bearophile
Nov 21 '08 #1
5 2582
On Nov 21, 4:17*pm, bearophileH...@ lycos.com wrote:
I often use Python to write small programs, in the range of 50-500
lines of code. For example to process some bioinformatics data,
perform some data munging, to apply a randomized optimization
algorithm to solve a certain messy problem, and many different things.
For that I often use several general modules that I have written, like
implementation of certain data structures, and small general "utility"
functions/classes, plus of course several external modules that I keep
updated.

Compared to other languages Python generally allows me to write a
correctly working program in the shorter time (probably because of the
Python shell, the built-in safeties, the doctests, the clean and short
and handy syntax, the quick write-run-test cycle, the logical design,
its uniformity, the availability of standard data structures and many
standard or external modules, and the low number (compared to other
languages) of corner cases and tricky semantic corners).

Today Python is defined a dynamic language (and not a scripting
language, a term that few languages today seem to want attached to
them) but being dynamic isn't a binary thing, it's an analog quality,
a language can be less or be more dynamic. For example I think Ruby is
more dynamic than Python, Python is more dynamic than CLisp, CLips
seems more dynamic than C#/Java, Java is more dynamic than D, and D is
more dynamic than C++. Often such differences aren't sharp, and you
can find ways to things more dynamically, even with a less nice syntax
(or creating less idiomatic code). (In C#4 they have even added a
dynamic feature that may make languages like IronPython/Boo faster and
simpler to write on the dotnet).

In the last two years I have seen many answers in the Python
newsgroups, and I have seen that some of the dynamic features of
Python aren't much used/appreciated:
- Metaclasses tricks
- exec and eval
- monkey patching done on classes
- arbitrary cmp among different types removed from Python 3
While some new static-looking/related features are being introduced:
- ABCs and function signatures added
- More tidy exception tree

So it seems that while C#/D are becoming more dynamic, Python/
JavaScript are becoming a little less dynamic looking (and this I
think this is positive, because too much dynamism turns code into a
swamp, and too much rigid systems lead to bloat and other problems.
Note that there are another orthogonal solution: to use an advanced
flexible and handy static type system, as in Haskell).

I have seen that in lot of those little programs of mine, or in a
significant percentage of their lines, I often don't use the dynamic
features of Python (this means that the same code can be written with
static types, especially if you can use templates like in C++/D, or a
flexible type system like in Haskell, and it also means that lot of
those small programs can be compiled by ShedSkin/Cython, with usually
a sharp decrease of running time).

What are the dynamic features of Python more used in your programs?
(From this set try to remove the things that can be done with a
flexible static template system, like the D one, that for some things
is more handy and powerful than the C++ template system, and for other
things less powerful).

If very little or no dynamic features are used in a program it may
seem a "waste" to use Python to write the code, because the final
program may be quite slow with no gain from the other features of
Python. (I think in such situations Python can be a good choice
anyway, because it's good to write working prototypes in a short
time). (The large number of solution of this page shows how a certain
class of Python programmers want more speed from their programs:http://scipy.org/PerformancePython*and note that page misses many
other solutions, like SIP, Boost Python, ShedSkin, Cinpy, Cython,
RPython, and so on).

In the last year I have found two situations where exec/eval is a way
to reduce a lot of the complexity of the code, so if used with care
the dynamic features can be quite useful.

Before ending this partially incoherent post, I'd also like to briefly
remind how the dynamic features are used in the Boo language: Boo
programs are generally statically typed, but duck types are used once
in a while to reduce the "pressure" of the static type system. You can
find more info on this on the Boo site. (Note that I have never seen a
good set of speed benchmarks to compare the performance of CPython to
Boo).

Bye,
bearophile
http://scipy.org/PerformancePython is loading to slowly for my
connection. How ironic (though it probably isn't Pythons fault).
Nov 21 '08 #2
<snip>

You're right (I think), but I fail to see the point you're trying
to make or the question you're asking... :)

I use python for scientific research too, and for me speed can be
an issue too sometimes. By using numpy and scipy I have
an environment similar to Matlab in terms of speed and
functionality (but with a language thats much easier to code in).
C# or C++ etc would be faster, yes...
But what I find even more important is that my code is interpreterd,
so I can run some code from my editor, check some results,
run another piece of code, or make changes to the code and try
again. I've tried using C# for doing my stuff, but then the
compile-run step takes ages just too long... Plus in python you
can introspect all your varialbes using the python prompt.

Cheers,
Almar
Nov 21 '08 #3
Almar Klein:
but I fail to see the point you're trying
to make or the question you're asking... :)
It's not easy to define what my point was :-) I try again, but the
following questions don't cover all the points:
- What are the dynamic features of Python that you use in your code?
(excluding ones that can can be done with a good static template
system).
- Are them worth the decrease in running speed?
- Is it good for Python to become two languages in one, a fast
statically typed one and a dynamically one, like pypy shows to like
with RPython, or is it better to go the way of the Boo language, that
(while being mostly static) is mixing dynamic and static typing in the
same code, but that must rely on a very complex virtual machine to
work?
- Or maybe is it better to find other ways like CLips ones, that allow
to mix dynamic and static features, generally keeping programs fast
enough (Lisp-like syntax can lead to high performance too, as shown by
the Stalin Scheme compiler http://en.wikipedia.org/wiki/Stalin_...implementation)
).

Bye,
bearophile
Nov 21 '08 #4
On Nov 21, 4:17 am, bearophileH...@ lycos.com wrote:
What are the dynamic features of Python that you use in your code?
The main ones is using configuration files that are plain Python
instead of XML and not having to wait 5 minutes to compile larger
programs. I also prefer structural typing over nominative typing and
duck typing is closer to structural than nominative typing with the
difference that compilation doesn’t take forever but the disadvantage
that the checking doesn’t happen until runtime. Hopefully they will
keep improving pylint to generate warnings for all those.

As far as speed goes, there might be 5% of my code that I would be
willing to run through a slow compiler to speed it up. For the rest it
is probably not worth it.
Nov 21 '08 #5
On Nov 21, 7:55*am, bearophileH...@ lycos.com wrote:
It's not easy to define what my point was :-) I try again, but the
following questions don't cover all the points:
- What are the dynamic features of Python that you use in your code?
(excluding ones that can can be done with a good static template
system).
Off the top of my head, getattr/setattr are the most frequent dynamic
features I use.
- Are them worth the decrease in running speed?
- Is it good for Python to become two languages in one, a fast
statically typed one and a dynamically one, like pypy shows to like
with RPython, or is it better to go the way of the Boo language, that
(while being mostly static) is mixing dynamic and static typing in the
same code, but that must rely on a very complex virtual machine to
work?
- Or maybe is it better to find other ways like CLips ones, that allow
to mix dynamic and static features, generally keeping programs fast
enough (Lisp-like syntax can lead to high performance too, as shown by
the Stalin Scheme compilerhttp://en.wikipedia.or g/wiki/Stalin_(Scheme_ implementation)
Very valid points, and I also often think that dynamic typing is
overrated; most programs don't need to add or remove attributes at
will or change the class hierarchy. I don't know which of the
alternatives you mention would be better but I would welcome changes
towards the "static by default" direction, provided that (1) it *is*
still possible to write dynamic code if necessary and (2) the extra
effort in writing and reading it is not off-putting (e.g. no C++
template metaprogramming atrocities)

George
Nov 21 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1891
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October 24-28, 200) Organization committee: Roel Wuyts (primary contact - roel.wuyts@ulb.ac.be), Gilad Bracha, Wolfgang De Meuter, Stéphane Ducasse and Oscar Nierstrasz.
0
1486
by: only_me | last post by:
Not a coding question as such but highly related to asp/dynamic pages issues : has anyone any suggestions on the following ASP sites are generally (always) of a dynamic nature, pages can be built on the contents of querystrings, so search engines can only be directed to your first index.asp page since the search engine is unable to deduce what querystring parameters should/could be used. I have a company listing site and would like...
2
5366
by: Randell D. | last post by:
HELP! Its taken me ages - I'm a newbie and I've compiled bits of code that I've read in this newsgroup over time to create one of my most intricate functions to date... Basically, the script gets called with a single arguement (full path to an image). The image is supposed to be downloaded to the cache, and when complete, a new window opened that is slightly larger insize then the images dimensions... The new window will contain the...
13
2895
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when the user selects shirts another combo box called 'size' would contain sizes in relation to shirts (ie. chest/neck size). the same would occur for trousers and hats. when the user selects an option in the garment combo box, the options available...
2
4597
by: yzarc | last post by:
I'm working with a DB design that seems to me to be rather complex. This is a very slimmed down version of what I'm doing, but I believe it is enough to get my question resolved. Here is my layout. These 4 tables are used to generate a questionaire. Survey OrderID
0
2070
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab, System and Software Engineering Lab), ULB (deComp) and the Belgian Association for Dynamic Languages (BADL) are very pleased to invite you to a whole day of presentations about the programming languages Self, Smalltalk and Common Lisp by experts in...
0
1211
by: alexandre.bergel | last post by:
Dear colleges, You might want to consider Dyla'07 as a good venue to present your work and your favourite programming language. Regards, Alexandre **************************************************************************
0
1682
by: Alexandre Bergel | last post by:
Dear colleague, Please, note that after the workshop, best papers will be selected, and a second deadline will then be set regarding preparation of the Electronic Communications of the EASST. Note that we submission deadline has been extended. The important dates: - May 27: deadline for the workshop submissions. Submissions should follow LNCS format (www.springer.com/lncs) and should be sorter than
4
530
by: aarklon | last post by:
Hi all, recently a friend asked me is there any dynamic binding in C...?? to which i answered AFAIK it is in C++ only, but he says it is valid in C. if dynamic can be implemented via function pointers in C , can anyone give an example for dynamic binding in C...??
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.