Skip to content

JavaScript, Go With the Flow!

Updated: at 02:12 PM

As a technologist gluten, I probably spend too much time on different technologies and not enough time on any one particular one.  It does find me often frustrated with seemingly basic things that should take little time to solve.  Recently, a friend sent me a quote which sadly applies to me too much.

To be successful as a programmer, you, first and foremost, have to be a nerd.  You were probably born that way, but in any case, you already know if you are.  You are the kind of person who can stare at a screen for 14 hours puzzling over why the damn call to xref = malloc(len); is not accompanied by the appropriate call to free(xref); about 1 out of 100,000 times, and that’s why the frigin fuel injector hangs up on the new Mazda – and feel refreshed, energized, and dying for more.  Not everyone can – or wants – to do this.

Anyhow, where was I.  Oh yeah, JavaScript and going with the flow.  I’m pushing to get a SenchaTouch app done right now so I can make the January 21st deadline for putting a Blackberry 10 app together and getting it into there store.  I’m close! (I think).  I find myself staring at the following code that I’ve written.  Basically, I’m taking data that I got from a web service and updating a screen full of fields.  First, I DeRef all the data into local variables, then I set that data in the panel (form).

var customerFullName = obj.Data.CustomerFullName;
var cumulativeStarBalance = obj.Data.CumulativeStarBalance;
var cardDollarBalance = obj.Data.CardDollarBalance;
var numStarsTillNextDrink = obj.Data.NumStarsTillNextDrink;
var numUnredeemedRewards = obj.Data.NumUnredeemedRewards;

var goldCardPanel = Ext.getCmp(“GoldCardPanelId”); goldCardPanel.setData({ customerFullName: customerFullName, cumulativeStarBalance: cumulativeStarBalance, cardDollarBalance: cardDollarBalance, numStarsTillNextDrink: numStarsTillNextDrink, numUnredeemedRewards: numUnredeemedRewards });

I start to notice that I’m repeating myself kind of so I’m thinking maybe I only need to do this once and I can half the size of the code.  Then I say to myself, Self: does it really matter that our template uses lower case and not upper case variables? (obvious answer is no, I often talk to myself in rhetorical questions).

So, the rewrite is this:


Just Sayin…

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects