Thursday, September 01, 2005

Setup:

1. You have a page with a data-bound DataGrid.

2. The page makes multiple post-backs (for example, the DataGrid is editable).

3. There are template-columns in the DataGrid.

 

Here's the tip:

Make the ID of the DataGrid and the ID of the controls inside the template controls shorter.

 

See, the DataGrid control renders all the HTML elements it needs to display your data, and assigns them id's based on the ID of the grid itself and the ID of the controls they represent.

 

Have shorter ID's and the eventual HTML page that travels to the user will be much lighter. How much? We recently saved between 20% to 30% in a page that used to weigh in at around 500KB, and that's a lot.

 

Consider the following simple example:

I have a grid with two data-bound columns. The ID of the grid is "CitrusFruitData". Each column is a template-column. The item template of both contains just one control - an asp:label with and ID of
"Label1".

 

If I bind 100 records to it, the output page is 36343 bytes long.

View source, and you'll see the something like the following (about 200 times...):

<span id="CitrusFruitData__ctl7_Label1">... 

  

Now if I shorten the ID's of the grid (to "Cf"), and the two labels in the item template of the two columns (to "L1"), the resulting output shrinks to 32930, which is an easy 9% improvement.

 

And when you have more columns, and more controls in the columns, and more rows in the grid – the improvements will be more dramatic.

 

But wait, crazy man! What about readability?

True, your code will be less readable, but this is one case when I will prefer the performance over readability. And the readability can be easily contained, if you're smart about it.

 

Good luck.

 

Friday, September 02, 2005 5:21:42 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, August 02, 2005

I know, Microsoft Outlook is the number one productivity-enhancement tool in the world. I honestly don't understand how anybody got anything done before they had that stuff.

 

But that's not what this post is about. See, Outlook can also be a productivity destroyer. Here's how:

I'm a software development team lead. My job consists of doing a ton of little things, many of which require being concentrated (Well, some of them. Okay, few of  them.).

In order for that to happen(me doing the things I need to do so I can go home and watch mind-numbing TV till I fall asleep) – I need to be in the "zone". You know.

 

Anyway, here's a scenario that happens a lot(the parts where I speak to myself are all exact quotes):

1. Right, got that major document to prepare for tomorrow, boy that one's important. Phew.

2. Well, in that case, better open that Microsoft Word over there.

3. Opening Microsoft Word.

4. Okay, how to begin, how to begin, how to begin. (Thinking for about 80 seconds) Got it! There was that mail item in the Inbox that has most of the stuff that I need to address in my big and important Document. Better check that email right-away. Man I'm good. Wish I could teach others to be me.

