2009-07-29

Stupid perl Tkx tricks, part 1 in an ongoing series: Tkx::tk___dialog

I'll drop snippets of code here when I get stuff to work.

I've been programming desktop tools with perl/Tkx for work. I know that some may call me insane for doing so, but I am fairly well versed with the language, and I like how it allows me (most of the time) to get stuff done, instead of fighting me. For the Tkx part of my work, I've been leaning heavily on Tk Docs.

While Tk docs is a GREAT resource (and I'll be sending this post to the maintainer of it), it is far from complete. Today, it was "the standard dialog boxes that I've found are not sufficient for my needs".

To expand: I needed a dialog that had 3 buttons titled "Yes", "No", and "Yes to All". None of the standard dialogs have this. The closest uses "Cancel" as the third button, which, while it would *work*, I think that it isn't really nice to treat the user that way. Or teach them bad habits.

Since Tkx is basically (by my understanding) translating Tkx specific perl directly to Tk commands, most (if not all) of the Tk reference commands should work. I found that you can make custom dialog boxes with buttons that return numbers corresponding to their position in the list with Tk, using Tk_dialog. To implement this with Tkx in perl, I used the following


use strict;
use Tkx;
my $user_response = Tkx::tk___dialog(
    "[window name]",
    "[window title]",
    "[text in body of dialog]",
    "[tk bmp library icon (may be left empty)]",
    "[default button (may be left empty)]",
    "[button 0 text]",
    "[button 1 text]",
    "[button n text]",
    );


$user_response will return a number corresponding with the button number. The dialog box *does not* blend well with the OS widget set, at least with ActivePerl 5.10 on Win32. The icon (if you use one. I haven't dug for a list of icons yet) is a black and white icon, and the font used in the body text does not match what is used everywhere else. The *buttons* do use the proper widget settings, however.

2009-06-20

On failure...

This was brought about by a simple question posed by another: "If you could do one thing, with the guarantee of success, what would it be?". The follow up question was "Why are you not doing it?". Many in comments reflected that there is no such thing as a guarantee of success.

One definition of failure: an event that does not accomplish its intended purpose.

Yeah, that happens a lot. To all of us.

It's often not a good thing. It's nothing we strive for consciously.

But is it *always* a bad thing?

Let us set aside for a moment the idea that failure is always a bad thing, and focus on what failure represents.

To fail, in the definition represented above, must first be preceded by a purpose of goal.

One definition of purpose: an anticipated outcome that is intended or that guides your planned actions.

Taking these two ideas together, I submit that, while there is no reward in failure, there should not necessarily be shame in it either.

A person who failed has a dream, that they attempt to make reality. Just the initiative to step out of the safe zone to try can be cause for at least an appreciative nod. How many of us have stuck our neck out for some purpose we deemed good enough? How many of us even have a purpose better than "work 40 for a paycheck"? These questions make me uncomfortable myself.

Failure does not have to be the end of a goal. It is a set back. Ask anyone who writes code for a living. You write, you compile, you test, you debug, and repeat. If failure ended every goal, we'd still be writing with sticks in the sand.

Giving up, on the other hand, has no reward, except for lessons learned on the path. I speculate that in giving up, we give a tacit nod to the idea that perhaps our goal was ultimately unworthy of the time and energy we put into it. This is another admission that gives me uncomfortable pause.

In my profile, I give a sentence to dreams, failure, and surrender. I think it's worth quoting here, despite the fact that it may be somewhat self serving: "I find that dreams are malleable, and even if left unachieved, the ride can still be entertaining and rewarding, even if heartbreaking and depressing."

In my past, I have tried to realise dreams that I felt were worthy. I have failed miserably in them, due to a number of reasons. Some of my own doing, some because people suck. I am included in the latter statement as well. In the end, I am the one who made the decisions that I did that led me to the failure, and eventual shelving of these dreams. In that surrender, I have learned that sometimes, even tenacity cannot make some things work. "All of your decisions are half chance. So are everybody else's". There is wisdom to be gleaned from that statement, more than it would appear. I leave the analysis of that as an exercise to the reader.

Someone has to make fries. Just remember, they may have big dreams that they wanted to fulfil as well. They may just have been "right place, wrong time", and had to let them go because of other decisions they made. They may have been unrealistic. They may have been inane and unworthy goals. If they had the initiative to *try*, they have been true to the human spirit.

Find a worthy goal. Grind at it until you succeed. Mine is currently be the best husband and father I can.

2009-02-08

Writing believable antagonists

One of my pet peeves in most fiction is the lack of a believable antagonist. Here's a small selection of bad antagonist ideas that are used across the board:


  • Evil for evil's sake. This antagonist has no real reason to be evil/do evil, they just do it because they can.
  • Evil because it can grant immortality. This antagonist has latched onto an idea that promises immortality, yet to do so, they have to perform some sort of horrific act that any sane thinking person would not do.
  • Evil by nature/nurture. This antagonist was "born into" whatever position that they are in, be it a psychotic serial murderer, or dictator that is to "carry on the tradition of their lineage".


Bleh. Drivel. Some of it can be entertaining drivel (Harry Potter is a current example of this), but really, it's at best brain candy, as opposed to good stories.

Let's put aside the evil versus good discussion for a moment and discuss psychology for a moment.

Most antagonists are human, or (as in most fantasy settings) have similar mores to humans concerning the basic principals of life and the treatment of others. Most people have some sort of internal moral compass. Some may not match our own, but they have a set of morals that guide their decisions. Most people would rather be left alone to their own devices. "You let me play here, I'll let you play there, we'll be kosher." There are outliers, power grabbers, those that wish to be benevolent dictators, but honestly, most of us want to do our own thing, and not be bothered too much.

Now, before we continue with the idea of believable antagonists, let's look at what makes a great, believable protagonist.

Most good fiction is written in such a manner that the reader tries to put themselves in the shoes of the protagonist. We live these characters lives with them. We hurt when they hurt. We celebrate internally their victories. Good protagonists we can empathize with. They breathe. They live in our minds. The best protagonists will move our emotions and lives in such a manner that it gives us pause as we reflect on our own lives and wonder how better to emulate the good qualities of the protagonist.

One of the most common definitions of "hero" is "a man distinguished by exceptional courage and nobility and strength". I refine this further by saying that a hero is "a normal person performing extraordinary feats in extraordinary circumstances".

A good hero we can click with. We *want* them to win. We *want* Joe Sixpack to become an avenger and kick the crap out of people who deserve it. We *want* to be that person, because, from our perspective, they *are* the everyman, living with unspeakable demons in their lives, and dealing with them in a manner that idealizes the human spirit of tenacity and justice.

So, with the above in mind, let me break down what to me makes a believable antagonist:

  • They are the same kind of person that the hero is. The best antagonists are cut from a similar mold that the protagonist is. The closer the better. It lets us know that there *is* a darker path that the protagonist could have walked, but chose not to because of decisions made, and events witnessed.
  • They have a noble goal. The thing they fight the protagonist for is admirable. They desire good ends to their actions. They believe, and can make you believe that their goal is just.
  • They, like the protagonist, believe they are on the right path to reaching their goal. They have considered options, weighed consequences, and struggled with the decision that they have come to. They walk the path they do, not because it is right, they walk the path because it is the only way they see they can attain their goal.


Get close on the three above, and you'll have a readable antagonist that is a worthy adversary to your everyman hero.

An example of a *great* antagonist, from the most unlikely of places, Hollywood: Magneto from "X-men, the movie".

Magento and his adversary Doctor Xavier are very similar: Both (while extraordinary) are cut from similar molds as people who have extraordinary abilities. They both have the same goal of integrating these extraordinary people that have started evolving from humanity into the rest of humanity in a manner that they can coexist peacefully.

Magneto, however, has come to the conclusion that humanity will not accept this new stratification, these superior beings, peacefully, if at all. The rest of humanity will only accept this if the leaders of the world deem it necessary for them to do so. His plan is to forcibly cause this transformation in the leaders of the world. Even if it may cause the death of some or all of these leaders.

That, my friends, is an *excellent* protagonist, and the story told is wonderful.

2009-02-04

Concerning zombies

I've had a few friends try to get me involved in one of Valve's latest games, Left 4 Dead. I keep telling them "zombie hacking isn't my gig.". They keep telling me "But it's a cool game!", and list off lots of reasons concerning the AI, objective based play style, and other things. If I didn't have other things vying for my attention, and a bit more disposable income, I'd consider it.

However, since there's obviously interest, why not list a few things that have piqued my interest that do refer to zombies?:

A fan made music video of the Jonathan Coulton song "RE: Your Brains". Typical Coulton funny. The juxtaposition of loose, jangly guitar music with heavy pop influences and the subject material of the lyrics just makes me laugh.

A fan made music video of the No More Kings song "Zombie Me". Similar description as above.

Wikipedia article concerning the novel "World War Z", which is supposed to be a great book. I've been meaning to borrow it from one of my friends for a while now.

2009-01-16

Why I prefer Open Source for most things.

This is a rant that I've had for a while. I've finally articulated it properly now, in a conversation with my boss. This post refines and expresses those ideas further.

It typically makes no business sense to use closed tools. If it's an operating system, a desktop application, or a service. Here's why:

It's all about the data, dummy.

None of us really cares *how* we get the data we want. We just want the data that we need, if it's music, video, text, photos, whatever in the least painless method possible.

So, assuming we agree on the fact that it's all about the data, it's a small step to reason that the tools on the back end *really* don't matter anymore.

So why use tools that cost money for something you can't modify?

To be more specific, why not use tools that don't cost anything, that allow you (or someone you hire) to write other tools for you, with all the code there for you to make modifications to suit your environment?

With closed source stuff, you get whatever documentation the vendor gives you, whatever APIs the vendor gives you, and maybe some undocumented stuff that you or someone else has found. If you can't get it done, you have to switch tools, sometimes with great cost fiscally and training. On top of all that, you have licensing issues to deal with, sometimes becoming a complete nightmare in tracking what machines have what software and moving said software around as machines get retired or repurposed.

I know the problems with training someone on a new version of a piece of software. Office 2007 for example has made things terrible by pitching the entire interface that was being used into the can and placing an entirely new interface in front of the user. Why not move to OpenOffice at that point? It will import nearly every document produced by anything. Even Office 2007 documents. It can save in most formats too, but that is mostly a moot point. It'll even dump pdfs, which is available on almost every device and OS under the sun.

That's just one example. Here's another that hits closer to home for me:

We have an appliance made by a company. It produces the very heart of our work for us. The company builds a custom piece of hardware they stick inside of a commodity box. This custom card has drivers that the company writes, as well as a software package to utilize all the functionality on the card. Sounds like a perfect place to use open software to keep costs down.

The thing is, they haven't. They run Windows Storage Server 2003 on the box. It ships with a copy of Office on board. It has a commercial editing tool to edit the data that it generates. It ships with commercial recovery software, commercial anti-virus software. They could have used open alternatives, paid another developer $150000 for a year to work out the issues that they found with the open software, and still sold the appliances for the same cost as they do now. I figure they have at least $1000 to $2000 in commercial software on the box. Sell 150 appliances, the developer is paid for, as well as all the licensing. No other investment required, except for the next version of the software/hardware combination that will need to be authored. You could contract the developer instead of hire them and keep that cost down even further.

There are plenty of other examples and places for open tools as well. Mail, web services, going so far as to operating systems. Ask Ernie Ball. Roasted by the BSA to the tune of $65000, and another $35000 for lawyers to talk them down to that number. Due solely to licensing.

Open tools allow you to build wrenches and understand completely the weaknesses and strength of your new wrench.

And let's be honest: We all like good tools.

Pictures of Alex

http://s549.photobucket.com/albums/ii367/mrsslaq/

2009-01-06

Welcome Alexander James Ellis!

8 lbs, 6 oz, 20.25". Healthy. Pics coming sometime tonight.

Doc says "It's time"

Doc says that with all the monitoring looking like it is, a c-section is the way to go now. We'll be in the O. R. within the hour.

Progress report

No progress, but lots of pain. Drugs on the way, thankfully!

It's that time.

As many of you know, the Mrs.is great with child. The doc is saying too great. Today is the 42nd week of the journey. Apparently, after this time the likelihood of complications due to size and other issues.

We're both nervous and excited. It will be an interesting next chapter to our lives.

More news as events warrant.