Laptop Scrolling

January 22, 2009

Recently I had a problem with my work laptop running Vista. I have a Dell with a Synaptics Pointing Device for a touchpad. For a while, I could not scroll using the touchpad gestures when working within Visual Studio. That really sucked. Scrolling is a must-have when coding.

I had googled it before, but to no avail. I tried again today and found a winner post.

Turns out, disabling UAC (which is annoying enough that I really don’t miss it) fixes the problem.

Thanks Acer Guy!


I Just Want to go Offline

January 8, 2009

Ok… Another TFS gripe. I like to whine…

So, why is there no obvious “I would like to take my solution offline right now” function within Visual Studio? I am using 2008 and you would think that would be a feature by now.

It was not obvious, so I went web searching and found this: http://blogs.conchango.com/olusolanoah/archive/2008/10/31/13006.aspx

Looks like you either need to do it command-line with the Tweak util or via the registry. THE REGISTRY!?!?!?!? Come on! This is the 21st century, right?


Visual Studio Perf

December 29, 2008

Visual Studio performance for solutions with a large number of projects truly, truly sucks… I am working on a project right now which has 78 projects in a solution, including installer projects, unit tests, UI stuff, etc.

I know what you are thinking: “The problem isn’t VStudio, the problem is the idiot who built a solution with 78 projects”. If you were thinking that, you are right. The problem here isn’t the scalability of VStudio, but “project sprawl” but here is the lesson I am trying to burn into my brain… Every time you create a new project, class library, unit test project, etc, ask yourself: “Do I really need this?” Chances are, you could just add a new folder to an existing project. It would save hours and hours of refactoring piles of projects and project references, dependencies, etc into a smaller number of workable projects.

Lesson duly learned…


PostSharp AOP

November 25, 2008

I have been investigating a way to include trace statements systematically throughout a very large application in .NET. I was directed to the PostSharp framework by a colleague. It looked interesting, so I did some research.

Performance

Consider the following code:

   1: public class Person
   2: {
   3:     [TracingAspect]
   4:     public void Save()
   5:     {
   6: #if SkipPostSharp
   7:         WriteEntryMsg("Direct Person.Save");
   8: #endif
   9:         Console.WriteLine("::Save start");
  10:         Thread.Sleep(2000);
  11:         Console.WriteLine("::Save end");
  12: #if SkipPostSharp
  13:         WriteExitMsg("Direct Person.Save");
  14: #endif
  15:     }
  16:  
  17:     public static void WriteEntryMsg(string source)
  18:     {
  19:         string msg = string.Format("OnEntry fired for: {0}", source);
  20:         writeMsg(msg);
  21:     }
  22:  
  23:     public static void WriteExitMsg(string source)
  24:     {
  25:         string msg = string.Format("OnExit fired for: {0}", source);
  26:         writeMsg(msg);
  27:     }
  28:  
  29:     private static void writeMsg(string msg)
  30:     {
  31:         Debug.WriteLine(msg);
  32:         Trace.WriteLine(msg);
  33:         Console.WriteLine(msg);
  34:     }
  35: }
  36:  
  37: [Serializable]
  38: public class TracingAspect : OnMethodBoundaryAspect
  39: {
  40:     public override void OnEntry(MethodExecutionEventArgs eventArgs)
  41:     {
  42:         Person.WriteEntryMsg("Aspect");
  43:     }
  44:  
  45:     public override void OnExit(MethodExecutionEventArgs eventArgs)
  46:     {
  47:         Person.WriteEntryMsg("Aspect");
  48:     }
  49: }
  50:  
  51: class Program
  52: {
  53:     static void Main(string[] args)
  54:     {
  55:  
  56:         Stopwatch sw = new Stopwatch();
  57:         sw.Start();
  58:         try
  59:         {
  60:  
  61:             AopTester.Person p = new Person();
  62:             p.Save();
  63:  
  64:         }
  65:         catch (Exception ex)
  66:         {
  67:             Console.WriteLine(ex.ToString());
  68:         }
  69:         sw.Stop();
  70:  
  71:         Console.WriteLine("*~*~*~*~*~*~*~*~*~*~*~*~*~*~");
  72:         Console.WriteLine("Elapsed milliseconds for Main: {0:n}", sw.ElapsedMilliseconds);
  73:         Console.WriteLine("*~*~*~*~*~*~*~*~*~*~*~*~*~*~");
  74:  
  75:         Console.WriteLine("DONE!");
  76: #if DEBUG
  77:         Console.ReadKey();
  78: #endif
  79:  
  80:     }
  81: }

Using a conditional compilation symbol, the code above either uses aspects to inject the Person.WriteEntryMsg code or calls it directly.

Without PostSharp injection, the following outputs to the screen:

OnEntry fired for: Direct Person.Save

::Save start

::Save end

OnExit fired for: Direct Person.Save

*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Elapsed milliseconds for Main: 2,015.00

*~*~*~*~*~*~*~*~*~*~*~*~*~*~

DONE!

With PostSharp:

OnEntry fired for: Aspect

::Save start

::Save end

OnEntry fired for: Aspect

*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Elapsed milliseconds for Main: 2,027.00

*~*~*~*~*~*~*~*~*~*~*~*~*~*~

DONE!

Results

Considering the above results, it appears that the PostSharp framework adds an additional 12 milliseconds of overhead for the same code to execute.

Injected Code

PostSharp performs IL weaving; injecting tracing and logging code into the assembly at build time. Here is an illustration of the code added by the component using our example above:

Without PostSharp

Here is the disassembled IL as shown in Reflector:

   1: public class Person
   2: {
   3:     // Methods
   4:     [TracingAspect]
   5:     public void Save()
   6:     {
   7:         WriteEntryMsg("Direct Person.Save");
   8:         Console.WriteLine("::Save start");
   9:         Thread.Sleep(0x7d0);
  10:         Console.WriteLine("::Save end");
  11:         WriteExitMsg("Direct Person.Save");
  12:     }
  13:  
  14:     public static void WriteEntryMsg(string source)
  15:     {
  16:         writeMsg(string.Format("OnEntry fired for: {0}", source));
  17:     }
  18:  
  19:     public static void WriteExitMsg(string source)
  20:     {
  21:         writeMsg(string.Format("OnExit fired for: {0}", source));
  22:     }
  23:  
  24:     private static void writeMsg(string msg)
  25:     {
  26:         Debug.WriteLine(msg);
  27:         Trace.WriteLine(msg);
  28:         Console.WriteLine(msg);
  29:     }
  30: }
With PostSharp

Here is the disassembled IL as shown in Reflector:

   1: public class Person
   2: {
   3:     // Methods
   4:     [CompilerGenerated]
   5:     static Person()
   6:     {
   7:         if (!~PostSharp~Laos~Implementation.initialized)
   8:         {
   9:             LaosNotInitializedException.Throw();
  10:         }
  11:         ~PostSharp~Laos~Implementation.~targetMethod~1 = methodof(Person.Save);
  12:         ~PostSharp~Laos~Implementation.AopTester.TracingAspect~1.RuntimeInitialize(~PostSharp~Laos~Implementation.~targetMethod~1);
  13:     }
  14:  
  15:     public void Save()
  16:     {
  17:         MethodExecutionEventArgs ~laosEventArgs~1;
  18:         try
  19:         {
  20:             ~laosEventArgs~1 = new MethodExecutionEventArgs(~PostSharp~Laos~Implementation.~targetMethod~1, this, null);
  21:             ~PostSharp~Laos~Implementation.AopTester.TracingAspect~1.OnEntry(~laosEventArgs~1);
  22:             if (~laosEventArgs~1.FlowBehavior != FlowBehavior.Return)
  23:             {
  24:                 Console.WriteLine("::Save start");
  25:                 Thread.Sleep(0x7d0);
  26:                 Console.WriteLine("::Save end");
  27:                 ~PostSharp~Laos~Implementation.AopTester.TracingAspect~1.OnSuccess(~laosEventArgs~1);
  28:             }
  29:         }
  30:         catch (Exception ~exception~0)
  31:         {
  32:             ~laosEventArgs~1.Exception = ~exception~0;
  33:             ~PostSharp~Laos~Implementation.AopTester.TracingAspect~1.OnException(~laosEventArgs~1);
  34:             switch (~laosEventArgs~1.FlowBehavior)
  35:             {
  36:                 case FlowBehavior.Continue:
  37:                 case FlowBehavior.Return:
  38:                     return;
  39:             }
  40:             throw;
  41:         }
  42:         finally
  43:         {
  44:             ~PostSharp~Laos~Implementation.AopTester.TracingAspect~1.OnExit(~laosEventArgs~1);
  45:         }
  46:     }
  47:  
  48:     public static void WriteEntryMsg(string source)
  49:     {
  50:         writeMsg(string.Format("OnEntry fired for: {0}", source));
  51:     }
  52:  
  53:     public static void WriteExitMsg(string source)
  54:     {
  55:         writeMsg(string.Format("OnExit fired for: {0}", source));
  56:     }
  57:  
  58:     private static void writeMsg(string msg)
  59:     {
  60:         Debug.WriteLine(msg);
  61:         Trace.WriteLine(msg);
  62:         Console.WriteLine(msg);
  63:     }
  64: }

 

Results

The PostSharp framework added some nominal code for error handling and call-back methods for the aspect code.

The impact appears to be marginal. Efficiency measures are added to ensure the PostSharp objects are instantiated in a static constructor.


Service Security

August 1, 2008

At my current job we have been working at trying to get a good solution in place for web services. We have requirements that are not too unique:

Follow the Robustness Principle:

“be conservative in what you do, be liberal in what you accept from others”

We wanted to build an API which may be used internally, while also being used by vendors and partners in our B2B scenarios.

Our internal apps consist of both .NET and PHP, so we needed a solution which work across the board. The PHP guys wanted REST, but some customers and internal apps wanted to use SOAP.

We also wanted a flexible solution which would not require a lot of code duplication to get the job done.

What we finally settled on was WCF. In its latest incarnation, it supports REST and SOAP, while providing a very extensible framework which could be extended to meet our needs.

The biggest first hurdle we faced was authentication and security.

Security in the SOAP world can be a complicated mess of WS-* standards, certs, etc… I have gone down that road before, in the name of “standards compliance”, but it does require quite a bit of complicated configuration, coordination and testing, especially in the interop world.

So, WS-Security was out.

Also, in the magical world of REST, we don’t have a unified, standard way of doing security. Usually, it is left to the application hosting the services to provide some sort of cookie-based auth which the services also pick-up on. When users are logged into the web app, the cookies are in place and the services are able to validate authentication occurred.

But, in an A2A (Application to Application) integration scenario, this kind of solution does not play well. We sometimes don’t have a user context and in the cases we do have an actual user, we sometimes don’t need to know the identity of that user. So, 80% of the time we are fine with one app talking to another app using some kind of application or system credentials and the “user’s” credentials stop at the app’s boundaries.

I researched ways to provide authentication and authorization, such as looking at the methods used by Amazon, Google, Flickr, and MySpace, etc. Much of these services are very concerned about the end user and “federated” identity. In the case of Flickr, they need the end user to know when another site or service is attempting to view/change/delete that user’s photos. They want to ensure delegated authentication occurrs, ensuring that third-party sites are not storing their user’s credentials. We did not have that problem.

These services also use tokens and API keys with authentication services. The authentication service grants the user a temporary token, based on the API key and credentials presented. That token is then used to call the services that return data. We wanted a simpler, one-call approach where consumers would provide credentials along with their request message.

We settled on using the old stand-by: Basic Authentication with SSL.

We would use a custom implementation of basic authentication which would provide flexibility in the Authentication and authorization mechanisms. We require this flexibility because a service may be fronting a system using its own proprietary authentication scheme or the service may be able to utilize Active Directory security or LDAP.

The custom basic authentication mechanism had to be pluggable and extensible.

In a later post, I will explain how we implemented this authentication scheme.


Technorati

June 19, 2008

MVC Framework

January 28, 2008

Let’s face it, Microsoft is in the business to make money, not to just create what is architecturally elegant. MVC is an age-old, proven pattern, but it is also en-vogue due to the current rails tech fad (although some are jumping to the next cool thing).

MVC (and the related frameworks I know are coming) is Microsoft’s answer to rails. Rails makes web development crazy easy. ASP.Net is clunky and looks hard compared to what can be done with rails. Although, rails is not a do-all, be-all, Microsoft is losing developers to the rails club. You could even argue that more and more new web developers are growing up on rails and look down upon lowly old ASP.net.

Microsoft is just doing what it always does (and does pretty well): taking ideas of competitors and attempting to adapt and enhance them. “Microsoftizing” competitive technologies.

With all that said… It does not mean MVC is “bad” or a “copy” of what rails has made so popular… It is sweet goodness for all of us that understand what this pattern brings to the table. Like many others said, it gives us control where we previously had limited control. It gives us what exists in open-source frameworks but provides it in an interesting and more fully “supported” way (open source is good, but Microsoft’s enterprise-level support of a solid product like MVC is even better). This is huge to large organizations like my employer.


Innovation

November 28, 2007

I heard some good talks on innovation a few months ago at a user conference for iRise software.  One of the topics was how to create an innovation pipeline for your business using social networking concepts.  A few companies have already started doing these types of things to great success.

For instance, Dell has its new IdeaStorm web site.  They use a unique form of crowdsourcing to introduce product innovation to the company.  Users go to the web site, submit new product ideas.  Ideas can be modified, voted on, discussed, etc.  The main idea of the site is to use the user to initiate innovation within their line of products.  An interesting idea since the consumers are really the product experts.  Especially power users, those who are the most passionate about the products, have a lot of untapped insight.

Tying this all into a software model, programmers, business analysts and architects have been trying for years to bridge the gap between the user and the end product.  Things like forums and message boards are often catalysts for enhancement requests and bug fixes.  But, some companies are taking this to the next level by only including feature requests which are the most popular.  Using a voting system, Atlassian determines the most popular product enhancement requests.  This list determines the features to be added in the next version of the software (along with other factors).  It is a pseudo-open-source model.  They obviously continue internal innovation but user input seems to be the main factor.

Considering this Atlassian model works well for commercial software (although I could argue they may be too transparent about their future plans which puts them in a competitive disadvantage), I was considering how this could work for internally developed enterprise software.  I could see this really working.  Sit down with a seasoned customer service rep (power user) and you find out quickly where the limitations of your software lie.  If they only had a formal model or process where their feedback is adequately captured and fed into the enhancement pipeline.  Not overwhelming bureaucracy, just a direct line of communication between the grunts (users) and the grunts (programmers).  Like the red Batphone Commissioner Gordon had in his office.


Java

November 26, 2007

I took a Java development class years ago (back in 1999, I think). I learned a lot. I even used Java to build a server-side utility. It was quite simple, but it did have database connectivity, etc. It was nice to try it out and practice what I learned. Since then, I have been exposed to Java and its stack of technologies, but nothing hands-on.

About a month ago that all changed. My team is now deploying two Java-based 3rd-party products. The first is going through the pains of load testing, QA and production deployment. Not just little pains, but serious kidney-stone-type pains. I have learned a lot about Java during this time. I can’t help but compare it with what I know about .NET and my experience with Microsoft technologies. Here are my observations.

Application Server Confusion

