Monday, April 1, 2013

Async and Parallel Programming in .NET 4

I spent some time recently on some of the latest features of .Net. One area I overlooked a while back was Async and parallel programming. I've done mostly web development and it hasn't always been beneficial to me. Lately I've expanded my talents, and this has come into play.

Essentially the Task Parallel Library (TPL) helps add parallelism to your application without having to worry too much about your thread pool or exceptions. You have to worry about these things, but the TPL has really helped out in the simplification of these areas. This is important because as technology advances, our applications need to be more snappy. For example, on the Windows Store applications, you may have multiple threads happening, but you cannot lose responsiveness to your application. Microsoft will reject your application if it does not respond.

Tasks are the fundamental building block. I think of tasks as function that will consume a large number of CPU cycles or require information from a third party. If we had a single threaded application, we'll be forced to wait for these functions to complete. However, we can create a task that will start up another thread and we can go on our doing other things.

As always with multi threading, there is additional complexity versus having a single threaded application. The TPL helps handle these issues. Each task will have a status, a result, and an exception that can be checked for processing. How variables are passed into tasks will impact your results. The order of execution can also be impacted because of multiple threads running at the same time. The TPL helps you handle it all.

I'm going to spend some time focusing on a few different areas of the TPL and show how they may be able to help you out in development.

Friday, February 22, 2013

Securing Information In Your Database - Introduction

As a security precaution, it is important to not save any sort of sensitive information in clear text in your database. This can be information such as an email address, a social security number, answers to secret questions – or anything that would be considered sensitive data for the user.

For most people, it is surprising how a little bit of information can lead to malicious attacks. They use the same account names, emails, passwords, and secret questions for all of their accounts, so if you get one, you probably have them all.

I’ve seen an unfortunate amount of sensitive information stored in clear text from applications I have worked on. When I ask why it is done this way, no one has an answer. The response is always “it is just always the way it has been.” I don’t find this to be an acceptable answer as when you do your initial design, you know it needs to be done.

My next few posts will talk about encryption, hashing, and security in general. 

Sunday, July 1, 2012

Pro jQuery - Chapter 4 (JavaScript Primer)

It took me forever to go through this chapter. It was incredibly slow, and nothing too interesting. If you're reading a book on jQuery. jQuery has its bases in JavaScript, so a key foundation for it is JavaScript. Plus a lot of it was so long, with many examples that I went through on principal that it just got me really uninspired. I am glad to have finished it.

So it uses a lot of console logging, and created objects for its own demonstrations. It went into how you'd add a method onto a function, which is very different from how you would in c#. It was actually very good at explaining how to determine if an object has a property, explaining the differences between null and undefined. I spent a good portion of my time on this since it is a little different from c#.

The book did touch on array methods, but didn't go into depth. I'm glad about this because as I said earlier, it was longer than it needed to be.

So they had to put this chapter in for sure, but I feel that it was still a little long. It isn't really going to be of any assistance if you have a problem. You're going to need to go to another JavaScript reference and look at it there.

I am excited though because I see the next part is called "Working with jQuery".

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)
      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;

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.


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.