Blog Home  Home Feed your aggregator (RSS 2.0)  
What did you learn today? - Wednesday, July 23, 2008
Phil Denoncourt's Technology Rants
 
 Wednesday, July 23, 2008

Part of the .NET 3.0 release was the System.Speech namespace.  This gives you easy access to powerful speech capabilities.  Text to Speech, Speech Recognition, and Dictation are all part of this library.  I've tried speech recognition every 5 years or so, and it has always worked, but it never allowed me to work faster than just using my keyboard.

As a consultant, I work on a variety of different machines.  Sometimes just my laptop, sometimes my laptop with an external monitor, and other times a dual monitor system.  Pictured below is how I set it up on my laptop. 

Most panels are auto hide so that I can maximize the amount of space to view the code.  Getting to the solution explorer means I have to take my hands off the keyboard, and go to the mouse to select the tab.  There are keyboard shortcuts, but I either don't remember all of them, or they don't work in all types of documents.

Since speech recognition is so easy to use with the system.speech dll, and Visual Studio addins aren't rocket science either, I built an addin that enables speech recognition within Visual Studio.  Basically, the addin maps a list of words, that when recognized, execute a command in the Command Window.  So, when I need to quickly look at the task list, I don't have to remember the keyboard shortcut, or mouse to it.  I just speak "Task List".  When I need the toolbox, I say, "Toolbox".  I didn't get into dictation, because I don't think it is efficient to speak "for space open parenthesis int i space equal space zero semicolon i less than items period count semicolon i plus plus close parenthesis open curly brace..."

I uploaded the source and an installer here on CodePlex.  Because (I think) Visual Studio 2005 only works with addins written in .NET 2.0, this only works for VS 2008.  Try it out and let me know how it works.

 

Wednesday, July 23, 2008 7:13:18 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   DotNet  | 
 Tuesday, June 10, 2008

Me either.  See here in the C# Language Reference.  This means you can overload the operators for your classes.  The example on MSDN talks about classes that have a true, false, or null (neither true nor false) state.  You could also create a type that can be both true and false.

Overloading operators can lead to code that is difficult to read.  You should only overload operators when it makes sense to do it.  If it is unclear what “if (myType)” means, don’t overload the operators.

I wrote a small rules engine for a company a while back and this would have been helpful.  Supplemental rules were implemented as separate classes so that they could be dynamically strung together in different orders as the business logic changed.

Here’s a contrived sample using the true/false operators:

    public class Customer
    {
        public string CustomerName { get; set; }
        public string EmailAddress { get; set; }
        public decimal OutstandingBalance { get; set; }
    }

    public class CustomerIsGoodRule
    {
        
        public CustomerIsGoodRule(Customer customer)
        {
            this.Customer = customer;
        }

        Customer Customer { get; set; }

        public static bool operator true(CustomerIsGoodRule theCustomer)
        {
            return (theCustomer.Customer.OutstandingBalance <= 0);
        }

        public static bool operator false(CustomerIsGoodRule theCustomer)
        {
            return (theCustomer.Customer.OutstandingBalance > 0);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Customer c = new Customer();
            c.CustomerName = "Joanne Doe";
            c.EmailAddress = "joannedoe@mailinator.com";
            c.OutstandingBalance = 25;

            CustomerIsGoodRule cigr = new CustomerIsGoodRule(c);

            if (cigr)
            {
                SendNewCatalog();
            }
            else
            {
                SendNewStatement();
            }
        }
    }

One thing to keep in mind is that if you provide a definition for true, you must also provide one for false.  Also notice that the logical negation operator (!) was not overriden, so a statement like if (!cigr) fails to compile.

Tuesday, June 10, 2008 12:04:08 PM (GMT Standard Time, UTC+00:00)  #    Comments [2]   Development | DotNet  | 

I haven’t taken the time to upload the materials yet, so thanks to Steve Coombes for hounding me about it.  Here are the files:

Powerpoint Presentation

Source Files/Demo