This is the big one. Java has no single technology stack. You have to choose one. We have a new stack just rolled out. Our team is going through the pains of working with systems analysts and engineers who are just learning how to use the new stack. Whether it is JBOSS, Sun’s app server, weblogic, Websphere, or whatever; you have to learn and ramp-up on that app server’s quirks, expectations, deployment methodology, configuration management process, etc. Although some things are uniform across these stacks, a lot is not. “You have to unlearn what you have learned”.

.NET has one app server. One configuration management story. One runtime. I agree, there is lack of choice (i.e.: no choice), but therein lies simplicity, and therefore power and freedom. (I know, I know, you can run .NET on Linux with Mono, but seriously, who really does that? Is that really an alternative to Windows and IIS?) If I want to run a .NET web app, I just need to know Windows Server and IIS, nothing more. I don’t need to buy anything. I just buy a commodity Windows server and I am ready to roll.

Deployment

Deployment is not easy in the Java world. Maybe I am just a newbie, so it all seems complex, but man, working with wars, jars, deployment descriptors, config files, etc, can be a mess (this sentence has WAY too many commas). Especially considering migration from one environment to another, these obstacles can get even larger. Let’s say you move from your development environment to QA, you have to build a new war file with different deployment descriptors, set up your app server, data sources, etc, and deploy the application. It sounds easy when someone says, “To deploy an application, all I have to do is just drop a war file on the app server”. That is a lot more complicated than it sounds.

.NET eeks-out a win on this one, but not by much. It can be as easy as running an MSI file, but it can get as difficult as managing a mess of dlls, DSNs, config files and custom IIS settings. But, if done right, deployment can be quite simple in the .NET world. A lot of the ease, I think, comes from the unified/standard configuration system.

Operations Ramp-Up

If you look at the difference between the time it takes to learn how to use Linux/Unix/Solaris from an operations perspective versus Windows, you have to admit, there is a vast difference. This is more of an OS-specific thing, but it has tremendous bearing on the ability of operations staff to deploy, change and manage an application.

Windows server admins may be a dime-a-dozen, but that is because it is so much easier to learn. This means cheaper resource costs and quick ramp-up time and quicker time-to-market.

I am sure there are others. Maybe I will continue this later. Maybe not. Maybe I am just a Java bigot. Maybe not.


With Every Project, Churn… Churn… Churn…

November 7, 2007

It seems that every time I want to get a project done quickly and painlessly, I am cursed with a long drawn-out, painful project instead.  I must be doing something wrong in life to deserve this kind of torture.  Application development should not be this hard.

Process is all part of the game in software development.  I understand the value in process, approvals, checkpoints, documentation, etc.  But WOW, sometimes it feels like trying to get your license renewed at the DMV…  Wading through paperwork, “alignment”, approvals, reviews, etc can be very time consuming and painful.

I am convinced those who succeed at wading through process to get projects finished quickly are those with a very large network of buddies and insiders.  Insiders are people who either own or control parts of the governance process.  They are the people who know how to grease the wheels to get things done.  They are the ones with real control.  If you don’t know those types of people, you are one of the many who just wait in line, praying for the process to work as designed and advertised.

Also, these successful project managers know the process.  They understand each point along the way.  They have intimate knowledge about how each piece of the puzzle fits together.  They have the domain knowledge necessary to plan for each facet of the project’s lifecycle.  If a certain review is required, they know when, who, how to get it done.  They know prerequisites, impacts, key players, etc.  This knowledge is never obtainable over night.

No wonder so many projects fail to meet their original goals.  Consider coming on as a new project manager with no prior knowledge of a company’s proprietary process.  How can you expect to succeed on the first or second try.  It is near impossible.  You will have so many “gotcha” moments where you find out parts of the process you are missing because they are not documented or communicated properly.

Process is a necessary evil, but we (the software development community) have to find a way to simplify to the point where process is not a roadblock to project success.  We have to find a way to fade process into the woodwork of the project pipeline.  Make it transparent enough to know its there, but you don’t really notice it affecting or guiding your project.  It just does its job without meddling.