Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

01-30-2013 , 10:50 AM
Quote:
Originally Posted by Urinal Mint
Ahh it's a key word! Thanks, that makes more sense now
A lot of yearrs of software development experience indicated to me that all you needed was to be pointed in the right direction.. Keep at it you're doing fine.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 11:08 AM
Quote:
Originally Posted by kerowo
What problem does using lambdas solve?
Guido van Rossum wanted to remove lambda from Python 3 entirely. It's only still there because he caved to popular demand. Really.

(I actually see the merit in that sort example, assuming the sort function is both simple and something you wouldn't want to implement by overloading '>' etc in a class. I mean it does turn 3 lines into 1, which is a win if the 1 is still legible)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 11:21 AM
Perhaps an interesting read by Van Rossum:

http://www.artima.com/weblogs/viewpost.jsp?thread=98196

I'm not too sure what enlightenment you would get from a Python lambda expression. It feels more like a tacked-on procedure than a foundational construct, but I could be missing something here.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 11:37 AM
I've only seen them used a lot in a data analysis book. The limit to one line makes them basically useless from a software perspective but to the science guys working in an IDE doing nothing but running functions on data sets and combining them back together, they save some lines of code.

Code:
strings.sort(key=lambda x: len(set(list(x))))
I've noticed this author likes to assign the lambdas a variable sometimes so he's basically just using lambdas to fit a function declaration on one line of code.
Code:
expanding_mean = lambda x: rolling_mean(x, len(x), min_periods=1)
Code:
compound = lambda x : (1 + x).prod() - 1
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 12:13 PM
I would disagree with lambdas being useless if limited to one line. Short little anonymous functions are things that come up.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 12:28 PM
fair enough

The one line thing just seems silly to me.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:11 PM
Quote:
Originally Posted by e i pi
fair enough

The one line thing just seems silly to me.
Python's use of whitespace all around is either brilliant or silly.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:28 PM
I think that Python's white space is brilliant, but I honestly can't figure out why lambdas are cool to use in Python.

square = lambda x : x * x

is better or worse than

def square(x): return x*x

????

Seems deceptive to me.

In the lambda expression, I am stating that square is a value or variable bound to the expression x*x. The second is creating a function that is defined to return the square of x. It is more silly because you call both with:

>>> square(5)
25

But if using an equals sign suggest binding a value or variable, then why does:

>>> square

simply tells me it's a lambda function?

Obviously, I understand why the above is true, but syntactically, it is very messy, IMO.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:30 PM
To me, the value of lambdas is when you're NOT assigning them to a variable. It's when you just want to pass it along to something as a one-shot deal.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:35 PM
Well, there is one great reason to use lambda's in Python:

** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:37 PM
Quote:
Originally Posted by Neil S
To me, the value of lambdas is when you're NOT assigning them to a variable. It's when you just want to pass it along to something as a one-shot deal.
I can definitely see it being useful in the original example, where you pass in anon functions to functions, but I'm still a little cool to the idea. I wish there was a really good example where it is much clearer though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:40 PM
Quote:
Originally Posted by kerowo
What problem does using lambdas solve?
carpal tunnel syndrome :P
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:55 PM
you use a lambda when it's the right tool for the job. if you don't know what lambdas are, you'll never have them in your toolbox when you need them.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:55 PM
Quote:
Originally Posted by Neil S
To me, the value of lambdas is when you're NOT assigning them to a variable. It's when you just want to pass it along to something as a one-shot deal.
I think even among people that like python lambda, assigning a lambda function to a variable is considered bad style. daveT's screenshot above is actually one of the reasons I've heard cited for it (as exceptions relating to the function now talk about some mysterious lambda thing instead of just using the function's name)

EDIT: And I mean, you're not even really saving significant typing or space because you don't have to put line breaks in a def if they're only one line.

Code:
def square(x): return x*x
25 characters

Code:
square = lambda x: x*x
23 characters

Last edited by Xhad; 01-30-2013 at 02:02 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:55 PM
I just love stuff like this for sorts, filters, and the like

Code:
>>> a = [1, 2, 3, 4, 5]
>>> filter(lambda x: x % 2 == 0, a)
[2, 4]
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 01:56 PM
Do any of you do strictly contract work? It seems like if you know what you are doing that would be the way to go. I would love to be able to work 4, 10 hrs days or even just work 4 8 hour days and make a little less money. Is this practical?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:02 PM
hippo,

when you pay someone to come and work on your house, you're cool if they take a random day off every now and then, right?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:04 PM
Quote:
A programmer had a problem. He thought “I know, I’ll solve it with threads!”. has Now problems. two he
-- http://theprofoundprogrammer.com/pos...d-a-problem-he

Last edited by tyler_cracker; 01-30-2013 at 02:05 PM. Reason: btw this is a riff on a famous jwz quote about regex
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:43 PM
Quote:
Originally Posted by tyler_cracker
hippo,

when you pay someone to come and work on your house, you're cool if they take a random day off every now and then, right?
Don't know how cool it is, but its certainly the defacto industry standard among contractors (the lumber kind) :P
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:53 PM
Quote:
Originally Posted by tyler_cracker
That is actually pretty funny.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:56 PM
Quote:
Originally Posted by fluorescenthippo
Do any of you do strictly contract work? It seems like if you know what you are doing that would be the way to go. I would love to be able to work 4, 10 hrs days or even just work 4 8 hour days and make a little less money. Is this practical?
I used to, and soon am going back to that.

Depending on the kind of work it is, you can set your own hours entirely. But you'd better be good at communication.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 02:58 PM
Quote:
Originally Posted by tyler_cracker
hippo,

when you pay someone to come and work on your house, you're cool if they take a random day off every now and then, right?
If I pay someone X dollars to deliver Y product on Z date, I don't care what days or hours are worked as long as I get Y product on Z date.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 03:16 PM
Quote:
Originally Posted by tyler_cracker
hippo,

when you pay someone to come and work on your house, you're cool if they take a random day off every now and then, right?
As long as they're up front about it, its probably not a big problem. I had a friend that would only do software consulting jobs that let him work ~20 hours a week.

I'm leaning towards doing contract work once I'm done with my current job. I think it can pay pretty well if you're good and knowledgeable about high demand subjects and even if you have to work full or long hours on specific jobs you have a lot of flexibility in taking time off between jobs.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 03:37 PM
Quote:
Originally Posted by gaming_mouse
Don't know how cool it is, but its certainly the defacto industry standard among contractors (the lumber kind) :P
What kind of tools do they use? Let me guess, Craftsman and Ryobi? Are they union too?

Last edited by daveT; 01-30-2013 at 03:45 PM. Reason: proudly non-union...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2013 , 03:44 PM
Quote:
Originally Posted by tyler_cracker
you use a lambda when it's the right tool for the job. if you don't know what lambdas are, you'll never have them in your toolbox when you need them.
panda.jpg
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m