Tuesday, June 10, 2008 12:00:56 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Speaking Engagements  | 
 Friday, May 09, 2008
In case you haven't heard...  Notice the new location in Nashua.
 

New Hampshire Dot Net Users Group is back just in time for Microsoft’s latest releases of Visual Studio

We’ll be meeting In our new home at

6:00-8:30 May 15th

Eaton Richmond Center room 100

Daniel Webster College

The Guest Speakers will be

Phil Denoncourt

Overview of the AJAX control toolkit:

AJAX is an way to make websites more interactive and responsive.  It's powerful and easy to use.  The AJAX control toolkit is a set of controls that use AJAX and wrap common UI scenarios.  Cascading dropdowns, Auto completing textboxes, in-page popups, hovering menus and dynamically populated textboxes are some of the controls we'll go over.  No AJAX experience is required.

And Pat Tormey will be presenting

What’s new and important in VS 2008 with a little bit of WPF and Expression Suite

Stay tuned to http://www.nhdn.com for details and register up for notices…

Friday, May 09, 2008 12:21:02 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Speaking Engagements  | 
 Monday, April 21, 2008

I'm going to be taking this next week, so I thought I'd post my study notes as I assemble them.

  • May include but is not limited to: using the ConnectionStringBuilder; leveraging the ConfigurationManager; protecting the connection string; using Security Support Provider Interface (SSPI) or SQL Server authentication; correctly addressing the SQL Server instance; managing “User Instance” and AttachDBfilename

The ConnectionStringBuilder objects allow for an abstract way of building a connection string for ADO.NET.  There is a good writeup on the data access blog showing basic usage.  There is a SqlConnectionStringBuilder, OleDbConnectionStringBuilder, OdbcConnectionStringBuilder, and an OracleConnectionStringBuilder.

The ConfigurationManager has a specific section for storing connection strings and the ConnectionStrings property to manipulate them.  See this article on MSDN for more information.  An area that doesn't get much attention is that the Connection string configuration can be stored in a separate config file.  See the section titled "Using external configuration files" to see how to use the configSource property.

MSDN has an article on securing configuration strings.  An important part to pay attention to is encrypting connection string information stored in config files.  Scott Forsyth has a post on using aspnet_regiis to protect web.config files.  Daruish Tasdighi has an article at codeproject about protecting the contents using the ConfigurationSection.ProtectSection / UnprotectSection methods.

  • Manage connection objects.
    May include but is not limited to: managing connection state, managing connection pool; implementing persistent data connections; implementing Multiple Active Result Sets (MARS); encrypting and decrypting data

Managing connection state.  I think that is knowing that there are methods on the connection object to open and close the connection.  The connection will be closed when the connection object is disposed.

There is a great post by Sijin Joseph about connection pooling with all the different connection objects.  I wasn't aware that there is no connection pooling with ODBC using the managed providers.  Also interesting was that connection pooling for SQL Server was disabled while debugging in Visual Studio.  Another thing to be aware of is that when using Integrated Security for SQL Server, the domain/user is added to the list of things that need to match for a connection to be reused.

To have a persistent data connection, you disable connection pooling and keep the instance of the connection object around.  The connection will remain open until the connection object is disposed or the close method is used.

Eric Moreau has a post on using MARS.  It is only supported in the SQL Server and Oracle managed providers. 

You can encrypt/decrypt the data passed from the client back and to the database server by adding the Encrypt keyword to the connection string for SQL Server or using the Encrypt property on the SqlConnectionStringBuilder.

  • Work with data providers.
    May include but is not limited to: limitations, behaviors, performance, installation issues, deployment issues; ODBC, Microsoft OLE DB, SqlClient, managed providers, third-party providers, native providers

I guess this is a nice way of saying, "Know everything about ADO.NET".  Some of the things I'm aware of are the just because you have a managed provider available, you still need the native dll libraries.  Oracle, for example.  The client needs the oracle client libraries in order to connect to Oracle.  I mentioned some of the shortcomings of ODBC above in regards to pooling.  A great source for third party data providers can be found at the mono project (Firebird, MySql, SQLLite, PostgresSQL, Mimer, Sybase..)

  • Connect to a data source by using a generic data access interface.
    May include but is not limited to: System.Data.Common namespace classes

