Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, June 27, 2008

Blogging About Twitter Is Like Swimming About Bathing

It took me a long time, but I've finally got into Freebase. No, not that freebase, actually I mean Freebase, 'an open, shared database of the world's knowledge.' It's shares similarities with wikipedia and Google Base. What's cool about it (to me) is the query language. Would you like to give your daughter some examples of powerful women? Show her a list of Female CEOs of Public Companies in order of Market Cap. If it weren't one of the sample queries you can just click on, here's the query in Metaweb query language that would extract that info:
{
"query" : [
{
"employment_history" : [
{
"company" : {
"/business/company/market_capitalization" : [
{
"amount" : null
}
],
"/business/company/ticker_symbol" : [
{
"ticker_symbol" : null
}
],
"id" : null,
"name" : null
},
"title" : "Chief Executive Officer"
}
],
"hide:/common/topic/image" : [
{}
],
"hide:gender" : "female",
"id" : null,
"name" : null,
"sort" : "-employment_history.company./business/company/market_capitalization.amount",
"type" : "/people/person"
}
]

}


I'm not being facetious here, I think it's great that they're making an effort to semi-structure the web and make searching for info less of a crap-shoot. It's part of that whole semantic web thingy.

Anyhow, this might inspire your daughter, and she'll need that inspiration to deal with being taken away from you after she goes to school and tells people Daddy uses freebase.

I'm not being entirely facetious there, either. Naming the thing after the drug associated with Richard Pryor setting himself on fire and that scary scene in 'Boogie Nights' might make it difficult for Metaweb to reach Mr. and Mrs. Front Porch, as Guy Grand would call them. Anyhow, I respect what they're doing and this is one of those things where I'd be happy to be wrong.

Sunday, June 08, 2008

Oh yeah. I forgot to include the proof.

Re: a couple entries ago, the one where I engaged in EWD worship, I mentioned a nifty proof in his essay but left it out.

It's a cool proof because: 1) it requires no knowledge of math 2) it requires no knowledge of chess 3) it makes his point about looking at a set as a whole rather than bit by bit.

To recap, say you remove the 2 squares on opposite corners of a chess board. Prove you can't cover the remaining board w/ 2x1 dominoes.

The proof: those squares will be the same color (see chessboard). So you'll have 30 white and 32 black sq. Or 32 black and 30 white. It's not important which, the important thing is there are an unequal # of black and white squares.

Every 2x1 domino will cover a black and white square. So if there's a covering, there will be exactly the same number of black and white squares covered. Only there isn't the same number of black and white squares, so you can't. QED.

Saturday, May 24, 2008

Radical Novelty - Edsger Dijkstra and what might have been

Edsger Dijkstra is known for his many contributions to computer science, including but not limited to the algorithm named after him, structured programming, and the shunting yard algorithm. He's also famous for his ninny-eviscerating essays like 'Go To Statement Considered Harmful' (1968) and 1975's even more wonderfully titled 'How Do We Tell The Truths That Hurt?' (there are likely many country and western songs that share this title), which contains such deathless truths as these:
  • Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.
  • It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
  • The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.
  • Projects promoting programming in "natural language" are intrinsically doomed to fail.
Sadly, apparently nobody listened to him at all. Neither did anyone apparently listen to what he had to say in the equally brilliant 'On the cruelty of really teaching computer science', a 29-page manifesto whose words resonate so strongly with me 20 years later that I'm simultaneously thrilled and nauseated. Thrilled that somebody so brilliant would express ideas and attitudes similar to what's been boiling beneath my own impassive surface for years, nauseated by my tendency to go with the flow and firmly entrench myself as part of the problem. So what does he say? Well, for starters, he discusses the idea of a 'radical novelty', something that turns the world upside down and destroys the established order. In this case he's talking about computers. Dijkstra says when confronted with radical novelties we try to come up with analogies and metaphors to describe them in terms of our experience, but that in the case of a sharp discontinuity (a radical novelty) this approach is useless. The comparison he draws is to learning about quantum mechanics, a mind-fuck of an experience where thinking about Bobby and Suzy on a see-saw isn't going to do you a damn bit of good anymore. He then goes on to recount the suppression of and resistance to radical novelties throughout history: math's Michael Jordan, C.F. Gauss, is labeled a coward for keeping his discovery of non-Euclidean geometry to himself, fearing he'd get the Galileo treatment. He also recalls the story of King Ferdinand's visit to the conservative University of Cervena, where the King is assured by the Rector:
"Far be from us, Sire, the dangerous novelty of thinking."
Software Engineering comes under fire shortly after this. Though I've used the term (go with the flow), I've known real Engineers and what they do, and have considered it a bit of a joke myself (like calling a janitor a 'Sanitation Engineer'). Steve Ballmer and Microsoft side-step the controversy, preferring 'Developers'. Dijkstra's take:
Software engineering, of course, presents itself as another worthy cause, but that is eyewash: if you carefully read its literature and analyse what its devotees actually do, you will discover that software engineering has accepted as its charter "How to program if you cannot."
(It's funny because it's true.) Dijkstra then tells the truths that hurt about Artificial Intelligence:

Finally, to correct the possible impression that the inability to face radical novelty is confined to the industrial world, let me offer you an explanation of the --at least American-- popularity of Artificial Intelligence. One would expect people to feel threatened by the "giant brains or machines that think". In fact, the frightening computer becomes less frightening if it is used only to simulate a familiar noncomputer. I am sure that this explanation will remain controversial for quite some time, for Artificial Intelligence as mimicking the human mind prefers to view itself as at the front line, whereas my explanation relegates it to the rearguard. (The effort of using machines to mimic the human mind has always struck me as rather silly: I'd rather use them to mimic something better.)

So by this point Dijkstra has laid out that we have something completely new and incredibly powerful at hand, but by refusing to recognize it as such, we're blowing it, big time. Further, our efforts to get our heads around it by relying on analogies and metaphors are misguided at best, damaging at worst. As I look at my 'Desktop' and see icons representing 'Folders', I can see what he's talking about (but maybe I'm just too much of a die-hard command line UNIX guy). Since the essay promises something about teaching computer science being cruel, we are by this time wondering when Dijkstra will get around to that, and finally he does. He blasts traditional academia for buckling under the business elite, who dismiss traditional academics and intellectuals as largely irrelevant and powerless. He again rejects 'this guy talks to that guy' anthropomorphism of computers and presents a cool proof of the theorem that if you remove the two corner squares of a chessboard, it's impossible to cover what remains with dominoes that each cover two squares. Most would be tempted to use the fast and powerful computer to stupidly run thru all the permutations, Dijkstra shows that by thinking in terms of a set's definition (mathematical type thinking) instead of in terms of individual elements (brute force) - you can derive the answer much more quickly, just using your little brain. More importantly, the idea is if you think that way and try to approach the radical novelty that is the computer using ideas and thought processes from formal mathematics, you will see much better results than if you try to program a computer by connecting cartoonish machine icons to each other inside your IDE. What's funny to me (and I guess I'm alone here, I've really run on long I know, but this essay has been running through my mind all week now) is Dijkstra's proposed 'appropriate way to teach computer science' essentially involves teaching formal mathematics and providing a programming language that 'has not been implemented on campus so that students are protected from the temptation to test their programs'. Radical indeed, but familiar in concept to the math geeks out there. Sadly, today the focus and method is as far from Dijkstra's vision as it could possibly be. The focus is on teaching languages used in industry, with non-industry languages like Scheme used in some programs regarded as hoops to jump through and hazing to suffer through. Throughout the industry there's a profound dearth of imagination, a slog-through-it mentality, misplaced pride in taking what little one has bothered to learn to absurd extremes rather than to step back and think of a better, maybe even simpler, way. It's too bad, really, because in the words of the man himself:
Teaching to unsuspecting youngsters the effective use of formal methods is one of the joys of life because it is so extremely rewarding. Within a few months, they find their way in a new world with a justified degree of confidence that is radically novel for them; within a few months, their concept of intellectual culture has acquired a radically novel dimension. To my taste and style, that is what education is about. Universities should not be afraid of teaching radical novelties; on the contrary, it is their calling to welcome the opportunity to do so. Their willingness to do so is our main safeguard against dictatorships, be they of the proletariat, of the scientific establishment, or of the corporate elite.
So there you have it. Edsger W. Dijkstra is my lunatic fringe preacher, and I'm going to keep going to his church, consequences be damned!

Wednesday, March 12, 2008

Effusive Python Fan Love Pt 1 - Some Early Impressions

Just as Morgan Spurlock conducted an experiment where he put his health at risk by eating nothing but McDonald's food for 30 days, in 2005 I started an experiment where I put my career and sanity at risk by taking a job focusing on the use of Microsoft products. As part of that misadventure, I did some scripting with VBScript, a horribly malformed abortion that was at one point the scripting language of choice for ASP, the Microsoft Web Framework before ASP.NET MVC (way to go Microsoft, innovating by putting that MVC thing Xerox PARC came up with in 1978 in a product in 2008), before ASP.NET 3, ASP.NET 2, and ASP.NET aka 'the last web framework you'll ever need to learn'.

VBScript is such an abomination even Microsoft is now posting articles advising the faithful as to how to convert from it to Powershell, but a better option is to choose a proper scripting language, like Python.

Calling Python a 'scripting language' seems wrong, with the negative connotations of dabbling and sloppy (or malicious) code tied to 'scripting'. It's one of the approved languages within Google, who also hired the creator, Guido van Rossum (he works on it 1/2 time). Iceland's CCP games use a variant called Stackless Python well-suited to concurrent programming for their massively-multiplayer online game, Eve Online. It's also used in Civilization IV. So it's not something limited to sysadmin 10-minute throwaway scripts in any way, shape or form.

I learned Python a couple of times (and then went off and did something else, forgetting what I learned) before returning to it recently as part of the big Microsoft backlash (although Microsoft have hired the IronPython guy to work for them, and are wanting to have Python available as a development option for Silverlight Development via their DLR (dynamic language runtime). Until recently, Perl was the go-to scripting language, because writing code in Perl was like talking to the computer and asking it to do something. It was that effortless. It was, yes, fun! I decided to give Python a go in the ongoing interest of staving off senility and general brain rot.

This meshed well with my recent purchase of a MacBook, because Python 2.5.1 is already there. This site appears to be a good resource for Mac Python people, and the author recommends building from the source and going from there, something I may do in the future, but everything seems fine for my needs now.

Editing-wise, I played around with a few different editors before opting to go with Komodo Edit, from ActiveState and free. I have had fewer woes with improper indentation with Komodo Edit than with some other editors I've tried, and it has the nifty auto-completion. Eclipse has a plug-in called pydev, but Java skeeves me out more often than not.

As to fun out-of-the-box things I've noticed with Python, number one for instant gratification is the interactive interpreter. If you're unsure what a snippet of code will do, you just type python and are popped into an interpreter, which you can feed lines of code interactively and see what happens. It is part of the speedy development aspect of Python. Not only is the compile cycle gone, you get instant turn-around for little snippets or ideas.

Another nifty thing is easy_install. A killer feature of Perl is CPAN, a central repository for modules people have created, containing code they've written to solve problems lots of other people will likely need to solve, removing the need for wheel re-invention. While it's not quite at the level of CPAN, the Python Package Index is handy, and easy_install is great, because if for example you read an article about BeautifulSoup, the Python module to parse possibly poorly structured HTML (in other words, 99% of HTML occurring in the wild), you would type:

>easy_install BeautifulSoup

...and away you go.

So far I can report programming with Python IS fun, so apparently I don't hate programming after all, just programming involving the use of Microsoft products or overly cumbersome Java frameworks with xml configuration files from hell. Java pretty much evolved from 'cool new thing' to 'your father's Oldmobile' right before my eyes, and nowadaze so much Java development is outsourced/offshored/rightshored/whateverthefucktheycallitnow anyway I don't recommend it much for Americans, especially young Americans. At any rate I'd rather use a language as a means to an end rather than an end in itself, and Python fits that role nicely.

Saturday, December 01, 2007

I wish all Teddy Bears were named Muhammad



Back in 2006, the world didn't know how to act when a firestorm erupted over some cartoons in a right-wing Danish newspaper. Currently, people are freaking out in Sudan because a teacher allowed her students to name a Teddy Bear Muhammad.



In a show of solidarity w/ Ms. Gibbons (the teacher in question), and because I haven't posted a greasemonkey script for a while, below you will find a greasemonkey script that gives EVERY TEDDY BEAR ON THE WWW the name Muhammed. Above, a screenshot illustrates that there is a big community of TBNM collectors on eBay.



Christians are welcome to use this script to name all teddy bears on the World Wide Web Jesus, Rastafarians may use it to name all teddy bears Jah, and Satanists may use it to name all teddy bears Satan. Jews may use it to name teddy bears Moses or Sandy Koufax, jazz fans can use it to name all teddy bears 'Trane, the possibilities are endless, really.



The script:

// ==UserScript==
// @name TBNM
// @namespace none
// @description gives all teddy bears on the WWW the name 'Mohammed'
// @include *
// @version 1.0
// @homepage redacted
// ==/UserScript==
(function() {
var bad = [], good = [], modifiers = [];
// START CONFIGURATION
populate({
// Terms are listed as comma separated couples of words, in the form
// "Censored Word": "replacement"
// [Place custom word list below]

"teddy bear(s?)(?! named M.hamm.d)":"Teddy Bear$1 Named Muhammad",

// [End of custom word list]
}, "gi");
// END CONFIGURATION (don't touch anything below, unless you know what you're doing...
function populate(replacements, flags) {
var word, modPos, mod;
for(var key in replacements) {
if((modPos = key.indexOf("/")) > -1) {
mod = key.substring(modPos + 1);
word = key.substring(0, modPos);
} else {
mod = "";
word = key;
}
modifiers.push(mod);
bad.push(new RegExp(word, flags));
good.push(replacements[key]);
}
}


// this function does the replacements
function sanitize(s, noContext, notredirect) {

for (var j = 0; j < s =" s.replace(bad[j]," title =" sanitize(document.title," textnodes =" document.evaluate(" i =" 0;" node =" textnodes.snapshotItem(i);" data =" sanitize(node.data,">

More about Greasemonkey

You have to use Firefox for this to work. Sorry.

Tuesday, August 07, 2007

Learning about Learning LSL in Second Life

The Second Life backlash is in full effect, thanks in part to an article in Wired (How Madison Avenue is Wasting Millions on a Deserted Second Life) by Frank Rose, a journalist who made the shocking discovery that people don't want to spend their free time exploring the 'Coke Pavilion' or the 'Quaker Oats Hall Of Dietary Fiber' or other marketing efforts in this new space.

Further, the article implies that the companies that've sprung up to build these spaces for marketeers for stodgy companies that want to be cool might be taking advantage of misplaced enthusiasm. Sort of like the web design houses and professionals that took advantage of all the suckers wanting to get in on the irrationally exhuberant Web boom of the 90's, which I seem to recall Wired Magazine being around for. They weren't around for the California Gold Rush, where the people selling the pickaxes and such were the only ones making money, but they sure milked that analogy for all it was worth then, especially as things started to really turn to shit.

But I'm not here to defend SL, Wagner James Au will do that at New World Notes. This entry is about LSL, the Linden Scripting Language, and if it's true that SL is abandoned, you can probably find a nice quiet place to do some experimenting with building 3-D shit and then giving it functionality, which is one of the fun 'anything is possible' aspects to SL that people like Frank Rose are missing when they aren't missing their own reflection in a mirror.

Anyhow, with LSL basic programming (not necessarily BASIC programming) skillz are handy, but not necessarily required. It is not the prettiest language around. 'The New Hampshire Coder In Linden Lab's Court' calls it 'JavaScript after a lobotomy'. And it's true, it is not going to support large-scale development efforts. However, for some quick fun with 3-D graphics without having to blow the dust off your C++ book, it works nicely.

The LSL Portal is an obvious starting point (it's also an item in the help menu). The 'Scripting Guide' also under the Help Menu will be valuable as a reference (what are the arguments to that function?, that sort of thing), but as an intro, it's not so great. In fact, the intro caused me to completely lose interest in the idea of doing anything with LSL for months, until it crossed my mind again.

Actually, probably the best intro I found was this tutorial at the Kansas Board of Regents. As most people in the other 49 states can imagine, I was really shocked to discover I could learn something from the state of Kansas, but this guide is a nice intro to many aspects of scripting (particles, objects rezzing other objects, commands via chat, 'physics', etc), with examples. Of course there are millions of scripts on the wiki, but it's nice to get the info in a tutorial format.

As far as tools go, aside from the editor inside the SL client, there's an Eclipse plugin for scripting, which could prove to be handy for some off-line editing. There's also an LSLEditor which gives the developer a very rudimentary framework for debugging, however, there's really no substitute for trying out scripts in the 3D environment where you can interact with the objects you are scripting.

Finally, a particularly good sample script (set of scripts actually) is the sailboat library. Sailing is popular in SL as it is not whiplash-fast, but still requires skill since you are at the mercy of SL weather patterns, and can't just point in the direction you want to go and accelerate. Anybody can take these scripts as a starting point for building a sailboat of their own. For an airborne version, you can build a balloon or dirigible with your mind, or create robots which do bizarre stunts, or fireworks and the like with llParticleSystem, or whatever. The 'build it yourself' nature of SL is as I mentioned earlier both a really cool (because there's a ton of potential, and people do make some cool stuff) and horribly aggravating (people make some really hokey shit - scientists call it the 'MySpace Effect') aspect of SL, something marketeers have not figured out how to tap into or incorporate into a marketing effort at all (to be fair, it's not a trivial problem, or somebody would have figured it out by now). Anyhow, have fun, just don't create grey goo, scripts that hassle people, or the like, nobody needs that.