Some of the things I read in R. Aaron Zupancic's blog post New Operator in C# 2.0: ?? caught me off guard. I swear I'd read through several articles listing changes and additions in .NET 2.0 and C# 2.0, including MSDN, but never ran across the ?? operator. I even checked the C# Operators documentation and didn't see ?? Operator until the second pass, because it's grouped in the assignment category. I expected it to be grouped in the conditional category with ?:, but now I'm wondering why ?: isn't considered an assignment operator? While the null coalescing operator is cool and looks nice in code, I'm not sure how much I'll use it. Most of my code where I'm checking whether a variable is null throws an exception or takes some other action instead of using another value in place of the null variable. The most interesting thing that I noticed was the following comment from Owen Blacker: It's even cooler than that. The null coalescing operator does type forcing, too.
Imaging you have this:
public int? GetUserID() { ... }
int userID = GetUserID() ?? -1;
The ?? operator not only provides an alternative value if GetUserID returns null, but it also does type conversion, from the int? result of GetUserID to a non-nullable Int32, if it returns a non-null result. I was really thrown off by the int? part of the example code in the comment above. I eventually found that it's the same thing as NullableType. That's really nice syntax to replace using a nullable value type. Before I knew what it was, I immediately assumed that it was something like a nullable type. The question mark following the value type suggests that you're not sure that the returned value will be integer or not. I will definitely get some mileage out of this information. Finally, a way to represent a value from a SQL bit column in code. I'm not sure why I forgot about Nullable Types. I do recall reading about them in the feature list for a .NET 2.0 beta, but I don't remember seeing anything about them in any "what's new" articles. Maybe I just missed it. Back to the operator, I think the next example reads a lot cleaner than the following one which uses the NullableType's GetValueOrDefault() method. Of course, its probably better to use that method so you aren't hard coding a value type's default value in code (not that it would change). Using the ?? operator: int? x = null; int y = x ?? 0;
Using the GetValueOrDefault() method: int? x = null; int y = x.GetValueOrDefault(); It's interesting that the null coaelscing operator post is making rounds now, almost exactly a year after it's original posting. Labels: c#
Yesterday I posted about input devices, and mentioned that I couldn't configure the thumb button of my Microsoft USB Comfort Optical Mouse 3000 to enter the Alt+Tab keystroke. So what did I set as the functionality of the thumb button? I just had it configured to the default Back button functionality, which I found myself never using, and left it at that. Then I found a utility that lended itself very well to being mapped to the thumb button. Clipboard Recorder is a utility that stores the last 100 snippets of text that have been copied to the clipboard. Among it's several interfaces, there is a pop-up menu that can be activated with the keystroke Ctrl+Alt+V. I mapped this keystroke to my mouse's thumb button and, viola! My favorite mouse configuration ever!  I don't know how I lived without a clipboard history up to now. As a software developer, it is indispensable. Copying and pasting sections of code is something done every day, and it's very nice to be able to copy code knowing that you'll need it later, but not worrying about overwriting it in the clipboard, and maybe having to store it in a temporary text file. Also, our defect management software at work leaves a lot to be desired, and I find myself copying and pasting the same 3-4 pieces of information into several places, including VSS. I love Clipboard Recorder and that's why I registered it on " Support Your Favorite Small Software Vendor Day" last month. Some other utilities that I use daily: And some utilites that I use every now and then: Also, I have del.icio.us utilities links to tools that I want to check out some day. Update:I'm counting this as my official "Tools Day" blog post, in support of Jim Holmes and James Avery's new book " Windows Developer Power Tools". Labels: tools
I love ThinkGeek. I get their newsletter and get a kick out of checking out what new products they're carrying. I also maintain a wishlist there and occasionally add items that I think are cool. That way, whenever anyone asks me what I want for Christmas or my birthday, I can just tell them to check out my wishlist on ThinkGeek and Amazon (I keep one there too). I often forget what I added to the wishlist just because I thought it was cool at the time. At Christmas this year, my brother in law surprised me by getting me something from there that I'd forgotten about. The StealthSwitch! Hiding windows at work is pretty juvenile. When my father saw what I'd gotten, he said that some people at his office had installed a program called "the big cheese" or something like that, which would display a fake spreadsheet when they hit F1. He had the IT department un-install it and limit his employee's rights so they can't install applications now. Of course, he was concerned that I was doing something at work that I wanted to hide. But that's not the case! I wanted the StealthSwitch foot pedal to play with as a third input device. I'm not a keyboard Nazi, but I am particular about the input devices that I use. I use the Microsoft Natural MultiMedia Keyboard and love the over sized Delete key arrangement, but really don't like what they did with the function keys. I am really a mouse guy and I fall back to using the mouse even when I know keyboard shortcuts for some things. For instance, I know that Ctrl+B builds in Visual Studio, but I have a custom toolbar shortcut that I use instead. I used to have a cheap mouse with a thumb button that I had configured to enter the Alt+Tab keystroke. I found it to be VERY convenient since my right hand is on the mouse so often. When that mouse went bad, I got a Microsoft USB Comfort Optical Mouse 3000 because it has a thumb button and the scroll wheel features the horizontal tilt. While the mouse looks good, the horizontal scrolling isn't useful, and I'm disappointed by it because the Intellipoint software doesn't allow me to enter Alt+Tab as a keystroke for the thumb button. Tab isn't captured by the keystroke form, and I even tried to enter it directly into the registry but the driver didn't recognize it. Enter the StealthSwitch. The software installed from the CD that came with the device only allowed for hiding windows, and even then it was limited to hiding all windows, the current window, or all but windows with a short list of keywords in the title. Even if I was going for the window hiding functionality, I would want to specify particular windows to hide and this didn't allow that. I figured I was going to have to write some software to use the pedal's input. Then I found a newer version of the software on the (incredibly bad) StealthSwitch website. The latest version not only allows you to list the windows you do want to hide, but also has a screen to configure custom actions. Eureka!  Now I can have my Alt+Tab functionality again, and I don't have to worry about where my hands are ... I use my foot! Maybe I should look into the specialized foot pedals meant to replace the mouse or augment game play. Or, I could give the Zero Tension Mouse a try ... nah, never mind. Labels: devices, tools
 I just registered for the CodeMash conference and I can't wait to go! I held off registering in order to make sure it would fit our schedule and budget, and missed the early registry discount and also the block of rooms at the resort, but that's okay. I'll probably only stay there one night anyway. woot! Update: There were still rooms available in the block for the conference, even though the CodeMash site didn't reflect that. Labels: codemash
