Think in Russian

In the classic Cold War thriller, Firefox, Vietnam veteran Mitchell Gant has to steal the top-secret Soviet Union, titular plane.  Among its advanced features is that the systems are controlled by thought.  But only if he thinks in Russian.  This becomes a key plot factor in the climax of the film.

In my last post ; I remarked how many bad solutions I had found to sorting a SQLDataconnection Gridview.  Well I’m happy to say I solved my problem last night. (And as an aside, I will not be posting the solution at this time because while the solution itself is decent, I’m not sure the code is the best.)  Part of my solution was solved by “thinking in Russian”.

As I had mentioned, some of the so-called solutions to this problem that I had found on-line were pretty bad.  In one case the author apparently decided the easiest solution was to decipher the viewstate, extract out the information, sort it and stuff it back into the viewstate.  Now, as I’m writing this, I realize one advantage this has is that it removes a roundtrip from the web server to the database server.  But that’s about it.

I also saw a solution that involved passing the column name back to the code-behind and having that decide which of multiple stored procs to call.  I can’t say I favored this approach since it basically means a lot more maintenance if you ever say want to add a column to your Gridview (which turns out I decided afterwards I may want to do.)

Even worse, I’ve seen people propose things like building the select string on the fly and I can’t even begin to say how bad of an idea that is.

That said, the more I thought about it, the more I realized what the “right” solution was.  Rather than fighting the system, I had to think like the system.

So, after a side trip down to trying to use SqlDataAdapter, I went back to my first approach of using a SqlDataReader.  However, based on one example I saw, I decided to move this to a function of its own.  This, if nothing else resulted in cleaner code (since I was already calling the SQLDataReader in two places (see Rule of Three).  Once I did this, it was a little matter of figuring out how to bind the SqlDataReader to a Datatable and returning that.

Then I could bind the datatable directly to the GridView if I wanted to (which I do on the original Page_Load and Click_Submit OR I  could in the _Sorting event bind it to a local Datatable, sort that and then bind the resulting sorted Datatable to my Gridview.

Worked like a charm.  Well except for one little detail.  And this one I’m still not sure if it is a MSFT bug that lives on for backwards compatibility or I and MANY other developers are doing something wrong, but the GirdView incorrectly will always return “descending” for its sort direction.

So in this case the common (still not convinced it’s the RIGHT or BEST solution) is to stuff a variable in the Viewstate and read that back every time sorting is called and reverse it as needed.

Once I did that, I had working code that could sort my Gridview on the selected column that was clean, easily reproducible and made sense.

I’ve found with my forays into .NET Framework and VB programming that if my initial approach appears overly complicated or just plan wrong, it probably is.  So far in pretty much all cases, I’ve found that if I stop and try to “think in Russian” the solution will appear to me and is generally fairly straightforward and looks right.

Years ago when I studied Latin, I reached the point where I could read Latin natively.  I loved it. But part of the switch is being able to think in the structure of the language.  Not all languages use “SVO” (Subject-Verb-Object) order like English.   Latin, “SOV” (Subject-Object-Verb) order uses.  It takes some getting used to. But once you accept it, things get easier.

So I can’t fly a Mach 6 stealth aircraft, nor do I speak Russian, but I’m starting to think in VB. (Or is that I’m in VB starting to think?)

Goldstone has the Bird

One of my favorite web-comics is xkcd.  I was recently reminded of http://www.xkcd.com/978/.  I’m in the process of putting together a .NET 4.0 Framework based website using VB.  I have a very nice table thank you very much that is bound to a SQL Datasource in the code-behind.  Nice and slick.

Except, I want to make it sortable.  Should be as simple as setting AllowSorting=”True” and marking the columns I want sortable.  However, that doesn’t work when bound to a SQL Datasource.

No problem.  I’ll just Google it.  And there I find about a dozen answers.  And a third of them are just plain wrong (wrong enough even with my limited VB experience I can tell they are wrong), another third quote the wrong answers and the final third simply don’t work (and are so poorly commented in some cases I can’t even figure out what the original author was even attempting.)

And please, before you forward me a bunch of links in an effort to be helpful, don’t.  I’ve seen them.  Probably.

But it does lead to the general question.  How do you know what you read on the Internet is accurate? Even if it quotes a source, how do you know the source is accurate?

For years many people who followed the space program believed that “Goldstone has the bird” was a quote about Explorer 1, the first US satellite being picked up by the Goldstone tracking station, thus proving it had made orbit.  For years this was believed by many.  It is quoted in several reputable places, including the autobiography of someone who should have had first hand knowledge.

However, there is at least one little problem.  Goldstone hadn’t been built at the time.  So even the “original” source appears to have gotten it wrong.

http://www.thespacereview.com/article/550/1 for more details.

Just give that a thought the next time you look something up on Wikipedia or another source to confirm your facts.

Employee Loyalty

I’m in the midst of trying to put together an idea for a new company.  This is something I’ve wanted to do for years.  The hardest part of course is coming up with the right idea.  I think I’ve got that.

But as equally important to me is building a company that I would be proud of and that will attract good employees and retain them.

Years ago, I was consulting at a local software company, performing their IT functions.  They were a large customer of mine so I spent a lot of time there, enough that I was almost like an employee.  Only I wasn’t treated as badly.

I recall one day sitting in a company meeting where the CEO and the CFO patiently explained to the employees why their expense checks would be paid as late as possible.  You see, it was better for the company’s balance sheet.  But don’t worry, the employees would get their money, eventually.  They then basically gave a morale speech that boiled down to, “We’re not sure why everyone is complaining, you should feel lucky to have a job!”

As a contractor I had a much easier way of making sure I got my money when it was due me.  I could simply stop working.  A quick call to the CFO would get me paid.

This late payment of employee expenses combined with other issues basically killed morale at the company.

At the same time, my wife was recruiting for another software company across town and one of my other customers was across the river.  Both were recruiting.  It was amazing how many people jumped ship from the first company to either of these two companies.

One day I was at the company across the river doing some consulting.  They had recently recruited a developer from the first company.  Earlier that day he had submitted an expense check.  Now, like any reasonable person, he would have been content waiting until the next payday or some other reasonable amount of time for his expense check.

Well later that day, I saw him walk out of the finance person’s office with his expense check in hand.

A single act bought his loyalty more than any pay raise or speech about morale could have.

I want to make sure my company (assuming it takes off) can treat its employees with the respect they deserve.

A Bright Idea and State of the Art

I think everyone likes to talk about “their first program”.  I suspect though it’ll become a less common topic with future generations, just like most kids don’t recall the first book they ever read.

My first program calculated things in Celsius if you provided the Fahrenheit temperature.

I was probably 11 when I helped write it.  It was stored on paper tape and ran on the local high school’s minicomputer (probably a PDP-9 but I honestly have no idea).

It wasn’t a long program, it was probably in FORTRAN.  Again, that is so long ago, I can’t recall the details.  And it wasn’t a very impressive program.  Heck, these days you can do it in a Windows CMD script as one line. (well two for clarity, SET F=212, SET /A (%F%-32)/9*5)

I wrote more complex programs in High School (by then had moved up to Turbo Pascal) and made my first money programming in FORTRAN while in college.

Things had improved from paper tape to floppy drives to hard drives.  Writing programs and debugging programs for the most part became faster. But generally anything more complex than basic input and output through the screen and keyboard was still tough to do and time-consuming.

About two weeks ago I had an idea for project.  I was on the road at the time and didn’t get a chance to sit down at my desktop until last week.  In less than 24 hours I had prototyped the idea and tested it.  The program involved a website, a database, doing some lookups, writing to the database and a bit more.  Even just 10-15 years ago it could have easily taken me 4 or 5 times as long to do something like that.

On Thanksgiving Day, my son wrote a program in a language called Scratch http://scratch.mit.edu/ that would take input, make it circle around then settle on the screen.  The more times you entered text the bigger the resulting “wordle” spiral would grow.  He wrote it that morning before our relatives showed up.  It took him maybe an hour or two, including debugging and overcoming some initial limitations.

He’s been writing programs in Scratch (and other languages) for years now.  I doubt he remembers his first program since writing programs now has become about as easy as using a computer.  I’m sure he doesn’t remember his first time using a computer like I do.  He writes programs at age 11 that in many ways are more complex than anything I wrote in my teens.

The state of the art has certainly changed and it’s made the world a better place all-around.  Languages and frameworks make developing faster and easier than ever before.

Though at times I’ll admit I miss the days of FORTRAN.