5. Alt-tabbing my way to Microsoft Outlook. Clicking the Inbox (ctrl-shift-I would've worked too, I know that, you smartasses. I like the *click*.).

6. Hey, I'll be damned, I got me 12 brand new shiny emails in me Inbox, mate (Irish accent kicks in for a moment there). What's this?

 

"FW: The following persons please come to the main office, your parking passes will be confiscated"

 

Oooh. Sounds interesting. Better read the whole thing.

7. Reading the whole totally useless, unrelated-to-me waste of virtual paper.

8. Boy, that was fun.

9. Wait a second, wasn't I up to something? Hmm. Beats me, guess not. Better go over that to-do list, see what should I do.

 

Now, do you see what just happened there? Me having to switch to Outlook for some reason, made me notice something unrelated in my Inbox, and forget all about my original intentions.

And it happens all the time! For example, step 4 could've included:

4. […] Gotta go to that Calendar of mine to see if I meet that dude next week so I can ask him that question about my important document. […]

 

See?

 

Now, let's analyze:

The problem consists of:

1. Me having often-accessed data in my Microsoft Outlook,

2. The Inbox, that contains tons of attention-catching garbage, is right there on top of Microsoft Outlook.

 

So, possible solutions are:

 

[Possible Solution #1] Never access that bloody Outlook during regular work, only on specially designated Outlook-Breaks. Keep no needed data there.

 

[Why Possible Solution #1 is No Good]

Well, much data that I call "Reference" (meaning I don't have to *do* anything specific about it anymore, but I might need to look at it some time) really *belongs* in Outlook:

1. Stuff in the calendar.

2. Information that got to me in emails – I don't want to translate anything to files, that would be insane.

 

 [Possible Solution #2]

1. Make the inbox less sticking out. Hide it someway so that I don't have to see it when I need to access stuff in a specific mail folder or in the Calendar.

2. Keep no "Reference" stuff inside the Inbox, move it all to other folders as soon as possible.

 

This one sounds alright. I think I'll give it a try tomorrow, tell you what happened.

 

What do you think?

Tuesday, August 02, 2005 7:11:24 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [18]  | 
 Sunday, July 24, 2005

Yo dogs!

Check this out: Oren Ellenbogen is up in the air.

This dude can do stuff with Visual Studio that'll make your hair stand up, form elaborate geometrical shapes and sometimes - do the Rumba. So anyway, pay him a visit.

Monday, July 25, 2005 2:41:20 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [17]  | 
 Saturday, July 16, 2005

Turns out I was born in the Year of the Rooster(1981).

Here's what the chinese calendar site has to say:

"The sign of the Rooster indicates a person who is hard-working and definite about their decisions. Roosters are not afraid to speak their minds and can therefore sometimes come across as boastful. They make good restaurant owners and world travellers."

I definitely agree with "definite about their decisions" and "sometimes come across as boastful".

And that stuff about "good world travellers" - Amen to that. Is that a job? "World Traveller". I can do that.

Well, go over there, see what it says about you.

p.s.

2005 is a Year of the Rooster too, so naturally I expect a fatter-than-usual cheque. So start saving now.

Sunday, July 17, 2005 4:50:19 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [0]  | 
 Friday, July 15, 2005

Holy mother of God.

Didn't know they sold these on Amazon. (Hint: Avi, don't click)

Saturday, July 16, 2005 4:56:28 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [11]  | 

Well folks, let me lend you a free piece of advice about this one travel magazine you should never be reading.

It's called "טיול עולמי" (World Travel) and it's available at selected bookstores near you(If you happen to live in Israel that is, my dear, devoted, non-existing, English-speaking readers). In fact, I bet you real money it's available right now. Go on, check it. Know why? Because nobody is stupid enough to actually buy one.

Me, I have a yearly subscription, luckily one that's ending soon.

 

I've been getting this tree-based piece of crap for the past year or so, and I noticed immediately that it sucks bananas big-time, but this latest issue that was waiting in my mailbox this morning was just too much. (Plus, I didn't have a blog before)

 

So here's my bias-free criticism:

  1. Factual Errors
    This had me really going crazy(white foam and all). The bunch of fellows over at the magazine, clearly don't intend hiding the fact they just do a (quick) google search for their "stories". Having the same two names signed on most of them, no matter how far the terms discussed in them are from each other, gives you a hint. But the real juice is when you dig in.
    Take the latest issue, one titled "Rome". Here's a typical paragraph:
    (start imaginary quote)
    "Rome, Rome. What can I tell you about Rome. Well, Rome contains many Italians. No, Romans. Many Romans. Or was it Romanians? Yep, that's right. Anyway, some 500 years ago the Romanians dominated most of modern-day Europe.
    While in Rome, you should enjoy a meal of the many Romanian foods – Pizza, Spaghetti and Berlusconi.
    Oh no, come to think of it, Berlusconi is no food, he's a famous football player for one of Rome's great teams – A.C. Milan."
    (end imaginary quote)
  2. Basic Content
    Now, the stuff they *do* get right, is just too basic. Don't get me wrong, I can enjoy the average Playboy, even though I already know how damn good looking porn-stars are. But this stuff wouldn't be good enough even for the "Mitzpe" elementary (my dear Alma Mater) paper.
  3. Spelling Errors
    Speaking about that school paper, you'd get fired for misspelling. Come on. Obviously, doesn't matter at the "טיול עולמי" headquarters. As long as you mean well.
    I kid you not.
  4. Pixelation
    It's obvious they have their photos taken by that cutting-edge Nokia 1.3 mega-pixel phone. And they have that crap on the *front page*! This is embarrassing. (More about that Nokia in paragraph 7)
  5. For all this wonderful material, you'll never guess the price tag. Come on, guess it. I thought so. It's 69 silver ones an issue!! I can get a book for that kind of dough. With thoughts in it.
  6. Little Content
    While on the subject of value, this baby has 60% ads in it. You rarely stumble upon a page that's not promotion. And if you do, it's rarely more than 200 words, with a big fat pixelized photo in the middle.
  7. Home-Made Photography
    Last but not least, the thing that made my day was one particular photograph found in this issue. It's subtitle says "Piazza di Spagna"(with a spelling error, of course). But what you see is something different altogether. Well, it probably is on the Piazza, but there ends the connection.
    The photo features a fountain, hidden by an average looking Israeli Aunt. Her name is Aunt Tzippora. So the photo really should've been titled:
    "Aunt Tzippora, Rome, 13/5/2004".
    You know what I mean?
    And that's when I realized how the issue came to life:
    Aunt Tzippora(after returning from a weekend in Rome with her husband, Yosi): Hi Itzik, we're back!
    Itzik(the nephew, one of the "טיול עולמי" writers): Great, how was?
    A.T.: Wonderful, we went to the Colosseum and stuff. Uncle Yosi took many pictures with his new phone.
    I.: Is that so?
    (Itzik is struck by an idea)
    You know, I'll probably do a whole issue on Rome soon, mind if we use your pictures?
    A.Tz.: Of course not, no problem at all.
    (They continue, but it's really irrelevant)

    Appendix
    Fearing copyright laws, here's what the photo kind of looked like:
    Aunt Tzippora, Rome, 13/5/2004
Friday, July 15, 2005 11:29:14 PM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [11]  | 
 Tuesday, July 12, 2005

I knew I didn't want to go to work this morning for a reason.

Well, aside from the fact I only went to sleep at 2am, my eyes were burning as if I just spilled some special gazoline-based, industrial-strength stain-remover on them and rubbed them with garlic, and I just all-around don't get turned on by going to work in the mornings. Never mind that.

I knew I had *The Bug* to deal with, and no matter how much I wished I had something super-important to do all day, I knew I had to tackle that bug *today*.

And I'm not talking with you about one of those well-behaved Im-getting-an-8-instead-of-a-7-return-value, school children type of bug. This one was a mean mother.

Well, there's this main page on one of our secret web-apps, and on it, there's some secret client-side javascript code that's supposed to run when the .aspx page finishes loading, and do a bunch of secret stuff.

It all works fine when run from localhost, but then when run from the test server, two times out of three it just doesn't run. And Shani, who's responsible for maintaining it, is, well, unavailable at the time, so I had to figure it out.

It usually takes 20 minutes to figure out you don't have a clue how to fix a bug. I did my 20 minutes a couple of days ago, so I wasn't very optimistic.

Well, I started with some debug statements.

The page has an HTC behavior attached to it, like this:

<body style="behavior:url('file.htc')" ...>

Inside the behavior file there's a function, with some code in it(!):

function foo(){
//...
}

Which is attached to the onreadystatechange event of the document (using an ATTACH tag in the behavior).

Function foo() checks for the readyState property of the document and when it's value is "complete" - does it's thing. And like previously explained, the thing doesn't get done for no apparent reason.

Like I said, after some debug messages(actually they were just output to the window.status, javascript alert's are just too damn annoying when trying to debug), I narrowed it down to:

1. Either foo(), for some reason couldn't attach to the onreadystatechange event, some of the time,

2. Or, the event wasn't even raised.

After some more time, I realized the event wasn't being raised at all, "2" was the correct one. Great. Some more time, and I figured out also that the document was "stuck" with readyState="interactive", and the body element(the one the behavior is attached to) with readyState="loading". Plus, the behavior file wasn't being loaded at all - even code placed inside it, but outside all functions, wasn't running. More proof to the theory, yet no advance towards the solution, getting home, being happy, etc.

So this was now my great question: something was causing the IE to be unable to load the behavior and because of that, not to finish loading the whole page, getting stuck in the same incomplete readyState, not throwing the onreadystatechange event and being generally miserable. Hmm. That's not even a question, is it? Right. The question was: Why?

Now, on a side note, all this probably doesn't sound much, but by this time I was way past my lunch break, pretty angry, and above all - clueless.

I managed to pass some time using excessive coffee making and consuming, cooler-talk and staring at my inbox. So I reached 16:45, time for my weekly weights training and so we, Doron and myself, went.

Coming back to the office I only hoped to be home before midnight.

Fortunately(for me then, and for you'all now), the solution came in about 90 seconds.

I noticed two script elements referring to external javascript files, like so:

<body...>
<script language=javascript src="file1.js"></script>
<script language=javascript src="file2.js"></script>
<form ...>
...

I remebered Shani saying something about placing stuff within the <head> element if you want to make sure it gets loaded fine. So I gave it a try and moved the two script's inside the <head>.

Voila. No problem.

 

Tour-de-France recap starts in two minutes, so quick concluding thoughts:

1. If you can avoid client-script in IE, especially event-based, do it at any cost.

2. Man, I'm happy it ended the way it did.

3. To tell you the truth, I have no idea how to explain exactly what happened, why IE had trouble to load the script's and was getting stuck on the whole page. And how come it's so hot in here lately, for that matter.

Wednesday, July 13, 2005 6:19:54 AM (Jerusalem Daylight Time, UTC+03:00)  #    Disclaimer  |  Comments [0]  |