The common namespace is the abstract definition for all data providers.  You would use this when you aren't sure which data provider your application will ultimately use.  Using the DbProviderFactory you can instantiate objects for a specific data provider.   Suman Chakrabarti has a post showing how to use the DbProviderFactory class.

  • Handle and diagnose database connection exceptions.
    May include but is not limited to: implementing try/catch handlers

Joydip Kanjilal has a post on handling exceptions in ADO.NET.  If you catch a SqlException, you would examine the number property to determine the root cause of the problem.

 

Next -> Section II Selecting and Querying Data

Monday, April 21, 2008 11:50:36 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]   Certifications  | 
 Monday, November 12, 2007

I'm retrieving data without effort now.  The Linq syntax is starting to sink in.  I don't have to look at the reference as much anymore.  I think I'm stuck, though.  I'm trying to send updates back and I was hoping to have one method per entity called "Save" that would take in the modified entities and use Linq magic to get it back to the database.  No such magic seems to exist.  I'm going to have to write a method per operation (Delete, Insert, Update).  What stinks is that the work required to do this is about the same as it was before using traditional methods.

This could be a case of programming in a closet and not having anyone currently present to bounce ideas off of.  I'm going to bounce this off some of the developers when I go back to work tomorrow.

So far, Linq has a nice intuitive syntax and allows a standardized way of querying collections.  It's also nice that it supports lazy loading and relationships natively. However, from a productivity point of view, I'm not sure it adds a lot to what we currently have. 

Monday, November 12, 2007 8:15:10 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]    | 

After getting the images downloaded and setup, I've started to develop.  After getting over a few minor bumps, I'm underway.  I've used SqlMetal to generate entity classes from the DB Schema.  Initially, the classes weren't marked as datacontracts.  This is because I didn't use the /Serialization:Unidirectional switch.  After I regenerated the entity classes, I'm in business.  My WPF application binds to the results of a WCF call that retrieves data using Linq to SQL.

Monday, November 12, 2007 7:03:39 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 

I haven't been very good lately about taking time to learn the new technologies, so I'm taking today off to learn Visual Studio 2008.  I've found over the years the best way to learn a new technology is to create a demo application.  I'm going to be creating a restaurant reservation / order system, using a model proposed by Barry Williams at Database Answers.  I hope to post progress as things go along.

I'm really hoping to get into Linq, so I'm going to architect the system using the traditional 3 tiers, DB, Mid Tier and Presentation.  The Mid Tier should contain all the linq stuff, exposing the objects via a WCF Service.  I'll start with a smart client presentation, and perhaps add a web facade later today. 

I'm still waiting for the download to finish; probably another 2 hours.  So right now I'm going to read all I can about C# 3.0 and Linq.  An article I found very informative is the Linq to SQL overview at MSDN.  The nagging issue I'm trying to resolve is, "How does Linq make life easier for the Mid Tier developer"?  It looks real easy if you don't mind exposing your data model to service consumers. But if you want to abstract the data model a bit, it looks like end up writing some code because you lose a lot of convenience features.

YumDataSchema

Monday, November 12, 2007 2:52:59 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]    | 
 Saturday, June 23, 2007

From Pat Tormey, Director of NHDN:

Summer Recess..And Study Groups

During the summer I'll be forming Study Groups to meet for particular topics.

Personally I'll be studying the SmartClient Software Factory. If you are interested, drop me a note.. We'll be meeting at my office in Derry NH on Monday evenings

If you'd like to host a Study Group or have an idea for one please drop me a note and I'll see if we can find some people in your area with the same interests.

Saturday, June 23, 2007 4:44:41 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Development  | 
 Monday, May 07, 2007

For those of you local to New Hampshire, Chris Bowen and Bob Familiar will be back in town speaking about AJAX.  I've been working with a client on an AJAX site and have been very impressed with the results.

