Infinite resources

Nov 17, 2010 21:10

Remember driver's ed? I barely do. I don't remember how far before a railroad crossing I'm supposed to stop, or how far away from an intersection I have to be to change lanes. Probably the only thing I took away from it, the one mantra repeated over and over, is to slow downRaining? Slow down. Low on gas? Slow down. Bumpy road? Slow down. ( Read more... )

geeky

Leave a comment

Comments 8

two_pi_r November 18 2010, 06:32:21 UTC
One of my first programming tasks at the ol' alma mater was to take the horribly nasty perl script they were using for account management, pull the gigantic if-elsif-elsif-elsif-elsif-elsif thing they had, and construct a hash-of-functions to work with. From then on that's been my baseline software construction building block.

This python @funcs.append shit baffles me. Then again, Python baffles me; in Ruby we'd phrase this as
irb0> x = [lambda do
irb2* "hello"
irb2> end
irb1> ]
⇒ [#
]
irb0> x[0].call()
⇒ "hello"

Reply

eevee November 18 2010, 06:42:45 UTC
I've never seen anyone use that trick, and I sort of hope nobody actually does. But yes, it works.

Ruby requires an end dangling on every single block to allow anon syntax that's pretty darn ugly anyway. Python removes the noise and just doesn't support the ugly. 8) I am okay with this.

edit: Wait, .call()? Are you serious?

Reply

two_pi_r November 18 2010, 06:48:48 UTC
The .call is necessary because Ruby is a lisp-2, whereas python is a lisp-1.

The dangling end is a little annoying, but let's just think of it as a discouragement from nesting too deeply, shall we? Also, it isn't for the anon syntax specifically, it's for the yield/block thing.

I never got into python's decorator syntax, so, yeah.

Reply

eevee November 18 2010, 06:51:00 UTC
You need the end even for if/for/while/etc, don't you?

Decorators are way easier than anyone makes them out to be. This:

@exp def foo(): ...

is equivalent to:

def foo(): ...
foo = exp(foo)

And that is exactly all they do.

(So you will actually end up with foo == None in my code, because .append() doesn't return anything.)

Reply


krinndnz November 18 2010, 06:56:34 UTC
There are only two hard problems in programming, I'm told - naming things correctly, expiring caches correctly, and off-by-one errors.

Reply

eevee November 18 2010, 07:04:30 UTC
Every time we get a cool new gadget for the house, we spend a good half-hour sitting around trying to give it a good name before we can actually use it. :(

Reply


Leave a comment

Up