Wednesday, July 25, 2007

Ruby : Fall through if your closure is empty?

Today my designer asked me if there's an easy way to take something like this:

<% Thing.find(:all).each { |t| %>
  Your thing is <%= t.name %><br/>
<% } %>

and add something that says "And if there were no Things found, do this other thing."

Good question!  I googled around for a bit and tried a handful of things, but couldn't get it to work the way I liked.

I found one way to do it.  Not sure it's the greatest, but it works.  Maybe somebody can chime in with a more "right" way to do it:

<% Thing.find(:all).each_with_index { |t, @thing_index| %>
   Your thing is <%= t.name %><br/>
<% } %>

<% if @thing_index == nil %>
  You poor soul, you have no things.
<% end %>

If the loop does not execute at all, @thing_index gets no value.  I'm using @thing_index instead of just thing_index, because the latter would be local to that closure and no longer exist outside of the curly braces. 

 I am sure that my syntax leaves something to be desired, there's probably a much more compact way of doing the actual fall-through check.  I did it the way I did so that I could tell the designer "You fill in this block here" and have it clearly delineated.

Monday, July 23, 2007

There Are Two Kinds of Demos

If you code for a living, chances are that you'll eventually have to do a demo.  If you're lucky it'll be one of the good ones.  Because, really, there's only two kinds of demo.

The first is a customer, or external, demo.  Maybe the customer is really "company executives who don't know you from a hole in the wall", but still, customer demos always go the same:

  • You want it scheduled as late in the day as possible, because it feels like you're never really ready for it.  You come in that morning thinking "I only have until 3 to finish this."  If it's put off for another day, you're excited about the extra time you get.
  • You're incredibly nervous during the whole thing that you're going to make a stupid mistake, because you know that's what they'll remember.
  • Customer demos are typically a team effort, where one engineer is selected to do the actual presentation.  This means that you're getting the heat if anything goes wrong, even if it was not your code that did it.
  • No matter how hard you work, nobody's really going to care.  Most of the people in the room don't want to be there and don't really understand what they're being shown.
  • 10 times during the demo you will seriously consider finding a new job, or perhaps just throwing up.
  • If anything catches anybody's eye it will be the animation or the fonts or the color, or some other shallow, trivial detail that has nothing to do with the architecture of what you built.
  • Chances are very good that you'll have to do it all again in a few weeks.

Compare to the internal, "prototype" demo.  This time you're demoing to your peers, and it couldn't be more different:

  • You're bouncing off the walls with excitement at getting to show off what you've done.  Your meeting is scheduled at 10, you arrive at 9 and it's frustrating to you that you have to wait an hour because you want to keep tweaking on the code.  If the meeting gets delayed you're royally pissed off because darnit you want to show it now!
  • You're a frickin rockstar during your presentation.  You are so confident in what you've built that when there are little snags you just say "oops" and move on to the next thing.
  • Your peers are actually listening, and can actually ask intelligent questions about how and why you did certain things a certain way.  And you're glad to answer those questions, up to the point where it starts to take away from your demo because you know that you're not going to have time to show off all of the greatness if they keep talking.
  • Peer demos are very often solo efforts, so it's entirely on your shoulders whether it works or doesn't. This somehow manages to comfort most engineers, who wouldn't have it any other way. 
  • The people in the room are going to acknowledge your hard work.
  • You actually don't want people to dwell on any one aspect as the "best" part because it's all good, damnit.
  • While talking you're also thinking up new features you haven't added yet, and solving problems that you hadn't yet solved. 
  • At the end of the meeting you offer to do it again in case anybody missed it.

For a period of time I worked at a big stuffy bank.  "We have 6 week deliverables," some random VP told me. Every 6 weeks an army of executives in white shirts and dark blue suits would parade over to our side of the office for their demo.  The night before I watched as the project manager got grilled by his managers, memorizing the script they'd worked out.  He regularly threw up before the demo.  And the most he ever got out of it was a list of things they hadn't gotten into the release (that were due for the next one, of course) and stuff that was broken that had to be fixed, and see you in six weeks. 

Then I went to work for a big company where marketing ran the e-commerce group and they liked them some demos.  True story, I once promised them a demo for a meeting, but the demo was incomplete when my boss came around to tell me the meeting was starting.  I was so pissed off at myself that I finished what I needed in the next 15 minutes or so, went upstairs and actually slipped my boss a note in his meeting that said "Demo's ready if you still want it."  They did, so I came in, did my demo, and then the marketing guy running the show said, "Well, Duane's the only thing that actually accomplished anything today, and I think it's going to be even cooler than we thought it was.  So I think that merits a round of applause."   A little appreciation goes a long way.

What's the point, other than to point out what we as software people already know?  I'm wondering if you can bridge the gap, and bring a little bit of the good stuff over to the dark side of the customer demo.  Let's see:

  • The schedule is what it is.  Once you've got something you agree is ready to demo, then put it aside, stop working on it.  Whether the meeting is at 9am or 4pm, if you keep touching it up until the last minute you're going to leave yourself in a bad situation because there's almost certainly going to be something broken or half completed in there that you have to explain at the last minute.  Don't do it.  Freeze it.  Check it into source control, tell your boss, and then go do something else until demo time.
  • In almost any room there are going to be people who are listening to you, and perhaps even interested, even if they don't know what you're talking about.  Find those people.  Then, concentrate your efforts on them and ignore the old bald heads who are checking their blackberries while you're talking.  The fact that someone is listening to you, will help remind you that you're not totally wasting your time.
  • If people want to be the most impressed with the way the form animated itself on submission, and don't seem to care about your n-tiered architecture, let it go.  They are either users, or they are representative of users, and that's the sort of thing that the user sees.  Save your architectural vision for your peers. 
  • Confidence in what you're doing goes along way toward doing it well.  Mistakes have a way of creeping up on you if you let them.  Slow down.  Breathe.  Pace yourself.  Focus on the parts that are going right, don't panic over stuff that might go wrong.  When you are among your peers you tend to do this naturally because you're not thinking your job is on the line if you make a mistake. 
  • The entire tone of your presentation will often come down to here's how much we accomplished, or here's how little we've accomplished.  It's entirely in your control how you spin it.  If you keep saying "We didn't get to this, and in the future we want to do this, and it doesn't do this yet...." you're leaving your audience with the wrong impression.  Your fellow engineers will hear such things as, "Yup, long term strategy, ok, makes sense, there's a bigger vision that he's working towards."  Customers, however, will hear such things as "What's that?  It's not finished?  Oh, well, let us know when it is."

You can come out of a customer demo with one of several outcomes:

  • I aced the demo, and they really seemed to like it.
  • I aced the demo, but they didn't really care one way or the other.
  • I got torpedoed when they started talking about things that were never supposed to be in the demo, so it looks like we blew it when we actually had something good.
  • We were totally not ready for that, that sucked.

Three out of four of those actually mean you did a pretty good job.  You might be frustrated by the results, but that doesn't have anything to do with how much you accomplished in getting your produtc ready.

Really there's only one thing to fear when doing a customer demo, and that is "If they don't like it, I'll lose my job."  If you feel that way, then you have to give yourself a reality check and ask if that's really the case.  Are you good at your job?  Is your team, in general, good at their job?  Is the fate of the company riding on this demo?  We hear all the time in the movies about advertising agencies who put everything into making one customer happy.  Who knows, maybe you really are in such a situation.  I don't think I ever have been.  If I blow a demo, the most I'll do is walk around the block to blow off steam, possibly even wreck the whole afternoon, and then come back in fresh the next day and try to do a better job next time.  Would you really lose your job over a bad demo?  If so, do you think maybe you should be looking for a better job?

Wednesday, July 18, 2007

TiVo Series 3 Lite Is Coming

Hurray, it looks like the high def Tivo "lite" is indeed a reality, and will come in at a much more attractive $299 price point. That's the major thing that's been holding me back from going high def in the house. I tried to explain this to my wife once who said, "Well then we'll just use the family room [hidef] tv for when we want to watch without Tivo." I paused for a moment, dumbfounded, and said, "I don't understand a word you just said. What the hell does "watch without Tivo" mean???"

read more | digg story

Sansa MP3 Player Doesn't Recognize Memory Card

I've written previously on the car jukebox I made for my wife and kids, which basically means I loaded up an MP3 player with their music, attached an FM transmitter and now they can listen to the music they want without fighting about what CD to put in next.

Well last night I was updating it with High School Musical, and I broke it.  All of a sudden the memory card was not recognized.  The player itself has a gig of regular memory, and then a gig SD card where I keep the kids stuff.  And it's not being recognized.  The song collection has dropped from 374 to 249.  That's not good.

Found the problem.  In moving the folders back and forth to the computer, I had accidentally moved over a Lyrics folder as well, that was full of TXT files.  That apparently was confusing the heck out of the player (presumably it auto scans all the files on the folder).  When I deleted that folder, everything went back to normal.  Phew!  I did not want to explain to my 3 yr old why she not only did not have High School Musical, but all of her music was now gone.

Just thought I'd blog that in case anybody else is experiencing the same problem.  If your memory card is suddenly not being recognized, scan it and see if there are any non MP3 files on it. 

Gmail Hack : Bulk Delete

I am lousy at inbox management with my Gmail.  I have over 5000 "unread" messages.  What that really means, of course, is that I'm ignoring 90% of what comes in.  And then, once it gets into numbers like that, the interface for deleting things is just unwieldy.  (Remember the early days when they tried to argue that there was enough space that you never needed to delete anything?  Sure I can archive, but I don't want to archive stuff I never read and never plan to read.)

I just found a trick I'm quite happy with that should help take care of some of that bulk:

  1. Search for a string that's unique for what you want to delete.  Typically this would be the sender's entire name, but if you want to get creative, go for it.
  2. Gmail will tell you how many conversations matched, and show you the first 20 or so.
  3. Select all.  You'll get those 20.
  4. In the status message that tells you "20 conversations selected", there'll be a link that says "Select all conversations that match this search."  Click that!
  5. Now, hit Delete.  Gmail will warn you of what you're about to do.  Go for it.
  6. Tada!  Potentially hundreds of old emails wiped out, without having to page through months of messages 20 at a time.
  7. Optionally, go into Trash and do a "delete forever".  Otherwise all you really did was move them from one place to another.

Unless I'm mistaken, you can't sort gmail by sender, and this is exactly why you'd want to do that - bulk deleting.  At least with this trick if you can identify it as something you want to bulk delete, it's only a few clicks away.

BONUS  TIP - Trying to figure out what to delete?  Hit that "Oldest" button in the lower right corner to jump to your oldest conversations, and start there.  The stuff on the front page is still new enough in your mind that you're thinking about whether to keep it.  But the oldest stuff might go back months or longer, and you'll find yourself saying "I forgot I even had that" for things that you can now happily blow away.

 

Technorati tags: , , ,

Tuesday, July 17, 2007

Podshow : Continuing to Suck, Unfortunately

