Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 16th, 2005, 8:43 PM   #1
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Only in python!

Only in python could I do things like:

for word in "This is a sentence".split():
     print word

or

numbs = range(10)

def kid(x):
     if x < 8:
          return x

for x in filter(mature, numbs):
     print x

or even

people = {"Bob":20, "Joe":25, "Anne":10}

for a, b in dict([(name, age) for name, age in people.items() if age > 15]).items():
     print a, b

I just feel like I am cheating.
Yes, the features in python are fantastic, but I somehow get more satisfaction from implementing it myself. Am I the only one?
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!

Last edited by Jessehk; Dec 16th, 2005 at 9:01 PM.
Jessehk is offline   Reply With Quote
Old Dec 16th, 2005, 9:50 PM   #2
MicDareall
Programmer
 
Join Date: Dec 2005
Posts: 67
Rep Power: 0 MicDareall is an unknown quantity at this point
Yes and No......... I feel real satisfaction from writing an assembly language program too .... but I would still much rather create projects with C\C+ then that..... and I would much rather create projects with Python then C\C+ for the same reasons..... I still get satisfaction from it....either way,,
MicDareall is offline   Reply With Quote
Old Dec 17th, 2005, 2:05 AM   #3
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Its not cheating, these are pythons features man :-)

These are the things that i love about python. But the higher the level of your programming the language, the more cool stuff like this are included. (IME)
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Dec 17th, 2005, 9:31 AM   #4
Master
Programmer
 
Master's Avatar
 
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 4 Master is on a distinguished road
you are not cheating, you can do that too in ruby.
Master is offline   Reply With Quote
Old Dec 17th, 2005, 9:53 AM   #5
Riddle
Programmer
 
Riddle's Avatar
 
Join Date: May 2005
Location: Nar Shaddaa
Posts: 42
Rep Power: 0 Riddle is on a distinguished road
Send a message via ICQ to Riddle Send a message via AIM to Riddle Send a message via MSN to Riddle
>>Master
Does that make it any less.. cheatlike?

I don't think it's cheating, or lame; the built-in functions are included for a reason. The reason? To be used.

This is cheating, in my opinion.
Riddle is offline   Reply With Quote
Old Dec 17th, 2005, 11:11 AM   #6
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
for a, b in dict([(name, age) for name, age in people.items() if age > 15].items():
Converting to dict and then calling items does exactly the same thing to the list as not having done so, unless you're trying to remove duplicate entries.

And you think these features are cool and make life too easy? Try reading webpages, writing/reading CSV files, dumping/loading objects from files, and using db files in C++ or C or even PHP or Perl.
Cerulean is offline   Reply With Quote
Old Dec 17th, 2005, 11:34 AM   #7
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by Cerulean
for a, b in dict([(name, age) for name, age in people.items() if age > 15].items():
Converting to dict and then calling items does exactly the same thing to the list as not having done so, unless you're trying to remove duplicate entries.

And you think these features are cool and make life too easy? Try reading webpages, writing/reading CSV files, dumping/loading objects from files, and using db files in C++ or C or even PHP or Perl.

Ya, I caught the pointless conversion to a dict and then to a list of tuples. Unfortunately, the edit button dissapeared. There is also an error the second code snippet where I define a kid() function and then call mature() with filter(). The specific examples are really not the point of the thread.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Dec 17th, 2005, 11:45 AM   #8
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Ya, I caught the pointless conversion to a dict and then to a list of tuples. Unfortunately, the edit button dissapeared. There is also an error the second code snippet where I define a kid() function and then call mature() with filter(). The specific examples are really not the point of the thread.
You were all excited about Python and made a few booboos. We forgive you! Python is something to be excited about! The language is much more modular than C++, so let's use those highly optimized modules.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Dec 17th, 2005, 4:11 PM   #9
Klipt
Hobbyist Programmer
 
Join Date: Dec 2005
Posts: 118
Rep Power: 0 Klipt is an unknown quantity at this point
It's hardly a case of 'only in Python' - more like 'only in high level languages'. The filter function you like so much is a functional programming feature which Lisp had fifty years ago. And with the right kind of libraries you can do a lot of those things in C++ or Java too.

Using a library isn't cheating if your goal is to write a program to do something which the library would make easier. It's only cheating if your goal is to learn how to write such code and understand how it works yourself. So long as you don't cheat yourself, I wouldn't worry. Or would you rather write everything in machine code? (Not even assembler, I'm talking about using hex code instead of mnemonics like ADD and MOV! :p)
Klipt is offline   Reply With Quote
Old Dec 17th, 2005, 4:34 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
The filter function you like so much is a functional programming feature which Lisp had fifty years ago
Your "facts" are bullshit, despite the position of Lisp as a seminal language. ('Seminal language' is my personal opinion.) Fifty years ago was 1955. List processing was being introduced (hopefully) into Fortran at that time. Possibly you're thinking of IPL. In 1956, John McCarthy began to develop the concepts behind what would become Lisp. Inaccurate souces will perhaps credit him with inventing it as early as 1958. The first complete compiler appeared in the early 60's. OO concepts were incorporated in Lisp in the 80's.
__________________
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC