Sunday, June 24, 2012

Syntax Highlighter - Show code directly in your Blog

You may have noticed that in the recent gridview radio button blog post, that I had code formatting directly in the blog post. This is something that you cannot easily do with blogger. Bummer. I recently came across Syntax Highlighter, and it allows a syntax highlighter to be implemented into any web page (or blog) with a few lines. It works for a number of languages, and is open source. I really like it so far.

Friday, June 22, 2012

RadioButtonGroup Across Multiple Rows in a Gridview

At work, I have a grid view, and in that grid view, every row is a different option. .Net is too smart for its own good in this case, as it puts every radio button in its own group rather than allowing you to use the same group along multiple rows. As a result, when you go to use the radio buttons, they do not deselect the previous selected option. So I thought about this from my point of view. How would I break it down?  Here's what I came up with.

Loop through every row, and find the radio button you want, then turn it off. Go back to the radio button that was originally selected, and then select it. We can do this because we can go back to the sender, find it, and modify it. Here's the code that does it:

protected void rdoPolicy_CheckedChanged(object sender, EventArgs e)
{
      DeselectRBButtons();
      RadioButton sendingRB = (RadioButton)sender;
      sendingRB.Checked = true;

}

private void DeselectRBButtons()
{
      int x = 0;
      foreach (var gridviewRow in grdPolicies.Rows)
      {
          var rb = (RadioButton)grdPolicies.Rows[x].FindControl("rdoPolicy");
            rb.Checked = false;
      x++;
      }
}

Monday, June 4, 2012

Improving the quality of software using Code Reviews

Peter Sergeant recently wrote an article about code reviews. He had a lot of really interesting points and ideas about code reviews, like using a review tool, and scheduling review time regularly. I've never really used a review tool, but I use ReSharper's ToDo Explorer to keep track of notes, review areas, and code smells. I like the idea of a regular review, but in some teams (especially where I work today), I highly doubt it would work. 
I believe code reviews are an invaluable tool that have in your SDLC. I believe this because it does many different things. Code reviews help improve code quality coming from all developers, it helps enforce domain level knowledge among developers, and allows for communication among developers to be opened up.
As a junior developer, I initially thought as code reviews as a way to improve my code quality. I was easily intimidated, and insecure in what I was producing. I stuck with it, and after the second review or so, I learned that wasn't the case.  There is a sense of "You don't know what you're doing," at times, but you can't have that attitude. I believe everything is done for a reason, and that every developer chose a specific solution for a reason. 
Code reviews allow developers to ask questions, and learn new things. For example, if I had a question how to write an automated unit test a specific area, I could put a note in there asking for help. "Is this sufficient for testing?" is a review note I frequently had. By finding those areas, and having a conversation about them you're producing better quality code, and then you're going to be able to build on top of that quality to ask better questions such as "Can we use a row test to increase the efficiency of these test?" Further more, when I looked into more experienced developers' code, I see new methods and patterns I've never seen or used before. I can then ask questions about them. If these patterns are easy to make sense, the senior developer will easily be able to explain his logic. If he can't then there probably needs to be some refactoring.
Domain level knowledge is very difficult to obtain. On all of my major projects, they've been on subjects that I know nothing about. I've always talked to the users to get information I needed. But as I became more exposed to that project and product, I was able to contribute that knowledge to newer developers.  As an example, I may say "This is unnecessary for us to write because we've never allowed users to input strings into this field." That is communicating business rules and experience into each others' code base.
Finally, it forces communication about architecture among developers. I see a lot of code duplication in my project I currently work on. I found nearly the same functionality in 7 different spots. And when there was a bug, I had to go in and fix it in 7 different spots. The question of "Can we tear that out and put it in one spot?" was asked. However, I asked the question of, "Why is it this way in the first place?" There's always a reason - even if it is laziness. Unfortunately, it took me 3 attempts to find all 7 spots. So it looked like I had a ton of bugs come back. Had we had a code review on the development on one of these areas, perhaps we may have said "Keep it DRY", and go forward. Maybe the developer didn't know about the other six spots with that functionality? Perhaps it can go into a class with other similar functionality that another developer is working on?
So code reviews are valuable for a number of reasons, to anyone of any skill level. I've only listed some of the reasons here, but it is interesting to think about. I'd like to hear stories and reasons for others' stances on code reviews.

Friday, June 1, 2012

My Favorite Chrome Extensions

Adblock Plus

Adblock Plus prevents advertisements from being displayed to you. Nearly any big time website now has advertisements on it, and when you visit them regularly, you’re going to become annoyed and get a lot of the same advertisements regularly. It doesn’t matter if it is a video, a banner, text link or even pop up – it gets blocked.
I understand that advertisements help fund the websites I visit. I understand that advertisements help inform me of products that are available. However there are simply too many. Without Adblock Plus, I get advertisements for hockey and software related products all the time. When I go to YouTube I have to watch an advertisement that is longer than the video itself.

Copy Link Text

Copy Link Text is a very simple, but effective extension for copying and pasting links. While I don’t use it regularly, when I do use it, it saves me a lot of time. Rather than having to highlight the link (which can be difficult based on how the browser behaves sometimes), then copying it, I can just right click on the link and select “Copy Link Text” and the text displayed is what goes to my clip board. I use it regularly when in my bug tracking system at work.

Firebug Lite

Firebug Lite is a great tool when it comes to  development. I use it a lot when it comes to styles so I can examine the styles being applied, where they’re coming from, as well as modify them right in the browser to see what rules I need.
However, The DOM explorer, as well as script viewer also makes this tool extremely beneficial to anyone doing front-end web development. There is a console tab as well that looks like a glorified console for JavaScript debugging and logging but I have yet to use it.

TweetDeck

A popular tool for your social media needs. TweetDeck allows you to log into multiple twitter accounts, and maintain them all in one area. It is great for people who run different online brands, and don’t want to have to log into many different accounts. Simply compose your update, select which account(s) you want that update posted to and go.
You can also schedule posts, post images, use their auto link shortener, follow trends, and a few other interesting little tools.

Checker Plus for Google Calendar 

The newest addition to my extensions is CheckerPlus for Google Calendar. This extension is fairly powerful and integrates with Google Calendar. In the corner of your screen, a small notification will show up when you’er coming up on an appointment. You can snooze it if you like but it will come back. It is a lot like the notifications for Outlook, but using Google Chrome.
You can also schedule new events in your calendar right from your browser by clicking a button. While there are a ton of configuration settings, it makes it very powerful and a bit overwhelming at first. But once you set the settings to how you want them, you really never go back into it.