Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Comment Re:Adventures in duck-typing (Score 1) 311

What you describe (that names are merely labels attached to objects) is more or less right, but doesn't capture what duck typing is.

Duck typing is summed up neatly by contrasting two principles: LBYL (look before you leap) and EAFP (easier to ask forgiveness than permission). These catchy phrases nicely capture two different methods. Consider these examples (numbered 1 through 4):

def square(value):
.. if type(value) != int:
..... raise ValueError('Argument must be an int')
.. return value**2

def square(value):
.. if isinstance(value, int):
..... raise ValueError('Argument must be an int')
.. return value**2

def square(value):
.. try:
..... return value**2
.. except TypeError:
..... raise ValueError('Invalid value passed')

def square(value):
.. return value**2

(Sorry about the prepended dots, but Slashdot's ecode tag is lame.

If you're used to statically typed languages, you may gravitate to the first two examples, but this is unpythonic. This tests that the type of the value passed is what you expect, and in doing so, prevents duck typing, because you can't pass it an object that acts like an int. (The second one is slightly better than the first, in that it will allow other objects so long as they are subclassed from int.)

The third example is better still, but why bother catching the exception at all? In doing so, you're passing less information in the exception than if you'd just done nothing at all, which is what example 4 does. Example 4 is pythonic: it allows duck typing (anything that supports __pow__ can be passed), and if the value is invalid, the TypeError exception automatically raised will be informative.

Comment Re:HDMI and Hollywood (Score 1) 603

Out of curiosity, what was the source your friend was using? If it was a Blu-ray player, that could be consistent with what I've heard. (That Blu-ray licensing terms rather than HDCP may necessitate downscaling on analog outputs. But I've not read anything authoritative on that.) But if it's a cable terminal, I'd be curious to know what cable provider was used.

I know that the DCT for my cable provider (Rogers) doesn't downscale over component, so I capture that way. And for Blu-ray, AnyDVDHD has been a worthwhile purchase. :)

Comment Re:28 lines in Prolog :-) (Score 3, Insightful) 311

in a Python doc comment, I'd be a rich guy. What is a foo exactly? A class? A tuple? A list of tuples of classes? Or worse, any of the above?

This is certainly one of the practical drawbacks of duck-typing. But name-based polymorphism is exceedingly powerful, and with great power comes great responsibility. (Namely, to document one's arguments and return values properly.)

Comment Re:HDMI and Hollywood (Score 1) 603

My understanding with HDCP licenses was that downscaling is only required when the ICT flag is enabled, and I didn't think the ICT flag was being used yet. (I seem to recall some agreement not to use it for some years, but maybe "some years" have passed.)

Blu-ray itself might be a different matter. I vaguely remember reading about Blu-ray licensing requiring downscaling through all analog outputs.

In any case, I'm very skeptical about your original claim that the TV (as opposed to the source) was downscaling HD signals coming in over component. I'm going to play the "citation needed" card on that one.

Comment Re:Because Americans are a Polity, not a Volk (Score 1) 622

This Canadian doesn't consider himself very patriotic. I see my relationship with my country primary as a business relationship: I provide payment in the form of taxes and agree to follow a certain set of laws (which more or less overlap well with my moral views anyway), and in exchange my country provides me infrastructure, social services, and a generally good quality of life.

If my country begins to piss me off and it's clear our differences become irreconcilable, I would take my business elsewhere, provided better options existed. (If I were American, for example, I'd have relocated to Canada some years ago.) To me, patriotism smells disturbingly like religion, with all the same blind allegiances and childhood indoctrination. It also provides one more vehicle for group-think.

That's not to say I'm not proud of Canada. I think we do a lot of things fairly well, relative to other countries. It's just not something I would put on the same level of what I consider patriotism.

Comment Re:But will it have free will? (Score 1) 630

I think you're making the assumption here that a deterministic universe is incompatible with any notion of free will. You can define free will a certain way so as to be incompatible with determinism, but there are good arguments to be made (and made very convincingly by, say, Dennett) that the kinds of free will worth having -- those needed for legal and moral accountability -- are perfectly compatible with determinism.
Science

Scientists Turn Tequila Into Diamonds 249

MaxwellEdison writes "Researchers, oddly enough from the National Autonomous University of Mexico, have found a way to make diamond films using tequila. They were originally testing methods of creating the films with organic solutions like acetone when it was noticed the ideal ratios of water and ethanol turned out to be about 80 proof, or 40% alcohol. '"To dissipate any doubts, one morning on the way to the lab I bought a pocket-size bottle of cheap white tequila and we did some tests," Apátiga said. "We were in doubt over whether the great amount of chemicals present in tequila, other than water and ethanol, would contaminate or obstruct the process, it turned out to be not so. The results were amazing, same as with the ethanol and water compound, we obtained almost spherical shaped diamonds of nanometric size. There is no doubt; tequila has the exact proportion of carbon, hydrogen and oxygen atoms necessary to form diamonds."'"
The Courts

Hacker Admits To Scientology DDoS Attack 275

lbwbl writes with news that a New Jersey man will plead guilty to one felony count of 'unauthorized impairment of a protected computer' for his distributed denial of service attacks on Scientology websites as part of 'Anonymous' earlier this year. From Wired: "He faces a likely sentence of 12 to 18 months in prison based on stipulations in his plea agreement, which also obliges him to pay $37,500 in restitution. ... Friday's case, in US District Court in Los Angeles, marks the first prosecution of an Anonymous member for a series of attacks against the Church of Scientology that began in mid-January. The secretive religious group strayed into Anonymous' sights after trying to suppress the publication of a creepy Tom Cruise video produced for Scientology members."
Microsoft

Microsoft Adding jQuery To Visual Studio 67

Tim Anderson writes "Microsoft's Scott Guthrie, Corporate VP of the .NET developer division, announced that the open source jQuery Javascript library will be integrated into Visual Studio, the main Windows development tool. Further, Microsoft will treat jQuery as a supported product within technical support contracts, and will use jQuery to build new controls for ASP.NET, its web platform."

Late Adopters Prefer the Tried and True 383

smooth wombat writes "There is a fairly significant portion of the population which does not go out and grab the newest OS, gadget, web browser or any other technology related product. Why? It's not because they're luddites but rather, they are comfortable with what they know. Take the case of John Uribe, a 56-year old real estate agent who still uses AOL dial-up and only recently switched to Firefox after being prodded for weeks by an AOL message telling him that on March 1st, AOL would no longer support Netscape. Why did it take him so long to stop using Netscape and make the switch? From the article: 'It worked for me, so I stuck with it. Until there is really some reason to totally abandon it, I won't.'"

Slashdot Top Deals

"You don't go out and kick a mad dog. If you have a mad dog with rabies, you take a gun and shoot him." -- Pat Robertson, TV Evangelist, about Muammar Kadhafy

Working...