I found the shape of my lunch today to be very pleasing, so I decided to snap a picture with my cell phone. I may decide to keep a picture log of my lunches ... we'll see. Labels: humor
I call the few business days between Christmas and New Year the "Holiday Hump", kind of like people call Wednesday the "Hump Day". We're in the midst of the holiday hump here. A long Christmas weekend is out of the way, but I still have the in-laws descending on my house this weekend, and whatever we end up doing on new year's eve. I have neglected this blog, and I'm considering making it my new year's resolution. I'm still really into reading various blogs, even if the RSS feeds I subscribe to have changed over time. I still enjoy reading Joel Spolsky, Jeff Atwood, Leon Bambrick, K. Scott Allen, and others, but those are the first that came to mind. I suppose I started this blog because I wanted to be able to contribute to the community like these other people have inspired me, but I've found that writing doesn't come as easily to me as I'd hoped. Also, I realized that blogging is life for some people and it's just a supplement for me. I still think I have things to contribute from time to time, but I also have been working on such mundane things lately that nothing has come up. It will be really interesting to see what pops up once the current project I'm working on is up, and into the new year. This project is due the first week of January, but we'll see about that. I was complete with code, had the design documents updated, had started on a user guide and had my one resource doing unit testing and working on example configurations when I was blindsided on Friday morning. I should have seen it coming, but there has been totally new functionality added to the requirements. Requirements being a non-existent document. I'm not really upset about the change of scope because I've had to deal with it plenty of times in the past, but I'm not sure what will happen if I don't meet the deadline. Things are so disorganized here that I really have no idea. Holiday hump, project hump (almost), and unsure about what the new year will bring. In the face of all of this uncertainty, I'm still blessed with a loving family and I still love what I do. Maybe I don't need any new year's resolutions after all. Labels: misc
Last night was shaping up to be a pretty dull Halloween. My son wasn't feeling well (probably just teething) and with the rain and temperature dropping, we decided to not go out for trick or treat. At this age, he wasn't looking forward to it, so it's not like he even noticed. Then, at 8pm, we heard two gunshots outside our house. They were 5 or 7 seconds apart. After the first one, I thought it might have been a backfire from the state route just on the other side of our neighbor's house. But the second gunshot convinced me of what they were. I tried calling the neighbor whose house was in the direction of the gunshot, but got no answer. His lights weren't on and we suspect that he might even be out of town. Our neighbor on the other side heard the gunshots too, and agreed that they were gunshots, not something else. I called 911 and the police showed up about 8:17pm. The first officer parked in our driveway and approached our front door with his hand on his gun, still holstered. There was a second police cruiser on the road that stopped in front of our house. I opened the front door and told the officer what we heard, but stayed inside. The officer said that they'd go check out the neighbor's property, and he took off across my front lawn. The other officer stayed in his cruiser and drove over to in front of the neighbors house. They searched the neighbor's property, the first officer on foot, and the second using the spotlight on his cruiser. About 5 or 6 minutes later the first officer came back to say that they didn't find anything. The neighbor's house was secure and they didn't find any bullet holes in the windows or walls of the house. The officer also verified that the cars parked in the neighbor's driveway were ones that I'd expect to be there. There was nothing else for them to do at that point and the officer told me not to hesitate calling 911 if anything else happened. The officers then hurried away. I got the impression that they were probably pretty busy on a Halloween night. All in all, I think the police showed up fairly quickly and did a good job investigating the incident. I don't like not knowing what actually happened, but at this point I don't think I'll ever know. My wife thinks that it might have been someone just shooting out of their car as they drove by, but I don't think that was what happened because the shots were too far apart to be coming from a moving car and not sound differently. I still haven't gotten a call back from the neighbor whose house the shots sounded like they came from, but maybe that will provide more insight. Labels: misc
My first goal on 43 Things was to create a blog, so here we are. I'm planning on using this blog to post topics about software development, but I may sneak in something personal every now and then. Now it's time to change that goal to something like "don't let your blog stagnate." Labels: blog
I'm working on a new project where I laid out the class structure in ArgoUML and generated the C# code. This was my first time using ArgoUML and I found that I didn't like the generated code that much, and had a lot of changes to make. One such change was to refactor my public members into private members exposed by public properties. In Visual Studio 2005 this is no problem with the built in refactoring. This project, however, needs to use the 1.1 .NET framework, so I'm stuck using Visual Studio 2003. So I resorted to Find & Replace using Regular Expressions. The regular expression used for the Find: ^{:b*}public {:a+} {:a+}; And the expression used for the Replace: \1public \2 \3\n\1{\n\1\tget { return m_\3; }\n\1\tset { m_\3 = value; }\n\1}\n\1private \2 m_\3; This results in code like this public string Name;
being replaced with this public string Name { get { return m_Name; } set { m_Name = value; } } private string m_Name;
I suppose it would be a little better to somehow replace the capital first letter in the private member with a lower case equivalent, but it's not really that big of a deal ... at least, not big enough to spend more time on this task. Edit: I need to come up with a better format for posting code. Labels: programming, regex
|