|
Tuesday, June 23, 2009
Recently I worked with a colleague on some code using decimal.TryParse() and tried to find a better way of using it. Specifically I had a string value representing a currency amount entered by a user in a web form. The amount needed more than just normal validation, so I needed to do some stuff with it. Here's the code I started with: public void SomeMethod(string userEnteredAmount)
{
decimal amount;
if(decimal.TryParse(userEnteredAmount, out amount) {
//Do some stuff with amount
}
else {
//Show message to user about invalid amount
}
}
I've recently found many cases where I find the use of Value Objects to be very applicable. I found this case to be a particularly interesting example. Anyway, I created a Value Object called Amount to abstract away the TryParse stuff. Below is the class I created.
public class Amount
{
private readonly decimal _value;
private readonly bool _isValid;
public void Amount(string amount)
{
_isValid = decimal.TryParse(amount, out _value);
}
public decimal Value
{
get { return _value; }
}
public bool IsValid
{
get { return _isValid; }
}
}
See how clean it got? At least I think so. The important part though is that it's usage is so much easier to understand and read:
var amount = new Amount(userEnteredAmount);
if(amount.IsValid) {
//Do some stuff with amount.Value }
else {
//Show message to user about invalid amount
}
It's more code, but cleaner. Or did I say that already? And of course it's reusable other places where amount has a meaning.
Thursday, June 04, 2009
Sunday, May 17, 2009
When so called secure institutions like banks, insurance companies and others ask you to create a password, you expect them to allow strange characters like ,.$#@{}[] to make the password stronger. To my surprise on several occasions I’ve experienced that they did not accept other than plain letters and numbers! What!? Didn’t the developer that implemented that logic raise a flag?? One specific case is with BankId (a national authentication mechanism for all banks in Norway), where I know the underlying implementation support strong passwords. However, when prompted by my bank to create the password, you’re not permitted. Actually I had to type in a temporary weak password and then change the password in the login screen which support the expected behavior! At some point there had to be a discussion like this: Developer: What type of password should we support? Product Owner: What do you mean? Developer: Should we allow people to make up their password from everything that they can find on their keyboard? Product Owner: No, the normal alphabet and numbers should be sufficient. Or else people just forget their passwords. My above experience with BankId was just an example from today, and in that case there were a workaround, which is not the common case. I always get puzzled when this happens. What puzzles me even more is that to prevent people from entering strong password, you actually have to code a business rule for exactly that! And what about those who only permit numbers!? What’s that all about? Sorry for this rant, but I think it is important that we as developers, architects and technically skilled people take responsibility to avoid stuff like this to happen. I just can’t see one single good reason for limiting the users choice when it comes to passwords.
Saturday, May 16, 2009
This is a non technical post to add even more pressure on myself than the actual investment of my new bike and associated equipment. I found it was about time to add some physical fitness to my life other than moving from the computer to get coffee or to and from the car on my way to work  So this is a promise to myself (and now to the rest of the world I guess) that I will ride my new racing bike to and from work whenever the weather permits (read not snow or ice). However, I might need a few weeks of training to actually physically be able to get to work on a bike 
Sunday, May 03, 2009
Are you using InfoQ? I found InfoQ to be a great source of information long before I started to write for them. During this time I’ve discovered some tips and tricks on the site. As a user of the InfoQ website you can either just browse news or you can take advantage of some of the more advanced features the site has to offer. Disclaimer: This information is based on my personal usage of the InfoQ.com website. There might be more functionality available (and probably is) or I might be wrong about some functionality I’ve covered here. Website functionality Not functionality per say, but in the top left corner you see how many visitors InfoQ has on a monthly basis. Here showing almost 400.000 visitors for March 2009, which I think is pretty good! On the left hand side there is a list of all the communities that InfoQ writes about. Un-checking communities let you filter out stuff you’re not interested in. Clicking on any community you will see all content from that community. Based on your community selections above you can get a personalized RSS feed, that of course gets updated whenever there are new content on InfoQ.  On the right hand side of the site, there is a box with tabs showing Articles, Presentations, Interviews and Books and one tab showing All. This is a great source of info which I learned to appreciate quite late. Today I use it very often, especially to find recent presentations and interviews. Note: All content you see here will also be announced as news items.
InfoQ publish content in four different languages: English, Chinese, Japanese and Portuguese. In the top right corner of the news section there is a button for contributing news. Use this for suggesting tings you want InfoQ to cover or maybe you have an interesting article that you want InfoQ to consider publishing? Other options If you are a registered logged on user, you can go to Preferences and check the box for the InfoQ Newsletter. This will give you a summary of the content for the past week. If you don’t have time to monitor the website on a regular basis, this is a nice option for many. InfoQ also have it’s own bookshelf written by several different authors, many of them being editors for InfoQ. Books currently available for free online reading (print version at a small cost): URLs Community By adding the name of the community behind the infoq.com URL you get a page displaying featured content, news, articles, interviews, presentations and books about that particular community. For e.g. NET you would use http://www.infoq.com/dotnet. Topics By clicking on a topic, e.g. you get a box like this: It’s quite self explanatory, but the Exclude might need some extra explanation. On InfoQ you can exclude topics you don’t want to show up on the website. So let’s say I want to follow what’s going on in the .NET queue, but I don’t want to see anything about Windows Forms, I can do that by selecting a topic as showed on the left or go the Preferences and add that topic to my exclude list. Tags Tags work much in the same way as Topics, except they’re tags and not topics Twitter InfoQ is also present on Twitter. You can follow at http://twitter.com/infoq or just add @infoq to your Twitter client. Planet InfoQ - Opinions and Perspectives from InfoQ Editor’s Personal Blogs The title kind of says it all Check out http://planet.infoq.com. Here you’ll also find Tweets from all the editors on Twitter.
Saturday, May 02, 2009
About a month ago I was contacted by Kjersti Sandberg at Programutvikling. She asked if I knew about any companies in Bergen that would be interested in having a full day seminar with Mary Poppendieck. I figured this was a great opportunity and contacted some of the companies I knew in Bergen. Webstep found this very interesting and invited customers and employees for a full day seminar with Mary. At the same time I asked if she would be interested in doing a talk at NNUG, which she did! So, If you haven’t seen this already, the invite is out, so go sign up (for free!). Mary is well known for her experience and knowledge within the Lean and Agile community: Mary Poppendieck has been in the Information Technology industry for over thirty years. She has managed software development, supply chain management, manufacturing operations, and new product development. She spearheaded the implementation of a Just-in-Time system in a 3M video tape manufacturing plant and led new product development teams, commercializing products ranging from digital controllers to 3M Light FiberTM. Mary is a popular writer and speaker, and coauthor of the book Lean Software Development, which was awarded the Software Development Productivity Award in 2004. A sequel, Implementing Lean Software Development, was published in 2006. A third book, Leading Lean Software Development, will be published in late 2009. Please feel free to forward this to anyone within your company or to your friends, because this event has a much broader crowd than the usual NNUG crowd of developers and architects. At least your manager should have this in her/his inbox by Monday morning 
Thursday, April 30, 2009
A good friend of mine, Mark Nijhof, will be doing a presentation on FubuMVC at the next European Virtual Alt.NET meeting. Mark is actively involved with the alternative MVC framework for ASP.NET together with Chad Myers and Jeremy D. Miller. Mark will also do a Fubu presentation at NNUG Bergen 27th of May (invitation will be available soon). If you want to know more about FubuMVC you can check out the interview I did with Chad on InfoQ and of course their public website. I encourage you to download Fubu and try it out, cause it has some interesting differences which I personally like compared to ASP.NET MVC. Also, Jeremy Miller is coming to Bergen and NNUG in mid June just before NDC (thanks Mark for organizing this!), so I’m really looking forward to that. A lot of stuff happening at the local community in Bergen at the moment!
Tuesday, April 28, 2009
Is there anything more annoying than standing on a red light, when there is no car, motorcycle or carbon life form in sight? Maybe traffic lights elsewhere in the world are more intelligent, but at least where I live this happens from time to time. So what have this to do with developers? Good question, but let me first try to answer another one: Why do we have traffic lights? From Wikipedia: Traffic lights, also known as traffic signals, stop lights, traffic lamps, stop-and-go lights, robots or semaphore, are signaling devices positioned at road intersections, pedestrian crossings, and other locations to control competing flows of traffic. I read: bla bla bla bla… control competing flows of traffic. I would probably have said something like this: To avoid cars running into each other and avoid have people run over in a cross road. It’s a very logical way of saying stop or drive (red and green). Yellow is the same as green, but for taxis only. Traffic lights are regulated by sensors in the ground detecting where there is traffic and not + a algorithm to give green lights in a predefined order. Now back to the first question, answered by asking a new one: What’s the equivalent of traffic lights in development? No, not red, green, refactor I was thinking about frameworks, internal DSL’s and the like. Stuff that good developers create, which the not so good developers should use. To keep them from “hurting” themselves or the company they work for. Do you find that to be ok?
Monday, April 27, 2009
Just a reminder that it will be Geek Beer tomorrow (Tuesday 28th) at Biskopen Pub (Neumanns gate 18) from 19:00. No official signup, but by leaving a comment here I can make sure there is enough seats for everybody. See you all there!
|
| |
|
|
|
|
| |
| June, 2009 (2) |
| May, 2009 (4) |
| April, 2009 (7) |
| March, 2009 (7) |
| February, 2009 (4) |
| January, 2009 (4) |
| December, 2008 (7) |
| November, 2008 (1) |
| October, 2008 (6) |
| September, 2008 (7) |
| August, 2008 (4) |
| July, 2008 (3) |
| June, 2008 (7) |
| May, 2008 (7) |
| April, 2008 (5) |
| March, 2008 (3) |
| February, 2008 (9) |
| January, 2008 (3) |
| December, 2007 (4) |
| November, 2007 (10) |
| October, 2007 (10) |
| September, 2007 (2) |
| August, 2007 (6) |
| July, 2007 (6) |
| June, 2007 (3) |
| May, 2007 (2) |
| April, 2007 (8) |
| March, 2007 (6) |
| February, 2007 (5) |
| January, 2007 (10) |
| December, 2006 (9) |
| November, 2006 (5) |
| October, 2006 (8) |
| September, 2006 (5) |
|
|
 |
 |
|
|