Friday, September 11, 2009

Something I always forget about Nullable Types

0 comments
int? foo = null;
foo += 123;
So what's wrong with this picture?
Well, if you apply arithmetic operations to a null value, you get a null value in return.
So instead of foo being 123, the value of foo is null.

It's easy to spot in the above example the fact that foo is null. But when you have lots of lines of code, it's easy to lose track of the fact that foo is a nullable type or that it could be null at the point in time you wish to perform calculations on it.

The correct way to perform that calculation is like so:
int? foo = null;
foo = foo.GetValueOrDefault() + 123;

So if you're working with nullable types you gotta keep in mind that null + 1 = null.

Problem with the code at the top is that it compiles fine.
You never know you made the error until you find your values are turning out as null.
Which in some cases will take you a few days to even find out something's not working right.

So always check your variable types. Hover the mouse over or hit period after the variable to check what pops out.

Happy coding!


1 + 1 = 10 ;)
1 + null = null :O

Wednesday, September 09, 2009

Anger Management. I need help.

0 comments
I'm unhappy. I haven't played a single game of badminton for over 2 weeks.
Our favorite place is being renovated and no one wants to play at the other venue.
I've been feeling grouchy the whole week.

When I'm grouchy...
Oscar the grouchI don't complete my sentences in IM.
I use more colorful language. (pissed instead of angry, fucked up instead of messed up etc ...)
I start replying to every stupid email in my inbox.
Flame wars get started and Trolls get fed.
People having their 'Water cooler' conversations when they're not near a water cooler makes me mad.

My friend says
ur getting cranky in yer old age
u got cabin fever!
Maybe he's right. Or maybe what I really need is a good badminton session.



Oscar was stolen from here

Wednesday, September 02, 2009

Savvy

0 comments
Got a kink in my back from sitting too long at my desk. So I got up to stretch my legs.
I see two guys poring over this screen umm-ing and ahh-ing saying "I think it's frozen"... "I think it's stuck."
I thought he had some performance issues. I always find hardware performance a nagging issue with my own machine so I thought I'd gloat over someone else's misery for a change.

Sadly, the machine was just fine. It had better specs than mine. Crap! Nothing to gloat about.
One glance at the guy's screen tells me he's got a dialog box open which was misplaced off the display area. So all he saw was this program with a grayed out title bar showing his window as inactive. Using your laptop with an external display will do this sometimes.
Simple fix, Alt+SpaceBar, out pops the control box of the missing dialog box.
Choose Move. Press the arrow keys on keyboard until the dialog box is dragged into viewable area.
Another way to fix it would be to open up your computer's display properties and reset to using only one display.

Moral of the story? Experience beats two smart IT guys huddled over a machine. Any day!

When you're faced with a problem, there's no tool more handy than experience.

Saturday, August 01, 2009

Ambition

0 comments
Pain... dull numbing pain.

My body aches. Shoulders, arm and left ankle. All the muscles below my waist are stiff. I feel tired but refreshed at the same time. I think it is the endorphins kicking in.
This pain is nothing new. I feel this way after every serious tournament. It is a good pain if I won and it adds to my misery if I lost. What do I feel today? Can't say it is bad or that it is overly good. Just a 2 hour training session. Yeah training... if you know me, you know how much I hate training.

I'm trying to change that. I've been to two training sessions and today was even better than the one last week. Two. That's not much. Anyone can do that much. To keep going week after week, now that's hard. It takes commitment and dedication. I guess time will tell how I hold up.

So why the sudden change of heart about training? Failure.
I've won and I've lost. I've never been one to hold my ranking however high or low it may be. When I say ranking, don't misunderstand me. I'm not a world class player. I mean it as a rough idea of who you can beat and who can beat you if you were to play in a competition against say club members.
Back to my ranking then. Well, I rank myself, as a player who can beat everyone currently playing badminton with me and also as a player who can get beaten by everyone of those players.
You have to work hard to win against a strong opponent. You don't have to work hard to lose to a weaker opponent and guess what? I don't like working hard.

I've been losing more than I won. My current competition record is a joke. Attribute it to my lack of will, skill, fitness or desire to win. No one wants to lose but some people desire the win more than others. I've never had the burning desire to excel in anything. Never coveted for the top position. Never put myself forward as a leader. Ambition is not something I have in vast quantities.

I lack ambition because I have it too easy. I'm gifted. Not gifted as in super genius, IQ in the hundreds gifted. I'm gifted as in I'm born with a natural ability. An ability to do “well enough”. Everything I do, I do well enough without trying. Other have to work consistently to be where they are at. I'm above average without even trying. So where do I find a desire to work harder? Like I said, through failure. I've failed at things. Lost many tournaments. Failure is nothing new to me. It takes a special catastrophic failure that will make me feel real small to knock me off my high horse.

Losing to a girl many years my junior at singles, in two straight sets with me not even coming close to winning a single set, in a badminton tournament with quite a number of people looking on. Yeah, that fits the description of catastrophic failure for me. Losing is not a bad thing at all, if it lights a fire in my heart. Make me want. Really want the win. So I lost and I waited to play her again. I did last week and won in two sets. How long is this motivation to win going to last? Who knows? Habits are hard to break and I'm a habitually lazy person. In the mean time, I have to do my best to stay in the best shape so that my last win wasn't a one off thing. Ergo the training.


Playing squash with friends in the morning and I still haven't finished watching the movie I was watching so that's it for today. Good night.

Sunday, July 26, 2009

July 26, 2009

0 comments
Sunday...
Nothing interesting happened today.
Played squash in the morning and walked home.
Weather is great today.

I'm reading The Great Gatsby because a friend of mine mentioned reading it.
I really like the expressions used by Fitzgerald. I'm enjoying it slowly one page at a time.
“There was so much to read for one thing and so much fine health to be pulled down out of the young breath-giving air.”

I like that line. I've become jaded in my set routine of work and play that I forget the simple pleasures. Everyday is a good day. It's only how you perceive it that makes things different.



By the way, you can find the book at http://www.gutenberg.org it's a great resource with thousands of out of copyright books.
 

Copyright 2009 All Rights Reserved. Zatlite | Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com