Here's the information for the Roadshow:

We're back in the saddle again, gearing up for another five-city tour to bring deep technical content to a projection screen near you!

Dates, locations, and registration links are at the bottom of this post.

Note that we've changed venues from Farmington to Hartford, CT and Manchester to Nashua, NH.

See you on the road!

-Chris

----------------------------------------------------------------------------------------------------------

Bob Familiar and Chris Bowen are two guys who love to write code and can’t stop talking about it. And now they’ve decided to take their long winded rants and questionable demos to a city near you. And if you were at our last event, you know the line about questionable demos is no joke!

AGENDA: AJAX, Extensible Scrubbing Bubbles and that Cross Browser Cleansing Motion
8:30am Arrive, check in, grab a nosh and a seat
9:00 – 10:15 XML and the Database
SQL Server 2005 offers architects and developers a slew of great features for creating data driven solutions. For this session we will focus on the XML features including XML Indexes, XQuery, the XML Datatype, the FOR XML clause and validating XML within the database using XSD. The use cases for these XML capabilities will also be discussed.  
10:15 – 10:30 <Break />
10:30 – 12:00 What’s New From The Patterns & Practices Group?
Like doing things the hard way?  Well, unfortunately for you this session is all about making your life as a developer or architect easier.  The Patterns & Practices group keeps churning out great tools, reference code, and guidance to show you Microsoft's recommendations for designing, developing and deploying great applications.  We'll cover Enterprise Library 3.0, various Software Factories, the Guidance Automation Toolkit and more, explaining how they could fit in with your development efforts.  If you suddenly find the hard way less thrilling, don't say we didn't warn you!
12:00-1:00 Grab a lunch and search for patterns in the carpet
1:00 – 2:15 Microsoft Silverlight (aka Windows Presentation Foundation / Everywhere)
At our last meeting, we dug into the Windows Presentation Foundation, a .Net Framework development library that sits overtop of DirectX allowing one to create the next generation of Windows user interfaces using advanced graphics, animation, rich documents and multimedia along with traditional UI controls. Windows Silverlight is a subset of the capabilities of WPF that can be used within browser based applications on the PC and the Mac. This session will discuss the architecture of Microsoft Silverlight and demonstrate how integrate XAML into your browser-based applications.
2:15-2:30 Take a break and animate
2:30 – 3:45 ASP.NET AJAX – Going Deeper
If you're developing applications for the web, you've likely heard about AJAX and how it can improve the usability and functionality of your site.  In this session, we'll quickly introduce the main concepts of ASP.NET AJAX and then we'll roll up our sleeves for other details that will help you when you're in the trenches with AJAX.  We'll talk about the client side library, Silverlight (formerly codenamed WPF/E) integration, enabling and invoking server methods and web services, debugging, best practices and more.    
3:45 – 4:00 Zune Giveaway
   

 

       
Location Date Time Registration 
Sheraton Burlington Hotel May 8th, 2007 8:30am-4:00pm Register! 
870 Williston Road  
Burlington Vermont Event ID:
  1032339883
RIT INN & Conference Center May 10th, 2007 8:30am-4:00pm Register! 
5257 Henrietta Road  
W. Henrietta New York Event ID:
  1032339884
Sheraton Hartford Hotel  May 14th, 2007 8:30am-4:00pm Register! 
100 East River Drive  
Hartford Connecticut Event ID:
  1032339886
MESDA May 15th, 2007 8:30am-4:00pm Register!
 506 Main Street   
Westbrook, ME 04092 Event ID:
  1032339885
Sheraton Nashua Hotel May 17th, 2007 8:30am-4:00pm Register! 
11 Tara Boulevard  
Nashua New Hampshire Event ID:
  1032339887

Monday, May 07, 2007 3:51:33 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   ASP.NET  | 
 Wednesday, March 21, 2007

There is plenty of guidance on reviewing code.  (Look at CodeFrisk.Com/Guidance.aspx for some links).   I’ve found that the one absolutely most critical piece of a traditional application never undergoes any type of review.  Most applications live and die by their database, and yet it rarely gets reviewed.  If you’re lucky (although you might not think so), you’ll have a DBA check things over, but they are mostly concerned with performance.  Maintainability and adherence to standards are not at the top of their list.  

 

I’ve listed some of the things I look at when I review a database:

-Appropriate Normalization

It’s tough to say what is and isn’t appropriate normalization.  You’ll know it when you see it.  Stuff like having a separate table for the US states or one called Gender is usually a red flag of having gone too far.  Conversely, having the same field in multiple tables is usually a sign that normalization hasn’t gone far enough. 

 

--Is all access through stored procedures

Most development shops have a policy that says, “All data access shall be done through stored procedures”.  If you have that policy, check to make sure this is being adhered to.  An easy way to check this is to deny access to the tables and allow access to the stored procedures.

 

--Look for premature optimization

I’ve seen times when developers are using Join hints or locking hints in their query.  “If I force the query to use a merge join, it goes 5x faster”.  Meaning it goes 5 times faster on the development box which has far fewer rows and 3 fewer processors than the production machine.  Once it goes the to production machine, there’s a good chance that SQL will decide upon a different plan to execute the statement, making the hint destructive on the production machine

 

--Are objects secured and scripted

Eventually, when you roll the database into a production environment, access to the database will (or should) be locked down.  Is the development environment the same?  Are the scripts that you have under source control (you do have the database creation scripts under source control don’t you?)  include securing of the object.

 

--Are updates applied in the same order

I can think of no better way to create an application that suffers from chronic deadlock situations than to have one stored procedure update tables A, B, & C (in that order) and have another stored procedure update tables C, B, & A (in that order).  Updates should always be applied in the same order.  Otherwise, you’re increasing the chance that a row in A will be locked by one stored proc while waiting for a row in table C locked by the other stored proc.  Generally the order is enforced naturally because you have to respect foreign keys, but every now and then I come across this.

 

--Biblical stored procedures

By biblical, I mean volume, not divinely inspired.  I’m referring to stored procedures that use up more than one printer cartridge if you were to print it.  Nowadays when you see a large stored procedure, it’s one of two things:

1) Embedded business logic – This seems to be a remnant of client server programming where you were forced to put your business logic in the stored procedure.  It’s arguable about whether or the database is the best place to keep your business logic.  Most people (including me) believe it’s not.  Business logic should be kept in a business logic component that validates, enforces and calculates.

2) Poorly defined schema.  Most validations that you see taking place in stored procs could be controlled by using schema constructs like check constraints, triggers, foreign keys and defaults.  Put that type of information in the schema where it can be enforced consistently everywhere rather than burdening the stored procedure.

 

--Does the Development database match what’s in source control

To reinforce this, database schema objects need to be kept under source control.  Having a database backup plan isn’t sufficient.  Putting the objects in source control allow you to manage changes and releases much more effectively.  Otherwise you’ll be struggling to determine which objects have changed in the development database and need to be deployed, and figuring out who added a field to table.  Keeping the schema under source control used to be a very manual process, but now tools like Visual Studio for Database Professionals make this painless.

 

--Cloned stored procedures / Views.

This is very common.  When you need data, most developers don’t look to see if there is an existing stored procedure or view that satisfies their needs.   They’ll create a brand new one.  Then you end up with a database that has 3 different stored procedures that get a customer record by its ID.  Now all these duplicated procs have to be maintained.  Best prevention for this is to have a strict naming convention for your procedures. 

 

Those are some of the quick patterns I look for when reviewing a database.  What are the kind of things that stand out when you look over a database?

 

Wouldn’t you feel comfortable having your code reviewed by an expert?  Go to CodeFrisk.com to see how I can proofread your code at a reasonable price.

Wednesday, March 21, 2007 3:59:42 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Development | SQL | Code Reviews  | 
Copyright © 2009 Phil Denoncourt III. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: