![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
My main attraction to Python is readability of code. I always thought that this was rather pythonic. Any other thoughts or disagreements?
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 4
![]() |
I don't really find it readable as you think. I do understand what the code does. But the formatting is not all that great. it is better to use braclet or begin and end like ruby does. Note i am not try to say that python is not good. But the way things are written in it makes it seems as if there is there a beginning but no end such
def blah(str):
print(str)
while(true):
print(str)
if(str == Nothing):
break
def dosomething():
print("something") |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
I sort of like Ruby's end, but on the other hand it is not always very easy to figure out where the end begins.
At least in Python I know that the colon starts the appropriate block indentation. However, mixed tab and space indentations, easy to do, can thoroughly ruin any Python code! I like Ruby and Python, they both have their strengths. Compared to C++ or Java, I feel like a kid in the candy store! So what do you call pythonic in Ruby? Rubiconic?
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 4
![]() |
Rubyist
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3
![]() |
I think C++ is way more readable, but then again I program it alsmot everyday.
__________________
I am Addicted to Linux! |
|
|
|
|
|
#6 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
I think some of the complicated list comprehensions are unreadable unless you've written them yourself.
Specifically the stuff I've seen Sane write... ![]() Getting back on topic, this is my impression of Pythonic. To make a reverse() function that will return either a reversed string, tuple, or list, I wrote this: def reverse(x): result = [x[len(x) - a] for a in range(1, len(x) + 1)] if type(x) == list: return result elif type(x) == tuple: return tuple(result) elif type(x) == str: return ''.join(result) Whereas Arevos' much more elegant, and "pythonic" code looked like this:
def reverse(s):
return { str : "".join, list : list, tuple : tuple }[type(s)](reversed(s))I think the differences are obvious :p
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! Last edited by Jessehk; Apr 6th, 2006 at 4:48 PM. |
|
|
|
|
|
#7 |
|
Professional Programmer
|
Basic is the most readable language (to me) but it isn't at all powerful enough to do anything I want. I like python because (to me) it has a very basic-ish feel to it.
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I thought pythonic was a man and woman with a non-sexual relationship
.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
With regards to the original question of this thread, I consider a program to be "pythonic" if it uses Python in an efficient manner, in terms of programming efficiency. For instance, this is a Pythonic way of returning two variables: def foobar():
return "Foo", "Bar"
a, b = foobar()def foobar(list):
list.append("Foo")
list.append("Bar")
list = []
foobar(list)
a = list[0]
b = list[1]Another thing to remember is that whilst Python is relatively small in syntax, it contains a number of tools and techniques that are worth knowing about. Looking around at some of the recipes on Python cookbook is a good way to learn about some of the more advanced tricks of the trade. The idea that pythonic code should be readable is also a good one. As a rough rule of thumb, I've found that better coders produce neater and more readable code than bad ones. This may be because the programmer is actively thinking about how to create readable code, or it may be because a good programmer will be thinking about the structure and architecture a lot more than a bad one, and this may reflect in the code itself. |
|
|
|
|
|
|
#10 | ||
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Arevos hits the nail on the head!
Quote:
Quote:
__________________
I looked it up on the Intergnats! |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|