* FAQ    * Search  * Register * Login 
Active topics
Unanswered topics

All times are UTC-06:00



Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [python] Having trouble seeing the need to use lambda, ever.
PostPosted: Tue Jan 15, 2013 8:45 pm 
Offline
DBB Artist
DBB Artist
User avatar

Joined: Mon Aug 01, 2005 8:47 am
Posts: 7124
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝
It seems to do exactly what a simple function would do, less the use of the return syntax and maybe writing parenthesis. That really doesn't save anybody time. The cost of a () and a return is insignificant. writing asdf=lambda x: is more work than typing def asdf (x):

Maybe lambda does something I'm missing? I think it goes against Pythons whole "there should only be one way of doing stuff" mentality. It probably should be removed.


edit: and this is for python

_________________
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ


Top
   
 Post subject: Re: Having trouble seeing the need to use lambda, ever.
PostPosted: Tue Jan 15, 2013 10:29 pm 
Offline
DBB Defender
DBB Defender
User avatar

Joined: Thu Feb 18, 2010 1:54 pm
Posts: 3409
Location: Mars
I've never used lambda. Maybe there is a practical performance reason for using it?


Top
   
 Post subject: Re: Having trouble seeing the need to use lambda, ever.
PostPosted: Tue Jan 15, 2013 10:30 pm 
Offline
DBB Master
DBB Master
User avatar

Joined: Sun Sep 05, 1999 2:01 am
Posts: 6377
Location: ☃☃☃
They're usually used for trivial one-liners, like if you have a list of dicts that you want sorted by their 'id' key,

Code:
list.sort(key=lambda x: x['id'])


Not everyone likes them, but I think writing a full-blown function to get the 'id' of a dict would be too verbose.


Top
   
 Post subject: Re: [python] Having trouble seeing the need to use lambda, e
PostPosted: Thu Jan 24, 2013 4:43 am 
Offline
DBB Master
DBB Master
User avatar

Joined: Fri May 28, 1999 2:01 am
Posts: 5426
ICQ: 28874658
Website: http://www.povterminal.net/
Location: Bellevue, WA
I'm not sure how much it differs from Python, but in languages like C++ they can come in pretty handy. It allows you to write callback functions pretty much in-line, sharing much of the context in which they're defined, as opposed to setting up a full function declaration and passing a bunch of variables as parameters, all for something you're only going to use once.

I've also commonly seen them used for generic algorithms; you can have a standard implementation of quicksort, binary search, or what have you, and use it on pretty much anything just by supplying a lambda that defines how to compare two items of an arbitrary type. Again, passing around function pointers would do the same thing, but if it's a one-off, they're a little more heavy-weight than you really need.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Descent'rs have piloted these pages
 
The layout and contents contained within this site are © DescentBB.net 1997-2006.
Descent, Descent II are © Parallax Software Corporation.
Descent III is Outrage Entertainment.
Descent is a Trademark of Interplay Productions.

Miner Wars™ is trademark of Keen Software House s. r. o.
.


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group