I'm disappointed that Podshow never made a bigger splash in the whole podcasting space, given that it's the brainchild of Adam Curry, who pretty much put podcasting on the map in the first place.  I'm sure podshow's doing great things, but honestly, it's just a non-starter in my podcast listening.  They attempted some sort of audiobook (Shadowlands, or something?) that I disliked so much I didn't make it through 3 chapters.  They had a deal with Sirius radio that I never understood (I thought the whole gimmick of podcasting was that it better than radio?), causing me to drop some podcasts (including Adam's), which fell through anyway.  And they stick assorted advertisements in some podcasts I listen to, that I've learned to tune out. 

And now they've got their whole "help Podshow suck less" campaign going.  At first I was excited, because as I said, I'm disappointed that Adam didn't really continue to break new ground in this new space.  So naturally I went to check it out, and I'm sad to report, they still suck.

Here's a list of the information that Podshow wants from me, before I'll be allowed to offer my opinion:

Email, Name, Address.  Phone number is optional, surprisingly, because nothing else is.  Gender, Marital Status.   Am I Latino?  What's my race?  Level of education, number of children I have, whether or not they live with me, and when they were born.  Employment status, job industry, and household income.

Adam, are you nuts?   Why not just say "Look, we want to know where to target our advertising"?  My opinion is only as valuable to you as my marketing data represents.  That's ridiculous.  The age of my kids has nothing to do with how much I think you suck.  It has something to do with whether I'll buy baby strollers, of course, which is really all that matters here, right?

And to add insult to injury, the homepage contains a graphic (blinking, no less) promising that you can "earn POINTS, and earn valuable PRIZES!"  Oh come on.  Who falls for that nonsense?

The Solution is "Non-Trivial"

I absolutely love this post over on The Fishbowl about how engineers define the degree of difficulty in a problem, ranging from "trivial" to "impossible" and how "non-trivial" fits into the mix.  Many times I've sat in a room and described a problem as non-trivial, and I know what was going on in my head as I said it, and the author just totally nails it.  If I know it to be impossible I'll say that.  But if it sounds hard and I don't have a clue, I'll say "Non trivial."  What a great engineer expression.  It means, in an instant, "Most other problems, to me, are trivial.  This one is only a little harder."  When in actuality it means "As of right now, I have no idea how I'd solve it, but I'm still sure that it can be solved."

Once upon a time I worked in financial services as a technical architect, and we used to rate projects on two scales of 1-5:  difficulty, and time.  Although I can't speak for anybody else, my definition typically was that "difficulty" referred to my own mental energy needed to think of a solution (including prototyping time), and "time" referred to "other resources, including people."  So a 1-1 project was what we typically think of as "cherry picking", something so quick and easy that it's almost not even worth doing, please throw it into the mix when you get a second.  A 5-5 on the other hand, was another way of saying "impossible."  It would take an undetermined amount of time and effort to complete.  I won't tell you it's impossible, because no engineer likes to say that (and no manager likes to hear it), but I'll make you think twice before telling me to go for it. 

A 5-1, something that is very difficult but requires almost no resources, is somewhat akin to the "non-trivial" concept.  It means "The burden of solving this would be entirely on my ability to come up with something, but when I do it should be ready to go."

A 1-5, on the other hand, would be used for a bureaucratic mess.  The equivalent of saying "Can we make the default font Helvetica instead of Verdana?"  The programmer has to change one style sheet, but the decision can only be made by 20 people arguing about it for 3 weeks.

(My current boss has his own version of the impossible/5-5 rule.  For projects he doesn't want to do, he estimates 200 person hours.  That backfired recently when the president himself came down and asked why it was so hard, and then redefined the problem on the spot until the estimate was more like 150 hours ;)).

Monday, July 09, 2007

E-Book Reading

Once upon a time I had a "Rocket eBook Reader" which was one of the very early dedicated devices for reading ebooks.  It was cool, but really only in a gadget sort of way.  If what you really want to do is tear through books of any sort, at any time and pace you want, then you need a ubiquitous device, and most dedicated e-Book readers are anything but.

Lately I've been carrying a Palm device.  Not a Treo, not a cellphone, a traditional "sync it up to your PC" PDA.  It's a model Tungsten C, the one with Wifi and keyboard.  But realistically over the last few months it's become an ebook reader for me.  I can dump PDFs and text files onto it, and whenever I have a minute where the iPod/podcasts aren't appropriate, out comes the PDA.

Well, the thing finally died on me today.  I guess my kids dropped it on the floor one too many times.  So now I'm left pondering just how much I like reading ebooks, and whether it merits getting a new device.  I don't feel like spending $400 on something.  I'm tempted to get the cheapest Palm device I can find and calling it a day, but then I wonder, are there any other dedicated ebook readers out there that are any good?  I'm not talking about the new $300 Sony thing, which I'm sure is pretty cool and all.  I'm talking about something pocket sized, barely more than a dumb text/PDF reader.  Something that I could get for maybe $100 or so.

I figured I'd throw it out there, see if anybody knows anything.  Maybe there's an online market for older ebook readers that have gone out of favor (ala the Rocket) that still have a hacker's market?

 

Technorati tags: , , ,

Friday, July 06, 2007

T-Mobile Hotspot@Home

I've been with T-Mobile for years.  I mean, seriously - my SIM card still says "Omnipoint".  I buy new phones and the kids in the kiosk look at it like "What the hell is this?" 

Anyway, I'm perfectly happy with that service other than the fact that I never get the cool phones.  So I was particularly interested when the same week as the iPhone came out, T-Mobile rolled out a fascinating new bit of technology called Hotspot@Home.  Basically they've figured out a way to do a seamless switchover from cell to wifi.  So when your new cellphone comes into range of a wifi point, it will switch over presumably to a VoIP call - and you stop using your minutes.  It's the seamless part that really makes it fascinating, and a quantum leap over something like a Skype.  If it works, then your T-Mobile coverage just got a whole lot better.  Forget about the free minutes thing for a minute, I never burn all my minutes anyway.  I'm more interested in the coverage.  For example, my wife's only complaint about T-Mobile is that there's no coverage in one very specific area, her parents' house.  She's there often, and her cell phone never works.  But hey, guess what?  With this Hotspot@Home thing, we could at least in theory just set them up with Wifi (which they don't have now) and she'd have perfect connectivity.  That's nice.

Now unfortunately comes the downside.  And there's two of them.  First, you have to buy a new phone.  I suppose that only makes sense, but they only offer 2 phones with this system, $50 each, and both I'm quite sure will force you down the "Psych! You bought a new phone, you just re-upped your contract for 2 years again!" path.  What if you like your current phone?  I like my USB and Bluetooth and MP3 ringtones.

Second, the service is an extra $10/month.  I hate the nickel and dime stuff, the cell phone companies are getting as bad the cable companies.  So not only did I have to pay for a new phone and extend my contract, now I'm paying more money per month for the service.  Is it worth it?  No, of course it's not worth it!  How does it save me any money?  Basically I'd have to be regularly going over my minutes every month to the tune of $10.  And I'm not even close to that.

So do I want to go through all that trouble just so I can reach my wife when she's at her parents' house?  Nope.

Still, though, I do like the technology.  Maybe after a generation or so it'll be a standard feature in all phones and services.

 

Technorati tags: , , ,