Showing posts with label DotNet. Show all posts
Showing posts with label DotNet. Show all posts

Monday, May 4, 2009

Complemeting FxCop with StyleCop!

I guess we all know FxCop by Now. But do you know about StyleCop?

StyleCop is a Source Code Style and Consistency Tool.

... FxCop performs its analysis on compiled binaries, while StyleCop analyzes the source code directly. For this reason, FxCop focuses more on the design of the code, while StyleCop focuses on layout, readability and documentation. Most of that information is stripped away during the compilation process, and thus cannot be analyzed by FxCop. ....

See: http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx

Happy Styling!

Thursday, November 6, 2008

Whats new in DotNet 4.0 (pdf)

Take a look at this .pdf to get a good but quick impression about the new types and namespaces included asof Dotnet 4.0 (and 3.5 servicepack 1).

http://brad_abrams.members.winisp.net/Projects/PDC2008/PDC2008-NETFX4.pdf

I think there is enough for everybody to benefit.

For me I particularly like:
  • the new biginteger datatype that is part of the new core;
  • the new concurrent-collection;
  • the mvc framework that is included;
  • the many new classes for the workflow framework;

What I like less about this release:

  • the entity framework seems part of this release. My experiences sofar before it was included in this release were disappointing;
  • in my opinion, the unity should have been part of the core;
  • new ajax stuff, but i would bet my money on jquery. No microsoft ajax for me anymore for a while;

Monday, November 3, 2008

My Favorite Code Snippets (Visual Studio)

Below, my ever growing list of my favorite Code Snippets:



happy Snippeting!

Sunday, July 6, 2008

Microsoft Arrowhead (DotNet)

Finally, I just found the time to download, install and play a bit with the DotNet Framework 3.5 Service Pack 1 (beta).

Part of this service pack seems to be something called "ArrowHead". As we are used from Microsoft, this is still the codename of course.

As I understand this "ArrowHead"is about supporting occasional connected clients.

Let me know what your experiences when you have taken the time to play with it. There is not much information available to me yet, but have a look at wiki:

http://en.wikipedia.org/wiki/Microsoft_.NET#SP1_.28codename_.22Arrowhead.22.29

Happy Playing (with your arrow-head :)

Monday, June 30, 2008

Extension Properties? (DotNet)

I was just wondering...

Its been allready a while since extension methods have been introduced. Hence, many of us hardly actively remember not having those methods available to us.

But I was wondering:
  • Where are the extension properties?
  • Do extension methods go against the Object Orentation principles?

What do you think?



Monday, May 26, 2008

Microsoft Posters (Biztalk, Visual Studio, DotNet)

Did you know that there are several excellent posters you can download from the Microsoft website? There are posters on many major topics including DotNet, Biztalk, Silverlight and Visual Studio.

Go check them out and download them here.

Below, as a preview, a list of the most populair posters.


Security & Reliability Co-Partner Marketing Poster 1
This contains marketing material which can be used by Microsoft Partners in the Microsoft Security and Reliability campaign. This download contains Poster 1.

BizTalk Server 2006 Capabilities
Lists BizTalk Server 2006 capabilities

BizTalk Server 2006 Runtime Architecture
Illustration of the modules and components of BizTalk Server 2006.

PnP Overview Poster pdf
PnP Overview Poster pdf

Security & Reliability Co-Partner Marketing Poster 2
This contains marketing material which can be used by Microsoft Partners in the Microsoft Security and Reliability campaign. This download contains Poster 2.

Microsoft® Silverlight™ 1.1 Developer Reference Poster
Microsoft® Silverlight™ 1.1 Developer Reference Poster

Smart Client Poster pdf
Smart Client Poster pdf

BizTalk Server 2006 R2 Scale-Out Configurations
This poster illustrates typical scale-out configurations and options.

Visual C++ 2008 Keybinding Poster
List of keybidings for Visual C++ language within Visual Studio and Visual C++ Express 2008

BizTalk Server 2006 R2 Database Infrastructure Poster
This poster depicts BizTalk Server databases and associated components, jobs, services, UI, and events.

2007 Office System Document: Open XML Developer Map
Download this poster to learn more about Open XML File Formats.

Visual C++ 2005 Keyboard Shortcut Reference Poster
This poster contains the default keybindings for Visual C++ 2005, and is available as a PDF download in either color or grayscale for you to print.

BizTalk Server 2006 R2 Poster
This poster lists the BizTalk Server 2006 R2 capabilities.

BAM Poster for Microsoft BizTalk Server 2006 R2
The BAM poster for BizTalk Server 2006 R2 enables both new and experienced users to better understand the concepts, processes, and management of BAM.

TechNet Magazine Active Directory Component Jigsaw Poster
Active Directory Component Jigsaw poster, originally printed in the March-April 2006 issue of TechNet Magazine.

BizTalk Server 2006 R2 Runtime Architecture Poster
This poster provides a detailed illustration of the modules and components that make up the BizTalk Server 2006 R2 runtime architecture. It shows typical message flow and data flow that occurs between these components at run time.

Windows Server 2008 Component Posters
Windows Server 2008 Component Posters, originally printed in the July 2007 issue of TechNet Magazine.

NET Namespaces Poster
The .NET Framework 3.5 Common Namespaces and Types Poster

Visual Basic 2008 Keybinding Poster
Printable wall poster containing list of useful keyboard shortcuts for Visual Basic 2008 developers

2007 Office System: Developer Posters
Download these posters to learn more about the new features and enhancement to the 2007 Microsoft Office System.

Sunday, May 18, 2008

Defensive Programming (Spec#, DotNet)

Do you apply Defensive Progamming techniques?

Based on my experience, changes are good that you are not.
If so you may be missing out on many benefits such as:
  • Producing easier to use, understand, and maintain class-libraries;
  • Havinging applications that are much easier to support and test;
  • And last but not least, having more secure code.
In other words: defensive programming makes your solutions more easy from many viewpoints. Which, to me, in itself is a goal.


So what is this defensing technique about?

Defensing is a concept that has many aspects to it (see WikiPedia here) but in this article I will focus on the ensuring that the so called "pre-conditions" are met instead of assuming they will be met.

I am sure you know what I am talking about we have to deal with this every day all of the time! Just think about all those function parameters that might have an invalid value when that function is being called. That integer parameter* that should not be zero or negative or that object-reference parameter that just should not be null for example. With defensing you always check those pre-conditions first and immediately throw an exception if one of them is not met.

In any application there are thousands of those "pre-conditions" that could and should be checked. Sure that sounds like lot but in fact when you do it from the start it is hardly any extra work and you start enjoying the benefits almost immediately returns your small investment . And with the help of a small (existing) library the equation is even more interesting! Let me explain what I mean:
  • For anybody, including yourself after a while, maintaining your code it is immediately crystal clear what your function cannot do or handle! In many cases there is no need to test if this new situation is supported, anymore;
  • If one of your methods is called with an invalid value a clear exception is thrown immediately. No more “Null Reference Exceptions”, for example, deeper in your library that are all too hard to trace! Which is only possible by developers nothing to do for the support department, over and over again.
  • Many security issues originate from an unforeseen use of an application or library. By making sure that all your, assumed ,preconditions are checked it becomes much less likely to have your methods begin misused.

Should I really use this? It sound like a lot of work!

Sure it sounds like it, but when you do this right this is certainly one of those so called "Low Hanging Fruits". Quick wins with huge benefits. If you would ask me just do it! Apply from the start of a new project or add when changing a function that already exists. A good programmer is a lazy programmer so make defensing more easy for yourself using Macro's, Tooling and a small library of perhaps extention methods!?


Oke, I am convinced! What do I need to do to start defensing, Today?

One of the first things we need to do is have a library that helps us easily check parameter values and throw the appropriate clear exceptions. You basically have three options here:

  • One option is of course to write your own; This has the benefit that the exceptions that you fully control the messages and types of exceptions that are thrown;
  • Another option is to use the assertion classes from any Unit Tests framework. The, architectural, downside to this is that you are using Unit Test classes and libraries in a production environment. Conceptually this is not wrong but as far as I know there are no practical downsides.
  • The last, certainly not the least, option is to use the upcoming, but already available, Spec# framework from the Microsoft Research department. Which has the huge benefit of having a framework specifically for this use on one side which comes with integrated Visual Studio support as well!

Spec# sounds really interesting! Where can I find more?

I will soon write an introductionairy article about this, so stay tuned!


How do you look at Defensing from an architectural point of view?

Architecture is about how things relate and about meeting stakeholder stakes:

  • The library classes that help to make your defensing easy should be part of your Core;
  • The information about the valid and invalid use of your methods should be part of your technical (generated) documentation. This is something, spec# nor sandcastle or nDoc, does not yet take into account but possibly could.
  • Defensing makes your class-libraries more easy to use, to maintain, to support and more secure. This is someting that should be in the interest of every stakeholder but in particular to the CTO and ICT (support)Managers.

We have been talking about defensing, but can’t I just see what it looks like?


Sure thing! To wrap things up I have included some examples below using my own practical little defensing framework. After all, we should not talk too much about coding, coding is something that you “just” should do!

public void example1(object parameter)

{
Defence.Object.MustNotBeNull(parameter);

}

protected void example2(object valueToAdd)
{
Defence.Boolean.ShouldBeFalse(_collection.IsReadOnly );

}

Does not look difficult does it? I told you so! The best things in live are the simple things...

Happy Defensing!

----

*) I know we might use an Unsigned Integer here, but this is not CLS-Complient thus in many not recommended to be used.

Wednesday, May 14, 2008

My Architectural debate on attributes (DotNet)

I really like the concepts of object orientation. Still, the longer I work with it the more and deeper my appreciation gets.

But lately, I have this tug that just won't go away. Something that is bothering me more and more. Something that just doesn't feel right. It is where Microsoft is going with the usage of attributes in the DotNet Framework.

Isn't "seperation of concerns" one of the main concepts of object orientation? Isn't one of the nice things of this that an object is or at least should be unaware of how it is used?

So why is it than that I have to add more and more attributes to my classes just to be able to use them? You must know what I am talking about. Just think about the "Serializable"-attribute. I don't change anything to the class. It was serializable allready but now I have to decorate it just to be able to use it in that way. Why? Same for exposing objects as services but also something trivial as security or needed permissions. Sure I can live with this but it really seems to be hot to use attributes these days. Think about the Enterprise Application validation block. I really consider those attributes to be a poor mans solution. (Note to myself: publish a proper concept for validation. Without attributes that is.)

What's wroning with "old fashioned" interfaces or exceptions?

If you would aks me I would have them ask Scott for permission for every attribute they want to add to ever wildgrowing list of attributes in the DotNet Framework.

That reminds me, the same is happening with .config-files. But fortunately that has been noticed by the community and Martin Fowler wrote an excellent article about this abuse.

Tuesday, May 13, 2008

Auto Implemented Properties (DotNet v3)

I just came across the option of using something called "Auto Implemented Properties" which is new to DotNet version 3.0.

The nice thing about this feature is that not only saves a lot of code in the simple scenarion where you only have a "dumb" property passing and returning a private field value in and out. But it is more conceptally right.

For example: public string Name { get; set; } will return a "true" property.

It is conceptually more right becauseit makes sure nobody access your fields instead of your properties like it should for an avarage application which makes it more readable and more maintainable. And there is less type redundancy aswell. Thus in my opinion this is more conceptually and practically right!

Just for the record: in many cases it is obvious (for sake of Anticipation Af Change) that you want to use a property and not just a field.

An example to fall in love with:

public class Contact
{
public string Name { get; set; }
public string Address { get; set; }
public int ContactNumber { get; set; }
public int ID { get; private set; } // readonly
}

Wednesday, May 7, 2008

Using Keyword (Using the Using)

I just had a small discussion about the "Using"-Keyword. A topic that everybody seems to have a slightly different, sometimes evan magical, view on. But what does it really do?

The "Using" keyword makes sure if an exception occurs during the life of an objectinstance or when that objectinstance goes out of the using-scope (thanks Edward Bakker) that the IDisposble.Dispose() method is called.

Nothing more, nothing less. That's all folks.

Because the IDisposble-interface is mostly implemented on objects that use managed resources it is often thought that it the "using"-keyword magically cleans up these resources but that is clearly not the case nor does it magically close open databaseconnections for example!

As a rule of thumb, you might want to use the "Using"-keyword for all objects that implement the IDisposable interface. Because this can be easyilly forgotton and because this should be part of every codereview this is an excellent candidate for a "CodeAnalysis"-rule. If it not allready is?

Happy cleaning!