Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 10th, 2004, 02:47 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
Question Why Python?

I am presently reading the book "Learning Python" (2nd ed.) which I am sure many of you have read. I really like Python's syntax and clarity but several points the author makes cause me to sometimes question why use Python as opposed to a fully compiled language like Java or C. For example, I just finished reading the section about lambdas and other 'advanced functions.' The author says that these functions run much faster as opposed to 'hardcoding' their purpose with for loops, etc. Now I could be dead wrong or am stating my thoughts incorrectly, but aren't the built in functions written in C or if it is Jython, Java? The author seems to emphasize speed a lot. I have also read that critics claim Python is too slow. Why not just learn C or Java (even though the learning curve may be a lot higher) if the underlying logic of Python is C code or Java code (is that dead wrong?)? Also, how much "slower" is Python and when would the difference be detectable? (in other words, is this difference completely negligible to the amateur programmer?). I hope this post makes sense...Thank you!

Ryan Kaskel

Last edited by ryankask : June 10th, 2004 at 02:48 PM. Reason: some spelling

Reply With Quote
  #2  
Old June 10th, 2004, 03:11 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
To extend this question, because I realize it applies to other popular languages like PHP, etc., when does code stop being compiled or interpreted. Also, if you have language and it is compiled, what language is the compiler written in and what "understands" the compiler and then what "understands" what "understands" the compiler, and so on. When does a lanauge finally become understood by electronics...maybe someone catches my drift. Are there any book on understanding something like this? I did see one published by Microsoft (hard cover) which looked interesting...thanks.

Reply With Quote
  #3  
Old June 10th, 2004, 05:30 PM
orthoorange42 orthoorange42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 6 orthoorange42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by ryankask
... I did see one published by Microsoft (hard cover) which looked interesting...thanks.


Is the book you're referring to "Code"? Whether or not it is, I'd highly recommend it. It gives a very understandable and readable look at some of the lower-level events occurring in your computer. It might not explain exactly what you're asking, but it will probably help you better understand whatever answers you get.

It's been a while since I read it, but I don't remember any m$ propaganda in it. I remember that being my biggest concern when I bought it, but I was pleasantly surprised.

Reply With Quote
  #4  
Old June 10th, 2004, 05:45 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,221 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 22 h 21 m 4 sec
Reputation Power: 263
Quote:
Originally Posted by ryankask
Now I could be dead wrong or am stating my thoughts incorrectly, but aren't the built in functions written in C or if it is Jython, Java?


Yes, the built in functions are written in C (or Java).


Quote:
Originally Posted by ryankask
The author seems to emphasize speed a lot. I have also read that critics claim Python is too slow. Why not just learn C or Java (even though the learning curve may be a lot higher) if the underlying logic of Python is C code or Java code (is that dead wrong?)? Also, how much "slower" is Python and when would the difference be detectable? (in other words, is this difference completely negligible to the amateur programmer?). I hope this post makes sense...Thank you!

Ryan Kaskel


There are two sorts of speed. The first is program speed - how fast the code runs. The second is programming speed - how long it took to write. In general, C/C++ (and to a lesser extent Java) are much faster than Python in terms of program speed. However Python is much faster in programming speed.

Sometimes program speed is crucial, but not as often as you think. For programs that process large data files the bulk of the time is often spent reading the data from one file and writing it to another. File IO is slow in any language since it is limited by the physical speed of the disk, so using a faster language may not make a lot of difference. Similarly in GUI programs much of the time the program is idle, waiting for the user to press a key or click the mouse. So long as it can respond fast enough to not piss off the user then it is OK. It does not matter if it takes 10 millisecond or 100 milliseconds to respond as the user is not likely to notice, but a 10 second response would be a pain.

On the other hand programming speed is ALWAYS crucial. Here is an extreme example: imagine you are given a one-off data processing job to do. You could spend 8 hours writing a program in C++ or Java that took an hour to run, or you could spend an hour writing a Python program that took 8 hours to run while you went off and enjoyed yourself. Which would you rather do? Or if you were running a business would you rather have a Python project that took 3 months to deliver a product that was a little sluggish but still usable, or a Java project that took a year to deliver a product that was a bit faster (maybe)? Thats a difference of 9 months revenue.

Even in cases where program speed is important, most of the time is usually spent in a few bottlenecks in the code. If you can write the program quickly in Python then you have more time to spend optimising those hotspots, either by changing the algorithms, fine tuning the Python code, or recoding key functions in C/C++/Java. This explains the apparent paradox that while statement-for-statement Python is significantly slower than C++ or Java*, Python programs are often as fast or even faster than their compiled counterpart. There is also a Python compiler (psyco) that can significantly speed up Python code.

In summary, don't worry about speed until you really have to.

Dave - The Developers' Coach



* Actually the speed difference between Java and Python is not as big as you might expect. Both are compiled into an intermediate bytecode which is then interpreted. Java has an advantage in that it is statically typed so does not have to do dynamic lookups for every function call. Python has an advantage that some of the bytecodes are at a higher level so do more work for each instruction. These can cancel out to some extent.

Reply With Quote
  #5  
Old June 10th, 2004, 06:37 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
Thank you Dave for that great explanation!

Reply With Quote
  #6  
Old June 14th, 2004, 08:30 AM
iserlohn iserlohn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 15 iserlohn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by DevCoach
* Actually the speed difference between Java and Python is not as big as you might expect. Both are compiled into an intermediate bytecode which is then interpreted. Java has an advantage in that it is statically typed so does not have to do dynamic lookups for every function call. Python has an advantage that some of the bytecodes are at a higher level so do more work for each instruction. These can cancel out to some extent.


Partially because of this comparisons are very slow in Python and should be avoided. Use built-in sorting on complex data by applying the Schwartzian transform or somthing similar.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Why Python?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT