Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Fredrik Normén

ASP.NET, AJAX, Silverlight, RIA, Architecture, Clean Code

  • Lazy Developers?

    When I was out with my new dog (I Chihuahua, wonderful dog), I was thinking about Defensive Programming and Design by Contract. I like to do some refactoring and help other people to write cleaner code etc,  not that I’m an expert in the area but I think most of developers can see stuff that blinds other developers during development. I remember a scenario that made me kind of mad, I often notice that some developers doesn’t even care to validate arguments on public API or other methods, they assume the caller pass in the right values. When I started to develop apps, I didn’t validate arguments (In know I was a noob ;)). But since I started to do validation, it reduces the number of bugs in my code, and the difference was big. But that isn’t the only reason I like to do validation. Another  reason is because the caller of the method should know if they have passed a wrong value, there are of course some other reasons also, but the main reason is make sure the caller or the method pass in the correct value, and if they do, they will get what they want.

    I notice that several developers today don’t care about validation, I ask them why and they all gave me the same argument “Why should I, it will only make me add more code and it’s boring to write code that checks values”. Can this be summarized that some developers are lazy?

    Maybe I’m stupid because I get mad when I hear that kind of argument, but I’m special ;)

  • Why can't I be satisfied when I'm looking back on old applications?

    Most of the time I build an application I  have the feeling "this is going to be a great app. Good design, nice written code and a perfect application". I think most of you had the same feeling sometimes. But when I look back on previous applications, I say "What!? NO!!! This is not good, well this could have been done much better ... omg! What have I done! .. what a bad method name....". I don't know why I often feel like that when looking back on my previous apps. When I'm looking back on my code, I always find something I could have done better. Why can't I just write the perfect app, so I can go back later and say to my self "Well Fredrik, this one is great, good work!".

  • Can the use of Extension methods break the Law of Demeter?

    To make an easy description of Law of Demeter we can summarize it to the following sentence:

    “In particular, an object should avoid invoking methods of a member object returned by another method.”

    What does this has to do with Extension methods? It depends on how it’s used. For example we have several Extension Methods for the IEnumerable interface, like Where and OrderBy. By using those methods we can easy select data out from lists, for example (I’m so worthless when it comes to give methods good name, and the following method is so stupid, but it’s only an example.):

  • ASP.Net MVC Framework - How do I design my apps with the MVC pattern and +P

    When I'm playing around with the ASP.NET MVC Framework I have created several prototype applications with different solutions to solve some "problems." In this post I will write down how I combine a Presentation Model (When I talk about Presentation Model in this post, I refer to a model which purpose is only to define a model for presentation purpose) with the MVC, it's what the P in MVC+P stands for. 

    When I build apps today I use Domain Driven Design and I use the MVC pattern in some of my web based applications. As many of you know the M in MVC stands for the Model and contains our entities, business logic can data access components. Often when I build my apps with the ASP.Net MVC Framework (still only use in as a prototype because the framework is under development) I create my own custom Controller Factory to support Dependency Injection (DI). For example I use constructor injection or setter injection to inject my Repositories or manual injection of Mock objects during test. I use Spring.Net as my DI framework because it’s the framework I like the most.