.NET and me Coding dreams since 1998!

14Apr/070

Enterprise Library a její použití v praxi | Altairis – kalendář akcí

 

Jan Seda and me would have a session on June 6th on Enterprise Library 3.

Session would be on english language and it would include general How-To's, What's new and presentation of two new blocks

So, please register for the session on Altairis site (link on bottom) if you are interested.

Hope to see you there :)

Link to Enterprise Library a její použití v praxi | Altairis - kalendář akcí

Filed under: Uncategorized No Comments
6Apr/070

Daniel Tammet – A beautiful mind

Daniel Paul Tammet (b. January 31, 1979, London, England) is a British autistic savant, gifted with a facility for mathematics problems, sequence memory, and natural language learning. He was born with congenital childhood epilepsy.

In March 2004, Daniel set a European record when he recited the famous mathematical constant Pi from memory to 22,514 decimal places in a time of 5 hours. He has been extensively studied by scientists at California's Center for Brain Studies and at the Cambridge Autism Research Centre UK and has been described as autism's 'Rosetta Stone'.

Take a look at 40 minutes Google video with him at

http://www.therightstuff.de/2007/04/01/The+Boy+With+The+Incredible+Brain.aspx

Source: Daniel Tammet - Wikipedia, the free encyclopedia

Technorati tags:
Filed under: Uncategorized No Comments
5Apr/072

Q&A: 30 second OOP trick question

To get a fast answer how good job candidate is in OOP thinking give him up to 30 second to give you an answer what is the output of next console application



using System;

namespace Example
{
    class Program    {
        static void Main(string[] args)
        {
            TypeB example = new TypeB();
            Console.WriteLine(example.ToString());
            Console.WriteLine(((TypeA)example).ToString());
            Console.WriteLine(((object)example).ToString());

            Console.ReadLine();
        }
    }

    public class TypeA:System.Object
    {
        public override string ToString()
        {
            return "Hello from TypeA";
        }
    }

    public class TypeB : TypeA
    {
        public override string ToString()
        {
            return "Hello from TypeB";
        }
    }
}


 


Technorati tags: , , , ,

Filed under: Uncategorized 2 Comments
5Apr/071

The Testable Object Pattern

 


Brad Wilson posted about Testable Object pattern which is a n interesting technique how to approach the fact that MVP Presenter constructor  signature can change during the time and by that broke our tests already written


What he is suggesting is defining the new type which would inherit from presenter type and expose static factory parameter method  and internally it would initialize elements of the the presenter constructor.


Looks cool except of the next things:


a) How we would handle different presenter constructors? (If we define overload Create methods we are breaking compatibility later again)


b) I'm not a big fun of creating *helper* types in test classes which are supposed only to support tests. Our tests should test only the "production" types, not the test types - no matter how primitive wrappers they would be...


I think much cleaner solution of the problem Brad is speaking is instead of defining new test type we should solve the problem in presenter type itself


 


Instead of constructor type of dependency injection we can use setter type and define inside of presenter two properties


IView View {set;}


IService Service {set;}


and then replace the presenter its constructor with static factory method (Presenter.CreateNewPresenter()).


That's how  we could solve the problem of test breaking changes of presenter constructor signature without adding additional types


 


Link to The Testable Object Pattern


 


Filed under: Uncategorized 1 Comment
4Apr/070

ISerializable – Roy Osherove’s Blog : Testable Designs – Round 2: Tooling, Design Smells and Bad Analogies

 


Very interested discussion about Test Driven Design approach; is it productive ore over complex.. Raises a lot of ideas and gives a lot of different opinions.. Check it out


Eli Lopian, the guy who runs TypeMock.NET(An amazing Mocking product, BTW - a bit too powerful for it's own good, perhaps) and myself share what seem to be conflicting views on how "Testable" object Oriented applications should be out of the box  that is, should or shouldn't you be considering Testability when designing your software, and how much would you let Testability considerations change your design (add interfaces, exposes some methods, allow polymorphism etc..).


Source: ISerializable - Roy Osherove's Blog : Testable Designs - Round 2: Tooling, Design Smells and Bad Analogies


 


Filed under: Uncategorized No Comments
4Apr/070

InfoQ: TestDriven.Net Once Again Supports VS Express Editions

 



TestDriven.Net has restored and enhanced support for the Visual Studio Express Editions in the 2.5 beta despite tensions between Jamie Cansdale and Microsoft over license concerns.

TestDriven.Net is a unit testing add-on that supports multiple frameworks including NUnit, MbUnit, and MS Team System. It is free for casual users and starts at $95 for professional and enterprise users.


Source: InfoQ: TestDriven.Net Once Again Supports VS Express Editions


 


Technorati tags: , , ,

Filed under: Uncategorized No Comments
3Apr/070

Designing .NET Class Libraries

.NET CLR team did a series of classes covering general design practices of .net based frameworks and made them available for free


This is simply too good to be true :)


Link to Designing .NET Class Libraries


 


Technorati tags: , , ,

Filed under: Uncategorized No Comments
2Apr/070

Somasegar’s WebLog : New/updated Icon Sets with Visual Studio 2005

In case you've asked yourself the same question I've asked myself - how to "steal" Visual Studio 2005 icons to get your application uniform look & feel, the answer is: no need to -> Microsoft published them last year officially


Check it out :)


Link to Somasegar's WebLog : New/updated Icon Sets with Visual Studio 2005


 


Technorati tags: , ,

Filed under: Uncategorized No Comments
1Apr/075

Gotcha – Improper exception handling

I was reading today a document written by Juval Lowy from IDesign "C# Coding standard - Guidelines and Best Practices V2.2" and under No 17 rule in Coding Practices I found next thing:

17. In a catch statement that throws an exception, always throw the original exception (or another exception constructed from the original exception) to maintain the stack of original error:

catch (Exception exception)
{MessageBox.Show(exception.Message);

throw exception;
}

I think this definitely is not a best practice, and I'll try to explain why:

throw ex

The problem this practice tries to solve is that in case of rethrowing of exception in catch block stack pointer moves from the original exception line to line of rethrowing of exception

   1: using System;
   2: namespace ThrowExample
   3: {
   4:     internal class Program
   5:     {
   6:         public static void ThrowException()
   7:         {
   8:             throw new NotImplementedException("Exception thrown!"); //Line 8
   9:         }
  10:  
  11:         private static void Main()
  12:         {
  13:             try
  14:             {
  15:                 ThrowException(); //Line 15
  16:             }
  17:             catch (Exception e)
  18:             {
  19:                 Console.WriteLine(e.Message);
  20:                 throw e; //Line 20
  21:             }
  22:         }
  23:     }
  24: }

Stack result would be

"Exception thrown!"

at ThrowExample.Program.Main() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 20

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
...

That's why IDesign suggest MessageBox printing of stack trace before it is been destroyed, but this is bad practice because it is:

  • Approach tied to specific UI technology (what with ASP NET app?)
  • Disables loging of exception through Log4Net  or EntLib block
  • Relies on developer to read the message and makes some action (when he clicks ok button all traces of the exception log are disappearing)

throw;

Instead of MessageBox printing the proper way is to use throw; call which doesn't destroy stack trace.

So our example. enhanced with throw; would be:

   1: using System;
   2: namespace ThrowExample
   3: {
   4:     internal class Program
   5:     {
   6:         public static void ThrowException()
   7:         {
   8:             throw new NotImplementedException("Exception thrown!"); //Line 8
   9:         }
  10:  
  11:         private static void Main()
  12:         {
  13:             try
  14:             {
  15:                 ThrowException(); //Line 15
  16:             }
  17:             catch
  18:             {
  19:                 Console.WriteLine("Exception happened");
  20:                 throw; //Line 20
  21:             }
  22:         }
  23:     }
  24: }

and then stack would be

"Exception thrown!"

at ThrowExample.Program.ThrowException() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 8

at ThrowExample.Program.Main() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 20

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
...

no try - catch

But there is one more problem: In "throw;" case of we are not seeing in stack trace line 15 which we would see in case we didn't have try-catch-block.

   1: using System;
   2: namespace ThrowExample
   3: {
   4:     internal class Program
   5:     {
   6:         public static void ThrowException()
   7:         {
   8:             throw new NotImplementedException("Exception thrown!");
   9:         }
  10:  
  11:         private static void Main()
  12:         {
  13:             /*            try
  14:             {*/
  15:             ThrowException();
  16:             /*}
  17:             catch
  18:             {
  19:                 //Console.WriteLine(e.Message);
  20:                 throw; //Line 20
  21:             }        */
  22:         }
  23:     }
  24: }

and then stack would be

"Exception thrown!"

at ThrowExample.Program.ThrowException() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 8

at ThrowExample.Program.Main() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 15

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
...

The way how we can see all of the important stack exception data is next one:

throw ex + inner exception

   1: using System;
   2: namespace ThrowExample
   3: {
   4:     internal class Program
   5:     {
   6:         public static void ThrowException()
   7:         {
   8:             throw new NotImplementedException("Exception thrown!"); // Line 8
   9:         }
  10:  
  11:         private static void Main()
  12:         {
  13:             try
  14:             {
  15:                 ThrowException(); // Line 15
  16:             }
  17:             catch (Exception e)
  18:             {
  19:                 Console.WriteLine(e.Message);
  20:                 throw new Exception("Some message", e); //Line 20
  21:             }
  22:         }
  23:     }
  24: }

the main stack result would be

"Exception thrown!"

at ThrowExample.Program.Main() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 20

and the inner exception stack trace would be

at ThrowExample.Program.ThrowException() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 8
at ThrowExample.Program.Main() in D:DocumentsDocumentsBlog materialThrowThrowExampleThrowExampleProgram.cs:line 15

So only on this way we could get all the data needed

 

Therefore, I believe that only the last approach (maybe the throw; approach could be ok)  is the approach which deserves to be described as best practice

Don't you think so?

Technorati tags: , , , ,

Share this post :

Filed under: Uncategorized 5 Comments