<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">ESE/ESENT Database Stuff</title><subtitle type="html" /><id>http://blogs.msdn.com/laurionb/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/laurionb/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-01-08T10:21:00Z</updated><entry><title>Version 1.5 of ManagedEsent released. PersistentDictionary goodness</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/09/13/version-1-5-of-managedesent-released-persistentdictionary-goodness.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/09/13/version-1-5-of-managedesent-released-persistentdictionary-goodness.aspx</id><published>2009-09-13T05:02:00Z</published><updated>2009-09-13T05:02:00Z</updated><content type="html">&lt;P&gt;There is a new release of ManagedEsent on &lt;A href="http://managedesent.codeplex.com/" mce_href="http://managedesent.codeplex.com"&gt;Codeplex&lt;/A&gt;. There are some new APIs, constants for the new Windows 7 ESENT features, bugfixes and performance improvements. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;There is also a new Esent.Collections.dll which contains a PersistentDictionary generic class. This is a drop-in compatible replacement for the generic Dictionary or SortedDictionary classes for applications that need very simple data persistence.&amp;nbsp;The database is stored in a location specified in the dictionary constructor.&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;var dict&amp;nbsp;= new PersistentDictionary&amp;lt;string, int&amp;gt;("DataDirectory");&lt;BR&gt;dict["foo"] = 17;&lt;BR&gt;dict["bar"] = 18;&lt;/P&gt;&lt;/CODE&gt;
&lt;P&gt;The&amp;nbsp;dictionary entries are persisted automatically&amp;nbsp;and updates are transacted providing data consistency and crash resilience.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9894600" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>6 New ESENT features in Windows 7</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/08/18/6-new-esent-features-in-windows-7.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/08/18/6-new-esent-features-in-windows-7.aspx</id><published>2009-08-19T00:35:00Z</published><updated>2009-08-19T00:35:00Z</updated><content type="html">&lt;P&gt;A quick look at some of the new features that are available in the Windows 7 version of ESENT. You'll need esent.h from the Windows 7 SDK to see these definitions:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Column Compression&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Columns of type JET_coltypLongBinary and JET_coltypLongText can now be compressed. There are two ways of enabling compression.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create the column with the JET_bitColumnCompressed flag. This can only be used with long-value columns, otherwise ESENT will return JET_errColumnCannotBeCompressed.&lt;/LI&gt;
&lt;LI&gt;Set the column with JET_bitSetCompressed. This flag can be used with any column type, we just ignore it for non-compressable columns. Alternatively you can use JET_bitSetUncompressed when updating a compressed column with data that you don't want compressed.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;EM&gt;How does compression work?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For 'short' columns (less than 1kb in size) we look to see if all the data is 7-bit ASCII characters. If so we compress each character to its 7-bit value. This is the only compression done for short values. It was added to help with the fact that Exchange stores a lot of strings which are often just 7-bit ASCII values, e-mail headers for example. Turning a 16-bit Unicode character to a 7-bit ASCII value gives a large savings and is cheap to do.&lt;/P&gt;
&lt;P&gt;For 'long' columns (greater than 1kb) we apply Microsoft's XPRESS compression, which is similar to ZIP or RAR compression. We only store the compressed data if it is smaller than the uncompressed data. Of course determining that data doesn't compress well costs CPU cycles so if you are storing already compressed data you shouldn't use compressed columns.&lt;/P&gt;
&lt;P&gt;Unlike SQL Server's page compression this feature is designed to compress large column values, not remove duplication when multiple records have similar values. This is done because this feature was added for Microsoft Exchange, where most of the data is stored in relatively large BLOB columns (e.g. e-mail bodies).&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;What else do I need to know?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Nothing, really. A compressed column looks just like a normal column and can be indexed, set and retrieved as normal. There is no way to retrieve the compressed data, you will always get uncompressed data when calling JetRetrieveColumn or a similar API. If you want to know how well a record compressed use the new JetGetRecordSize2 API which gives both the logical (uncompressed) and physical (compressed) size of a record.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2. 32kb and 16kb page support&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ESENT now supports 32kb, 16kb and 2kb pages. Changing the page size affects b-tree performance and you may find your application runs faster with bigger pages. Bigger pages also allow more columns to be set in one record before getting JET_errRecordTooLarge.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3. JetPrereadKeys&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you want to retrieve non-contiguous records quickly you can use JetMakeKey to calculate their keys and then call JetPrereadKeys. Prereading the records will issue the I/O as efficiently as possible, which makes retrieving the records a LOT faster if I/O is involved. Records must be preread in either ascending or descending key order. JetPrereadKeys may not be able to preread all the records so it tells you how many keys were preread so that you can issue a preread call for the rest after processing the initial batch.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;4. Space Hints&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In older versions of ESENT you could specify the initial size of a table/index, but didn't have much control over how the table size grew. Space hints allow you to give the initial size of a table/index and then indicate how much space the table should use as it grows. This feature is designed to allow databases with large numbers of tables where the tables start out small (perhaps one page) and then grow their allocation size so that they have contiguous space.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;5. JET_paramWaypointLatency and JET_bitReplayIgnoreLostLogs&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Write-ahead logging depends on the underlying storage being durable, which isn't really true for inexpensive desktop-class machines. To improve database recoverability we have added a 'Lost Log Resiliency' (LLR) feature to the Windows 7 version of ESENT. Setting the JET_paramWaypointLatency parameter to a non-zero value will enable the LLR feature, causing ESENT to delay writes to the database until N logfiles have been generated, where N is the waypoint depth.&lt;/P&gt;
&lt;P&gt;For example, if the waypoint is set to 1 and the current log generation is 28 then ESENT will not write any pages to the database that have been modified by log records in generation 28. This means that the database can be recovered without the most recent log but there will be data loss! If you are comfortable with some potential data loss and want to emphasise database recovery then set JET_paramWaypointLatency to 1 (or a small value, there is a performance penalty for maintaining the waypoint). You have to use the JET_bitReplayIgnoreLostLogs option with JetInit2 to tell ESENT that it is OK to perform a lossy recovery.&lt;/P&gt;
&lt;P&gt;This will allow you to recover your database even if a system crash loses the most recent log. In our power-down testing this improves the chances of a sucessful database recovery after a machine with non-battery-backed write caching is powered down.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;STRONG&gt;6. JET_bitTermDirty&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you want to shutdown REALLY quickly you can use JET_bitTermDirty, which won't even flush the database cache. Recovery will take longer the next time but no data will be lost.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;I know this was a very quick summary. If you have specific questions, leave them in the comments or use the 'contact me' area and I'll try to answer them or provide samples.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9874617" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Multimethods in C# 4.0 with 'dynamic'</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/08/13/multimethods-in-c-4-0-with-dynamic.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/08/13/multimethods-in-c-4-0-with-dynamic.aspx</id><published>2009-08-14T01:01:00Z</published><updated>2009-08-14T01:01:00Z</updated><content type="html">&lt;P&gt;(Continuing from the post on implementing the Visitor pattern in C# 4.0)&lt;/P&gt;
&lt;P&gt;A virtual method is polymorphic in one dimension (the runtime class of the object the method is attached to). Multimethods (multiple dispatch) are polymorphic in multiple dimensions, which can be very useful in some cases. The dynamic keyword in C# 4.0 allows for method selection that depends on the runtime class of the arguments, not just the attached object. This allows true multimethods. (Of course the lookup rules for dynamic&amp;nbsp;are complex so extremely complex cases might not resolve the way you want).&lt;/P&gt;
&lt;P&gt;The basic idea is to create method overloads which take all the (subclass1, subclass2) combinations that you are interested in and then have the (superclass, superclass) method cast its arguments to dynamic and then call the method again and let runtime resolution do its thing. In the spirit of the Wikipedia article on multimethods, here is a spaceship/asteroid collision example:&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;using System;&lt;/P&gt;
&lt;P&gt;namespace MultiMethods&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Program&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Thing { }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Asteroid : Thing { }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Spaceship : Thing { }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void CollideWith(Asteroid x, Asteroid y) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Asteroid hits an Asteroid");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void CollideWith(Asteroid x, Spaceship y) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Asteroid hits a Spaceship");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void CollideWith(Spaceship x, Asteroid y) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Spaceship hits an Asteroid");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void CollideWith(Spaceship x, Spaceship y) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Spaceship hits a Spaceship");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void CollideWith(Thing x, Thing y)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dynamic a = x;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dynamic b = y;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CollideWith(a, b);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var asteroid = new Asteroid();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var spaceship = new Spaceship();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CollideWith(asteroid, spaceship);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CollideWith(spaceship, spaceship);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9868920" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Implementing the Visitor pattern with the 'dynamic' feature of C# 4.0</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/05/29/implementing-the-visitor-pattern-with-the-dynamic-feature-of-c-4-0.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/05/29/implementing-the-visitor-pattern-with-the-dynamic-feature-of-c-4-0.aspx</id><published>2009-05-29T02:05:00Z</published><updated>2009-05-29T02:05:00Z</updated><content type="html">&lt;P&gt;A lot of the talk around the new dynamic keyword in C# 4.0 (available in the &lt;A href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" mce_href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;beta of Visual Studio 2010&lt;/A&gt;) is around interaction with external components (dynamic languages, HTML DOM, COM) but I'm most excited about being able to stragetically add dynamic lookup to an ordinary C# program. Normally, when an object is passed to a method the method lookup&amp;nbsp;depends on the compile-time type of the object. This means that code like this:&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;class MyClass&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;public void Foo(Stream s) { Console.WriteLine("Stream"); }&lt;BR&gt;&amp;nbsp;public void Foo(MemoryStream s) { Console.WriteLine("MemoryStream"); }&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;class Program&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;static void DoSomething(Stream s)&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;MyClass obj = new MyClass();&lt;BR&gt;&amp;nbsp;&amp;nbsp;obj.Foo(s);&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;static void Main(string[] args)&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;DoSomething(new MemoryStream());&lt;/P&gt;
&lt;P&gt;&amp;nbsp;}&lt;BR&gt;&lt;/P&gt;&lt;/CODE&gt;
&lt;P&gt;Will print out 'Stream', not 'MemoryStream'.&amp;nbsp;Method resolution for dynamic objects has&amp;nbsp;to use the runtime type of the object, so simply by changing DoSomething() to take a dynamic instead of a Stream&amp;nbsp;we get a program that prints out 'MemoryStream'. Basically, dynamic lets us implement&lt;A href="http://en.wikipedia.org/wiki/Multimethods" mce_href="http://en.wikipedia.org/wiki/Multimethods"&gt; multi-methods&lt;/A&gt; in C#! (Which I really do find very exciting).&lt;/P&gt;
&lt;P&gt;A&amp;nbsp;good use of this feature is&amp;nbsp;when implementing the Visitor pattern.&amp;nbsp;C# code that visits all the nodes in a Linq expression tree tends to be quite ugly, with&amp;nbsp;a huge&amp;nbsp;switch statement and a lot of casts to traverse the tree. By casting the Expression class to dynamic we can call a Visit() method which depends on the exact subclass of Expression. The code below prints an expression tree without needing any explicit conditional or loop statements (using dynamic makes the runtime do all the boring lookup work for us).&amp;nbsp;It is also quite a bit shorter than the C# 3.0 equivalent. Note that if there isn't an implementation for a specific expression type then the Visit method for the parent class will be called.&lt;/P&gt;&lt;CODE&gt;
&lt;P mce_keep="true"&gt;using System;&lt;BR&gt;using System.CodeDom.Compiler;&lt;BR&gt;using System.IO;&lt;BR&gt;using System.Linq.Expressions;&lt;/P&gt;
&lt;P mce_keep="true"&gt;namespace MultiMethods&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class ExpressionPrinter&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private readonly IndentedTextWriter output;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ExpressionPrinter(TextWriter output)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.output = new IndentedTextWriter(output);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Print(Expression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;dynamic&lt;/STRONG&gt; d = exp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Visit(d);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(Expression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("Expression");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(BinaryExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("BinaryExpression: {0}", exp.NodeType);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.Left);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.Right);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(ConditionalExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("ConditionalExpression");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.Test);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.IfTrue);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.IfFalse);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(ConstantExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("ConstantExpression: {0}", exp.Value);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(MethodCallExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("MethodCall: {0}", exp.Method.Name);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Visit(ParameterExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("ParameterExpression: {0}", exp.Name);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Visit(UnaryExpression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.WriteLine("UnaryExpression: {0}", exp.NodeType);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.VisitSubExpression(exp.Operand);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void VisitSubExpression(Expression exp)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.Indent++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;dynamic&lt;/STRONG&gt; d = exp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Visit(d);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.Indent--;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class Program&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var p = new ExpressionPrinter(Console.Out);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&amp;lt;Func&amp;lt;int, int&amp;gt;&amp;gt; e = i =&amp;gt; (0 == i%2) ? -i * i : Math.Abs(i);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Print(e.Body);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/CODE&gt;
&lt;P mce_keep="true"&gt;The output is:&lt;/P&gt;&lt;CODE&gt;
&lt;P mce_keep="true"&gt;ConditionalExpression&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BinaryExpression: Equal&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConstantExpression: 0&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BinaryExpression: Modulo&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ParameterExpression: i&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConstantExpression: 2&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BinaryExpression: Multiply&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UnaryExpression: Negate&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ParameterExpression: i&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ParameterExpression: i&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MethodCall: Abs&lt;/P&gt;&lt;/CODE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9649905" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Kobe - the Web 2.0 application that wasn't</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/04/17/kobe-the-web-2-0-application-that-wasn-t.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/04/17/kobe-the-web-2-0-application-that-wasn-t.aspx</id><published>2009-04-17T22:22:00Z</published><updated>2009-04-17T22:22:00Z</updated><content type="html">&lt;P&gt;Microsoft has released&amp;nbsp;&lt;A href="http://msdn.microsoft.com/en-us/architecture/bb194897.aspx" mce_href="http://msdn.microsoft.com/en-us/architecture/bb194897.aspx"&gt;Kobe&lt;/A&gt;, "a getting started resource kit for planning, architecting, and implementing Web 2.0 applications and services using the Microsoft Platform" and a lot of the response has been quite critical (&lt;A href="http://ayende.com/Blog/archive/2009/04/17/kobe-ndash-in-the-nuts-amp-bolts-and-donrsquot-really.aspx" mce_href="http://ayende.com/Blog/archive/2009/04/17/kobe-ndash-in-the-nuts-amp-bolts-and-donrsquot-really.aspx"&gt;Ayende&lt;/A&gt;, &lt;A href="http://codebetter.com/blogs/karlseguin/archive/2009/04/16/kobe-oh-dead-lord-why.aspx" mce_href="http://codebetter.com/blogs/karlseguin/archive/2009/04/16/kobe-oh-dead-lord-why.aspx"&gt;Karl Seguin&lt;/A&gt;). While the code, architecture and lack of tests have all been thoroughly criticized I think there is an even higher-level point&amp;nbsp;that has been&amp;nbsp;missed -- Kobe, a Web 2.0 sample, was released and managed in a very Web 1.0 way.&lt;/P&gt;
&lt;P&gt;Although&amp;nbsp;the Kobe Project Overview video talks about a Web 2.0 application as having an online community and&amp;nbsp;fostering "active and social user engagement" Kobe itself is available though an inactive, non-social MSDN page with no hint of community. The response on the other hand was far more Web 2.0, with people discussing the project through blogs and&amp;nbsp;on Twitter. At this&amp;nbsp;point the web page is updated to&amp;nbsp;say "&lt;SPAN style="COLOR: #ff0000"&gt;&lt;STRONG&gt;This sample application is being updated to incorporate community feedback. An updated version will be released shortly.&lt;/STRONG&gt;&lt;FONT color=#000000&gt;", but that level of interaction&amp;nbsp;is too little, too late.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I think the biggest mistake here is not releasing a bad Web 2.0 sample, but being unprepared to engage with the online community discussing your bad&amp;nbsp;Web 2.0 sample. Authentic participation on twitter, informative blogging and frequent updates would go a long way here.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9554548" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>iiobo C++ ESE library</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/04/07/iiobo-ese-library.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/04/07/iiobo-ese-library.aspx</id><published>2009-04-07T06:54:00Z</published><updated>2009-04-07T06:54:00Z</updated><content type="html">&lt;P&gt;(I saw a link to this from the Wikipedia entry on esent)&lt;/P&gt;
&lt;P&gt;A company called iiobo has released a C++ toolkit for using esent (I'm guessing they developed it for internal use). I haven't looked at the code, but their website says that they have:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"C++ classes that provide a higher level abstraction of Extensible Storage Engine e.g DbCursor, DbTable, DbSchema etc. These well designed abstractions allow you to seamlessly work with transactions and other database considerations inside object-oriented C++ code."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Their code is released under the BSD license.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.iiobo.com/ExtensibleStorageEngine.aspx" mce_href="http://www.iiobo.com/ExtensibleStorageEngine.aspx"&gt;http://www.iiobo.com/ExtensibleStorageEngine.aspx&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9535132" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Version 1.2 of ManagedEsent available on CodePlex</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/04/07/version-1-2-of-managedesent-available-on-codeplex.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/04/07/version-1-2-of-managedesent-available-on-codeplex.aspx</id><published>2009-04-07T06:07:00Z</published><updated>2009-04-07T06:07:00Z</updated><content type="html">&lt;P&gt;Version 1.2 of the ManagedEsent interop layer for the&amp;nbsp;ESENT&amp;nbsp;database engine&amp;nbsp;is now&amp;nbsp;available on&amp;nbsp;CodePlex.&amp;nbsp;The three most useful additions here are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;JetEscrowUpdate&lt;/LI&gt;
&lt;LI&gt;JetIntersectIndexes&lt;/LI&gt;
&lt;LI&gt;Helper functions to set/retrieve columns as DateTime&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;JetEscrowUpdate works like Interlocked.Add, allowing a column to be updated in an atomic fashion by mutliple sessions without conflicts. There are several restrictions -- the column must have a default value, has to be JET_coltypLong and cannot be indexed.&lt;/P&gt;
&lt;P&gt;JetIntersectIndexes takes a set of &amp;nbsp;index ranges and returns the records which are found in all the index ranges. This can be used to select records that meet multiple criteria. The StockSample.cs sample application shows how to use JetIntersectIndexes.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://managedesent.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25756" mce_href="http://managedesent.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25756"&gt;The release is up on Codeplex.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The source code now contains the source code for Pixie which is a 'work in progress' managed object layer for ESENT. It is nowhere near complete and will be changing a lot over the coming months.&lt;/EM&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9535073" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Why does JET_coltypBit return 0xFF when set to true?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/04/01/why-does-jet-coltypbit-return-0xff-when-set-to-true.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/04/01/why-does-jet-coltypbit-return-0xff-when-set-to-true.aspx</id><published>2009-04-01T21:28:00Z</published><updated>2009-04-01T21:28:00Z</updated><content type="html">&lt;DIV&gt;On our internal mailing list a user asked "When I retrieve a column of type JET_coltypBit that is set to true, why&amp;nbsp;do I get 0xFF and not 0x1"?&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;My co-worker&amp;nbsp;Ketan had to reach deep into his memory for the answer :-)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;In the very old days, the Jet API was designed as a replacement for the BC7 ISAM. BC = Microsoft Basic Compiler. &lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/wts33hb3(VS.80).aspx" target=_blank&gt;&lt;EM&gt;http://msdn.microsoft.com/en-us/library/wts33hb3(VS.80).aspx&lt;/EM&gt;&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;/EM&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;"When Visual Basic converts &lt;B&gt;Boolean&lt;/B&gt; values to numeric types, &lt;B&gt;False&lt;/B&gt; becomes 0 and &lt;B&gt;True&lt;/B&gt; becomes -1."&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;/EM&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;Now why would do they do this?&amp;nbsp; Because Basic treated Boolean/Bitwise as being the "same" operation. What does "NOT" do? It flips all the bits; hence &lt;/EM&gt;
&lt;DIV&gt;&lt;EM&gt;TRUE&amp;nbsp;= NOT FALSE&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;-1 = ~0&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;/EM&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9527533" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Unsigned considered harmful</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/03/27/unsigned-considered-harmful.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/03/27/unsigned-considered-harmful.aspx</id><published>2009-03-27T03:22:00Z</published><updated>2009-03-27T03:22:00Z</updated><content type="html">(or is&amp;nbsp;"xxx considered harmful" completely worn out as a meme?)&amp;nbsp; 
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;I believe that, in general, people should avoid&amp;nbsp;unsigned variables, even when dealing with quantities which should only be positive. I have three major problems with unsigned variables:&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Subtraction doesn't always make sense&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Unsigned numbers are used to model positive integers and &lt;SPAN style="BACKGROUND: silver; mso-highlight: silver"&gt;positive integers aren't closed under subtraction&lt;/SPAN&gt;.While subtracting two integers always gives another integer, subtracting two positive integers doesn't always give a positive integer. Integer subtraction is much more useful than positive integer subtraction!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Of course with wraparound the subtraction gives an unsigned integer, but that doesn't make arithmetic sense. Signed integers have the same problem, but only at the extremes where wraparound occurs. Even with idealized infinite-bit-length numbers subtraction of unsigned integers is problematic.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Lack of Error-checking on underflow&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;If subtraction does underflow most systems won't generate a runtime exception if they go negative (which would be useful), instead they silently wrap-around (which is not useful). In the end unsigned variables simply alias invalid negative values to positive ones.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Lack of Invalid Values&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;It is extremely useful when a type has support for a clearly invalid/unused value. This can be used both for error-checking and loop termination. Take a loop that iterates through a string backwards:&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;int IchLastCommaInString(const char * const sz) {&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int cch = strlen(sz);&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for(int i = cch-1; i &amp;gt;= 0; --i) {&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if(',' == sz[i]) {&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return i;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return -1;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;If we change the code to use an unsigned variable ("Array indexes can never be negative!") then we lose the ability to easily detect the termination condition:&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;int IchLastCommaInString(const char * const sz) {&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int cch = strlen(sz);&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for(unsigned int i = cch-1; i &amp;gt;= 0; --i) {&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;&amp;lt;= BAD! unsigned ints are always &amp;gt;= 0&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if(',' == sz[i]) {&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return i;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return -1;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Consolas"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;To use an unsigned variable we often end up on the dark and dismal path of "if(x &amp;gt; BIGNUM)" where BIGNUM is chosen to be a value so large that we 'know' that x is really a negative number in disguise. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Just use signed variables.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9512466" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>JET_COLUMNID scope</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/03/17/jet-columnid-scope.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/03/17/jet-columnid-scope.aspx</id><published>2009-03-17T23:47:00Z</published><updated>2009-03-17T23:47:00Z</updated><content type="html">&lt;P&gt;A JET_COLUMNID identifies a column inside of a table (it is actually an index into an internal per-table&amp;nbsp;array of column definition structures). The database meta-data provides a mapping from column name to columnid. The mapping of column names to columnids&amp;nbsp;can change when a database is defragmented by esentutl (esentutl /d). This means that each time you open a&amp;nbsp;database you&amp;nbsp;should use JetGetTableColumnInfo or JetGetColumnInfo to get the ids of the columns you are going to use. This only has to be done once per table -- different sessions that are using the same table will see the name name-&amp;gt;columnid mapping unless you do something crazy like rename your columns with &lt;A href="http://msdn.microsoft.com/en-us/library/ms684040.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms684040.aspx"&gt;JetRenameColumn&lt;/A&gt; (something that I do not recommend)!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9484751" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>What does a failing Assert() mean?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/03/01/what-does-a-failing-assert-mean.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/03/01/what-does-a-failing-assert-mean.aspx</id><published>2009-03-02T00:52:00Z</published><updated>2009-03-02T00:52:00Z</updated><content type="html">&amp;nbsp; 
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri"&gt;When an assert goes off what does it mean?&amp;nbsp;In the codebases I work in, a&amp;nbsp;failing assert doesn't always indicate that the code is about to fail.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri"&gt;There actually are several conditions that we want to check with asserts. The first three are from Meyer's &lt;A class="" href="http://en.wikipedia.org/wiki/Design_by_contract" mce_href="http://en.wikipedia.org/wiki/Design_by_contract"&gt;Design By Contract&lt;/A&gt;:&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; unicode-bidi: embed" type=disc&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Preconditions&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;: conditions that a method requires&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Postconditions&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;: conditions that&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;a piece of method guarantees to be true after executing&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Invariants&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;: class invariants that a method must preserve&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri"&gt;I also see two other real-world uses of asserts:&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; unicode-bidi: embed" type=disc&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Catch probable client misbehaviour&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;: These are cases where the method will work, but the arguments are probably incorrect (e.g. salary greater than $1,000,000,000).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Untested cases&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;: in a situation where not all code-paths have been tested (legacy code) we can put asserts in paths that should work, but aren't currently tested.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri"&gt;The second set of uses are good, but can make code hard to change because making changes can set off a lot of asserts.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-FAMILY: Calibri"&gt;It is useful to distinguish between the cases above. Eiffel does the first three with REQUIRE, ENSURE and INVARIANT. Unfortunately, in plain C++ or C# we just have Assert() which doesn't give any context. We are moving to using different Assert-like macros in our codebase:&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.75in; DIRECTION: ltr; unicode-bidi: embed" type=circle&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Assert(): this condition &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;must&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt; be true for the code to work. Assert( NULL != pv );&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Expected(): a condition that we expect to be true, but isn't required. These &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;probably&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt; indicate client misbehavior. Expect( cbToCopy &amp;lt; 0x40000000);&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Untested(): Document untested code paths. These can be used to expand test coverage, or indicate that changes are extra-risky.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9453085" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Immutable objects in Fluent Interfaces: a lesson from Functional Programming</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/02/16/immutable-objects-in-fluent-interfaces-a-lesson-from-functional-programming.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/02/16/immutable-objects-in-fluent-interfaces-a-lesson-from-functional-programming.aspx</id><published>2009-02-16T13:17:00Z</published><updated>2009-02-16T13:17:00Z</updated><content type="html">&lt;P&gt;&lt;A class="" href="http://www.martinfowler.com/bliki/FluentInterface.html" mce_href="http://www.martinfowler.com/bliki/FluentInterface.html"&gt;Fluent interfaces&lt;/A&gt; are a nice way of building up an API which reads very nicely. Chaining methods together is often a big part of fluent interfaces, but doing so isn't always as straightforward as it looks, especially for configuration objects. Suppose I'm building up some database meta-data, and I'm defining a new column using method chaining:&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;&amp;nbsp;var firstColumn = DefinedAs.TextColumn("name");&lt;/P&gt;&lt;/CODE&gt;
&lt;P&gt;Now suppose I have another table which also happens to have a text column called 'name', except it also has a default value. To save typing I decide to build on top of the column definition I already have:&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;&amp;nbsp;var secondColumn = firstColumn.WithDefaultValue("Jane Doe");&lt;/P&gt;&lt;/CODE&gt;
&lt;P&gt;If the WithDefaultValue() method is implemented the wrong way it will directly modify the firstColumn structure, which is a very unfluent thing as it doesn't fit with the name of the method (a method called 'SetDefaultValue' might be expected to modify the existing object but 'WithDefaultValue' sounds like it is creating a new object). Instead, for an interface like this, I think that an existing configuration should never be modified. Instead,&amp;nbsp;applying an option to&amp;nbsp;a configuration object should always return a new configuration object. Doing this means that firstColumn and secondColumn will refer to different objects and the API won't surprise the user. &lt;/P&gt;
&lt;P&gt;(Of course the functional programming people knew this all along)&lt;/P&gt;
&lt;P&gt;The expense of creating the extra objects is something to consider, but in the vast majority of cases creating configuration objects like this shouldn't be a big part of application runtime.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9425697" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>Cheaply estimating the number of records in a table</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/02/10/cheaply-estimating-the-number-of-records-in-a-table.aspx" /><link rel="enclosure" type="image/x-png" length="16842" href="http://blogs.msdn.com/laurionb/attachment/9409959.ashx" /><id>http://blogs.msdn.com/laurionb/archive/2009/02/10/cheaply-estimating-the-number-of-records-in-a-table.aspx</id><published>2009-02-10T08:22:00Z</published><updated>2009-02-10T08:22:00Z</updated><content type="html">&lt;P&gt;Counting the number of records in a table can be extremely expensive, as it requires reading all the database pages off disk. It is possible to get a reasonably accurate estimate the number of records in a table by using the&amp;nbsp;JetGetRecordPosition API. JetGetRecordPosition should be called when the cursor is on a record and it&amp;nbsp;fills in a JET_RECPOS structure with two numbers, the estimated position&amp;nbsp;of the record&amp;nbsp;table (centriesLT)&amp;nbsp;and the estimated number of records (centriesTotal). Together these two numbers form a fraction indicating how far into the table the record is.&lt;/P&gt;
&lt;P&gt;We calculate centriesTotal and centriesLT by looking at the fanout of the pages in the b-tree that lead to the current record so the numbers produced by&amp;nbsp;JetGetRecordPosition aren't terribly accurate unless all records in the b-tree are the same size and are packed to the same density. The estimate can be improved greatly by taking multiple samples from different places in the b-tree. We can easily go to different places in the b-tree with the JetGotoPosition API, which tries to position the cursor to a fractional location in the table. This has the same problems as JetGetRecordPosition (it isn't very accurate) but it is perfect for this purpose.&lt;/P&gt;
&lt;P&gt;So, we can simply use JetGotoPosition to position the cursor at different locations in the table and then call JetGetRecordPosition to get an estimate of the number of records in the b-tree. Averaging out the numbers should give a reasonable estimate. The code looks like this:&lt;/P&gt;&lt;CODE&gt;
&lt;P&gt;JET_ERR ErrGetApproximateRecordCount(const JET_SESID sesid, const JET_TABLEID tableid, const int cSamples, int * const pcRecords)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;*pcRecords = 0;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;JET_ERR err;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;int cRecordsTotal = 0;&lt;BR&gt;&amp;nbsp;for(int i = 0; i &amp;lt; cSamples; ++i)&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;JET_RECPOS recpos = {0};&lt;BR&gt;&amp;nbsp;&amp;nbsp;recpos.cbStruct = sizeof(recpos);&lt;BR&gt;&amp;nbsp;&amp;nbsp;recpos.centriesTotal = cSamples + 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;recpos.centriesLT = i+1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;if (JET_errSuccess != (err = JetGotoPosition(sesid, tableid, &amp;amp;recpos)))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return err;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;if (JET_errSuccess != (err = JetGetRecordPosition(sesid, tableid, &amp;amp;recpos, sizeof(recpos))))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return err;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;cRecordsTotal += recpos.centriesTotal;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;*pcRecords = cRecordsTotal / cSamples;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;return JET_errSuccess; &lt;BR&gt;}&lt;/P&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;
&lt;P&gt;To see how accurate this is I wrote a test program that inserted between 1 and 100,000 records into a table, each record having between 1 and 1024 bytes of data. Then I called ErrGetApproximateRecordCount with cSamples ranging from 1 to 64. I ran a total of&amp;nbsp;1,000 trials of the test program and graphed the results. It looks like somewhere around 15 samples gives a reasonable accurate number (&amp;lt; 5% error). Assuming a non-cached table the 15 samples will cost 1 or 2 page reads each&amp;nbsp;so it should take about 1/3 of a second, which is very cheap compared to the cost of reading in the entire table.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9409959" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>A dbm-like interface for Esent on IronPython</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/01/12/a-dbm-like-interface-for-esent-on-ironpython.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/01/12/a-dbm-like-interface-for-esent-on-ironpython.aspx</id><published>2009-01-12T11:53:00Z</published><updated>2009-01-12T11:53:00Z</updated><content type="html">&lt;P&gt;I've&amp;nbsp;wanted to be able to use Esent as a simple, fast, reliable and persistent key/value store.&amp;nbsp;The Python standard libraries contain that kind of functionality in the&amp;nbsp;*dbm modules. I've been working on providing identical functionality layered on top of Esent. I've uploaded the esedb module to the&amp;nbsp;release page for &lt;A href="http://www.codeplex.com/ManagedEsent" mce_href="http://www.codeplex.com/ManagedEsent"&gt;ManagedEsent on&amp;nbsp;Codeplex&lt;/A&gt;. To use it you need Esent.Interop.dll and esedb.py. The module exports an open function which returns a dictionary object that is backed by an Esent database. The dictionary keys and values are restricted to strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp;db = open('test.db')&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; db['a'] = 'somedata'&lt;BR&gt;&amp;gt;&amp;gt;&amp;gt; db['a']&lt;BR&gt;'somedata'&lt;/P&gt;
&lt;P&gt;The module is still under development, but the current functionality should be quite stable.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9307323" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry><entry><title>A C++ Refactoring Trick for "Encapsulate Field"</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/laurionb/archive/2009/01/08/c-refactoring-trick.aspx" /><id>http://blogs.msdn.com/laurionb/archive/2009/01/08/c-refactoring-trick.aspx</id><published>2009-01-08T13:21:00Z</published><updated>2009-01-08T13:21:00Z</updated><content type="html">&lt;P&gt;I was working on some old code that had a structure that looked like this&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;struct Foo {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool fOptionEnabled;&lt;BR&gt;};&lt;BR&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Tons of places in the code would check to see if the option was enabled, and do something based on it. The change I needed to make required that I do some extra work whenever the option was enabled. A good way to do this is to use the "&lt;A class="" href="http://www.refactoring.com/catalog/encapsulateField.html" mce_href="http://www.refactoring.com/catalog/encapsulateField.html"&gt;Encapsulate Field&lt;/A&gt;" refactoring to reroute access to fOptionEnabled through accessors and then change the set method to be a more domain-specific&amp;nbsp;"EnableOption()" and do all the required work in it.&lt;/P&gt;
&lt;P&gt;The problem is that the amount of code affected to do this was very large and I didn't want to do it all at once. Instead I used an intermediate way of turning off&amp;nbsp;just the set access to the variable (at the cost of making the structure a few bytes larger):&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;struct Foo {&lt;BR&gt;private:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool m_fOptionEnabled;&lt;BR&gt;&lt;BR&gt;public:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const bool&amp;amp; fOptionEnabled;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Foo() : fOptionEnabled(m_fOptionEnabled) {}&lt;BR&gt;};&lt;BR&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;This change meant that code that read fOptionEnabled continued to compile and work, while code that tried to set it started failing. This let me change all the places that turned the option on to use Foo::EnableOption(). After that I actually went ahead and encapsulated read access to the variable as well, but using this trick means you can work in smaller steps, with fewer changes between passing tests. That is always a good thing when you have to manually refactor code.&lt;/P&gt;
&lt;P&gt;Doing refactorings like this definitely makes me appreciate the argument behind Meyer's &lt;A class="" href="http://en.wikipedia.org/wiki/Uniform_access_principle" mce_href="http://en.wikipedia.org/wiki/Uniform_access_principle"&gt;Uniform Access Principle&lt;/A&gt;. In C# this change can be made quite easily by using properties (of course, hiding the implementation like that will upset some people -- they want to see the () so that they know what is going on).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9267512" width="1" height="1"&gt;</content><author><name>laurionb</name><uri>http://blogs.msdn.com/members/laurionb.aspx</uri></author></entry></feed>