Sunday, April 4, 2010

Giving them what they need, verses what they ask for

A little while ago I was contacted to see if I could help an elderly member of my congregation, she needed some help building a mail box post.  The phone call went something like this

her: Do you have a table saw?

me: ya, what do you need?

her: I need to cut up a 4x4 post

me: ok, what are you building?

her: A mail box post and I need to cut some braces at 45 degree angle, you can do that with a table saw right?

me: Bring your stuff over and I’ll help you build it.

This is a perfect example of someone who knew what they needed, but not how to get it.  What she needed was some supports cut with 45 degree angles, and she knew that a table saw could make 45 degree angle cuts, and true a table was could do it, BUT it’s really not the right tool, you’re far better off using a miter saw.

This got me thinking how often we as “tech” have been asked to do something only later to find out it’s really not what they needed or wanted. 

a possible example:

marketing: we need a share point server.

tech: sure, who needs access

marketing: The graphics designer

tech: you want a share point server for one person?

marketing: yes

tech: what is she going to use it for?

marketing: tracking the changes made to images

tech: you want a share point server to track image images revisions

marketing: yes, is there a problem with that?

tech: Let me show you subversion.

This is a very good example of someone having a need and coming up with a solution without consulting with anyone, and asking for the solution without explaining the problem.  In this case I used a marketing person, but this could just as easily be a developer not consulting with operations, or a DBA not consulting with the developers. 

Far to often we are asked to do things with little or not explanation to the problem we are providing a solution for and we don’t ask questions as to what we are solving and this really is a disservice to who we are helping.

Friday, April 2, 2010

The VS2010 Preview

At the local VS2010 Even held in Boise, Id we where given a basic over view of what's in VS 2010, while some of these feature are innovate, like the testing tools, there was a lot of Microsoft playing catch up with some of the other IDEs out there. This by no means is a complete list of what is in VS2010, this is just what was presented at the preview, with a little bit of my commentary added by me.

Team project collection

One of the new features is the Team project collection is TFS, while this sounds great, I fail to see where this is a big step up from other source control systems like clear case, subversion, etc. that have been doing this from the beginning, is this Microsoft playing catch up? or am I missing something.

Project templates

With so many more project types in VS2010 there are a lot more project templates, including Database projects, something to keep in mind is the DB projects only support SQL Server 2005+, sorry SQL Server 2000 people, an interesting side note, you can get a plug-in from Quest software for supporting Oracle.

Extension manager

One of the long awaited features for VS is the Extension Manager, as a user you can manage what extensions you have on your system and browse for new extensions in the online gallery. While I really like this feature, lets face it, Microsoft was really late to the party with this, seeing that most other IDEs (Eclipse, Sharp Develop, Mono Develop, etc ) have been doing this for years.

Multi framework targeting

VS2010 now has multi framework support, now vs2008 did support .NET 2.0, 3.0, 3.5 but under the hood it's still the 2.0 CLR.  In VS2010 you can run code on the 2.0 and 4.0 CLR, this was something the Microsoft reps where very proud of.  Unfortunately this is another area where Microsoft was late to the party where a lot of the other IDEs have been supporting multiple frameworks for years and it get even more prevalent when you get outside the .NET stack.

IDE improvements

The IDE improvements in VS is one area where Microsoft is a leader. Where VS2008 added refactoring tools VS2010 improved upon them, but you're still going to have to pull ReSharper out of my cold dead hand. A quick overview of the IDE improvements in VS2010
  • improved refactoring tools
  • improved debug tools
  • new IDE profiles (environment templates)
  • improved MVC support
  • performance monitoring
  • Local deployment build with end to end packaging for web application
  • improved SharePoint development integration

.NET 4.0 CLR improvements

With VS2010 comes the 4.0 CLR, not only did they improve the performance of the framework they also made strides to make better use of multi core systems.  Lets face it multi threading in general is painful, to solve this .NET 4.0 has an improved threading pooling engine, they now fully support the functional language F# out of the box, and have full support plinq.  Plinq lets you spread the work of a linq Query across multiple cores by figures out at runtime the most optimize query solution.  To use plinq all you have to do is add AsParallel to your linq query and .NET takes care of the rest.

Code Contracts was added to .NET to provide a non language specific way to express coding assumptions. Basically you can specify preconditions, post conditions, and object invariants in order to improve testing via runtime checking and enable static contract verification, how this affects me, I’m not sure yet.

Improved Testing tools

An area that has come a long way in VS2010 are the testing tools, unfortunately some of the more interesting tools are only available in VS2010 Ultimate, but Microsoft did add a stand alone testing product called Microsoft Test and Lab Manager, this lets you do most of your test management with out VS.

Testing features in VS2010:
  • UI testing tools that allow you to code/record UI tests, this looks kind of like the Art of Test (Telerik has a re-branding) tool for Web testing but this supports all .NET UIs
  • Test runner monitors what your testers are doing by allowing you to watch what's going on while testing in order to better track what the testers are doing, this includes customizable data collection to filter out irrelevant data, the ability to add video of how this bug was produced that can be added to the defect tracking system, and displays the step by step test steps to the testers .
  • Virtual system manager (Hyper-V is supported but VMware and Virtual box support is expected post RTM) for setting up and managing testing environments.
  • PEX- automated white box testing tool
  • IntelliTrace is basically a trace and profile tool
  • The test impact analysis tool specifies what test are going to be affected by code changes, for large code bases with lots of tests this allows more targeted testing for TDD.
What you get in the Test Lab and Manager
  • Test case management
  • Create UI tests just like in VS2010
  • Test runner for monitoring what your doing in the test just like in VS2010
  • Can import test cases from Excel
  • Can configure testing data including network connectivity (throttling connectivity )

Team Foundation Server

TFS  has an updated admin tool http://www.codeplex.com/TFSAdmin that generally improves managing your server and users. To better fit in the enterprise level space TFS also added clustering with load balancing and build server pooling; for small shops this may not be that big of a deal but it's nice to know for if and when you're no longer a small shop.

One of the major complaints with TFS 2008 was the build system was painful to use and almost required a dedicated builder, this has been supposedly fixed with 2010 by moving to a work flow based build system, I'm waiting to see if this actually fixes the problem.

An interesting new addition Excel Services integration in TFS.  This allows reporting, updating stories, tasks, test cases, etc. with out having to use the Test lab or VS2010.  The basic idea is the business people can use a tool they are familiar with to interact with TFS. Also the excel service integration doesn't require any CALs to use.

To my disappointment there is not a migration tool to move from other source control systems (subversion) to TFS yet, but supposedly it's on the way, so if you're currently using subversion your going to have to wait.

    Agile Software Development with TFS

    Some of the improvements to TFS are in it's support of agile development, with project templates for agile out of the box and the ability to customize your tickets (they are just xml).  All work items are queryable using Excel Services allowing your product owners and scrum master to know exactly what is going on at any time.

    The build server now supports ATDD (Acceptance Test Driven Development) and tie in UI tests, Unit Tests, Integration Tests, etc.

    An interesting addition is the ability to create a team portal and wiki in Share point automatically. 

    Conclusion

    I'm excited to start using VS2010 all in all I'm impressed with what it dose and how it works.

    Friday, January 29, 2010

    ASP.NET Controls, even the 3rd party controls are great, until you really try to use them

    Over the years I have had a kind of love hate relationship with asp.net web controls and after having some frustration recently I decided to rant about it.

    Conceptually it’s nice idea, the asp.net controls abstract away a lot of the “web development” so you can focus on just creating your application and not futzing around with html inputs, and creating elaborate javascript, and they give you a kind of sort of state;  and for about 90% of the time they do everything you want them to do. 

    Were they fall down is really in two places:

    1. In all reality not getting that last 10% really isn’t the controls fault it’s trying to be everything to every body and you really can’t do that.  This is even true the for expensive 3rd party controls, granted vendors like DevExpress, Component One, and Telerik make some very nice controls (a lot better then the stock controls from MS) I would even say they give you an additional 5%, and for the most part they make developing web forms easier and faster, BUT they still fall down when you really push them hard and then it feels like your spending all of your time tweaking their control verses just getting your application written. 
    2. The cost of getting that statefullness by using viewstate can sometimes crush your application, like most things it’s fine in moderation, unfortunately ViewState can quickly explode in size and blot your application, creating HUGE page sizes, slow responses and if it gets big enough it starts to corrupt and your applications starts to error, fun! Once again the 3rd party vendors tend to make better controls with less viewstate.

    So what is the solution, first learn about webforms controls and how they work, then create some server controls of your own.  If you look at previous posts I talk about how to create different types of controls and I’m only scratching the surface.  By rolling your own controls you can focus on getting them to do exactly what you want them to do and that might be the solution to getting the last 5% of the functionality you need.  Using Asp.net controls is one of the places where it’s really easy to get started with very little knowledge and quickly get sucked under.  This is defiantly a place where if you don’t understand how it works it can and will come back to get you. 

    Finally if you can’t get that last little bit of functionality, well for the most part you just have to deal with it.  Sorry to say but we are getting to a point where the development work on the web is going beyond what the underlying technology just can support. 

    Monday, January 18, 2010

    Unit Testing For Javascript

    Recently I had to write some fairly substantial javascript, and in the process I was reminded of how fast javascript, like most scripting languages, and get out of hand really quick. I took a step back and thought why should I work in javascript any different then I do in other language? Just because it’s a scripting language doesn't make it any less valid of a development platform, and I can apply the same design pattern and principles I would with anything else.

    So The first thing I did was went looking for a unit testing framework and I found JSUnit. JSUnit is available from http://www.jsunit.net/ and is a port of the JUnit framework to javascript. The entire testing framework and test runner is written in javascript so I can use it anywhere you use javascript and in any development platform(php, ruby, Perl, java, .net, etc).

    Getting started I have this javascript function I want to test

       1: function addTwoNumber(x, y) {
       2:     var result = x + y;
       3:     return result;
       4: }

    so first I create an html page and add the jsUnitCore.js and my .js file containing this function (almost all of your javascript really should be in .js files for a number of reasons, but that’s another blog post).

       1: <html>
       2:     <head>
       3:         <script language="JavaScript" src="jsUnitCore.js"></script>
       4:         <script language="JavaScript" src="javascriptCode.js"></script>
       5:     </head>
       6:     <body>        
       7:     </body>
       8: </html>

    then to add test cases I create functions inside a script tag in the body of the html page like so

       1: <body>
       2:     <script type="text/javascript">
       3:         function test_addTwoNumber_TwoNumbersAreAdded() {
       4:             var result = addTwoNumber(2, 2);
       5:             assertEquals("Adds 2 values together", 4, result);
       6:         }
       7:  
       8:     </script>
       9: </body>
    to tag a function as a test, simply start the function off with the text “test” and the test runner will pick it up and run it. The assert is done with the function assertEquals provided by the jsUnitCore.js file and takes 3 prams (test description, expected value, and actual result) and to run the test you simply open the testRunner.html page in the jsunit dir in a browser

    image

    then add the file location and run the tests, it’s that simple. If you look at the screen shot you will notice that I’m using opera, for what ever reason I couldn’t get the test runner to work in Firefox, every time I would try and run my test file I would get a time out error, The funny thing is it works in IE, Chrome, and Opera just fine, weird.

    Saturday, December 12, 2009

    Using WCF to build fast and lean web applications

    Recently I ran into a problem where I needed to reduce the size of a page, we had a page with a lot of drop down controls that may or my not be used. The problem with this was the size of the html was huge, every one of the controls was fully populated with over 50 items, next the view state was equally huge storing all of that content. The Solution, using WCF to load the control’s content on demand.

    Starting off we need to get WCF configured, and this confused me, I had to manually register WCF in IIS, WHAT!! ok to save you the hassle of having to research how to do this, execute c:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i and your good to go.

    We have two options for populating the dropdowns, you can use a 3rd party control like Telerik’s radcombobox, or roll your own, which in some ways is fairly simple but rather involved, for right now I’m going to show you how to roll your own, to see how to use radComboBox see here.

    Lets start with the WCF service, create a Ajax enabled WCF service. For what ever reason I had to remove the namespace to get this to work, and the examples I found online had it removed as well, this is something I’m going to research more on later. Next we need to build a data entity to hold the data, nothing fancy just something like this

       1: public class Item
       2: {
       3:     public string Text { get; set; }
       4:     public string Value { get; set;}
       5: }
       6:  
       7: public class Items : Collection<Item>
       8: {}
    next we build the service, in this case I’m just building some data.
       1: [ServiceContract(Namespace = "")]
       2: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
       3: public class DataService
       4: {
       5:     [OperationContract]
       6:     public Items GetData()
       7:     {
       8:         Items myItems = new Items();
       9:         for (int i = 0; i < 5; i++)
      10:         {
      11:             Item newItem = new Item()
      12:                {
      13:                    Text = string.Format("value {0}", i), 
      14:                    Value = i.ToString()
      15:                };
      16:             myItems.Add(newItem);
      17:         }
      18:         return myItems;
      19:     }
      20: }
    when you add the Ajax enabled WCF service some items will be added to the system.serviceModel section of the web config in this case it looks like this
       1: <system.serviceModel>
       2:   <behaviors>
       3:    <endpointBehaviors>
       4:     <behavior name="DataServiceAspNetAjaxBehavior">
       5:      <enableWebScript />
       6:     </behavior>
       7:    </endpointBehaviors>
       8:   </behaviors>
       9:   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      10:   <services>
      11:    <service name="DataService">
      12:     <endpoint address="" behaviorConfiguration="DataServiceAspNetAjaxBehavior"
      13:      binding="webHttpBinding" contract="DataService" />
      14:    </service>   
      15:   </services>
      16:  </system.serviceModel>
    if your not able to get your service to work with the Namespace, and you remove it, make sure to also remove it from the contract attribute in the endpoint node of the service node.

    Next we add the service reference to the page using the script manager tag
       1: <asp:ScriptManager ID="scriptManager" runat="server">
       2:     <Services>
       3:         <asp:ServiceReference Path="/DataService.svc" />
       4:     </Services>
       5: </asp:ScriptManager>
    Now we can access the webservice with javascript. First we need to have a dropdown control to work with, for this we are going to just use a plain old html select tag and add an ID and a runat=”server”.
       1: <select 
       2:     id="dropDownList" 
       3:     runat="server" 
       4:     enableviewstate="false" 
       5:     style="width:200px;" 
       6:     onfocus="populateDropDown(this);">
       7: </select>    
    something else I have done here is I set enableviewstate="false" this solution doesn't use any view state so for the “cool kids” out there using MVC, this solution works for you as well. Next add the javascript to populate our dropdown, as you can see in the select tag we have a populateDropDown function that is called with onfocus.
       1: var Control;
       2: function populateDropDown(dropdown) {
       3:     Control = dropdown;
       4:     DataService.GetData(dropDownRequest_onSuccess, onFailure);
       5: }
    Accessing the service is made easy by using the script manager, all we have to do is call javascript object created by the script manager with the same name as the service contract in this case it’s “DataService” and call the function with the same name as our service method “GetData”. The function takes 2 delegate functions that act as event handlers as parameters, in this case it’s dropDownRequest_onSuccess and onFailure. At this point I would like to say I’m in no way a javascript expert, if you know of a better way to any part of the javascript code by all means do it, and let me know.
       1: var selectedOptionValue;
       2:  
       3: function dropDownRequest_onSuccess(result) {
       4:     Control.options.length = 0;
       5:     for (var x = 0; x < result.length; x++) {
       6:         var opt = document.createElement("option");
       7:         opt.text = result[x].Text;
       8:         opt.value = result[x].Value;
       9:         if (result[x].Value == selectedOptionValue) {
      10:             opt.setAttribute("selected", "true");
      11:         }
      12:         Control.options.add(opt);
      13:     }
      14: }
      15:  
      16: function onFailure(result) {
      17:     window.alert(result);
      18: }
    The dropDownRequest_onSuccess function clears (if any) options from the select tag, then loops though the result from the webservice, creating option elements, setting their text and value then checking to see if the value matches the value of the selectedOptionValue var and if they do it sets that option as selected then adds it to the options collection of the select control.

    The onFailure is called when the service call fails, and for this we are just doing a simple alert to say it failed.

    The next part is getting the data out when the page is submitted, because we are not using any view state we can’t get the value the same way we would with a regular asp.net control, we have to pull it from Request.Form collection.
       1: string value = Request.Form[dropDownList.ID];
    Finally we need to add a way to set an option as selected. The code to set the selected option is already there we just have to utilize it by setting the value of var selectedOptionValue, to do this we use the ClientScript.RegisterStartupScript like this
       1: private void setValue()
       2: {
       3:     string script = string.Format("setpopulateDropdown('{0}',{1});", dropDownList.ClientID, Request.Form[dropDownList.ID]);
       4:     ClientScript.RegisterStartupScript(typeof(Page),"setDropdownValue",script,true);
       5:     
       6: }

    to call this javascript function

       1: function setpopulateDropdown(controlId, value) {
       2:     Control = document.getElementById(controlId);
       3:     selectedOptionValue = value;
       4:     populateDropDown(Control);
       5: }

    This sets the control to be updated, set the selected value, then populates the the control from the webservice.

    Like I said it’s kind of a long process but you can cut down your page size a lot if your doing multiple dropdowns with large amounts of data that may not be used.

    As always the full source code for this project is available (here).