Welcome to EMC Consulting Blogs Sign in | Join | Help

John Rayner's Blog (2006-2010)

Brain.Extract<IBloggable>( Where.Author.Is( "John.Rayner" ) );

  • Downloading sessions from MIX10 (and PDC09)

    To get hold of the videos of the sessions from the recent MIX10 conference, the MIX10 site suggests you download cURL and hack around with some .bat files.  Yuck!  But now a much nicer option is available - Naeem Khedarun from #Fellows has recently announced a WPF session downloader.  It supports resuming of interrupted downloaded and you can install it via the magic of ClickOnce directly from the #Fellows site (see Naeem's post for the URL).

    As an added extra, downloads of the PDC 2009 videos still work from this application.  So install it once and you get easy access to 280 hours of technical goodness!  Including, of course, our very own Paul Dawson.

  • Another reason to love Resharper: it can make you look like a LINQ-ninja

    EDIT: I became a SharpFellow and so this blog post has moved 

    For those of who spend our time immersed in code, we're usually trying to find ways to write better code that more clearly expresses our intent.  And in a place like EMC Consulting there is a very healthy competition between devs to write code that is better, cleaner, faster, etc.  One of the new features of Resharper 5.0 (R#) manages to address both of these points!  Big Smile

    Jetbrains have given R# a pretty deep understanding of LINQ.  To be honest, I'm feeling like R# knows LINQ considerably better than I do!  You see, R# 5.0 will offer to convert your code into LINQ statements wherever it can.  Here's an example:

    My code:

     foreach(var summaryType in TypeMapper.GetMapper(entityType.Assembly)

               .GetSummaryTypes(entityType))

     {

       if(typeof(VersionableSummaryBase).IsAssignableFrom(summaryType))

       {

         var summary = (VersionableSummaryBase)EntityCache.Instance.RetrieveIfCached(id, summaryType);

         if (((IVersionable)entity).Version < summary.Version)

         {

            mustReload = true;

            break;

         }

       }

     }

    Applying the R# suggestion:

     mustReload = TypeMapper.GetMapper(entityType.Assembly)

                      .GetSummaryTypes(entityType)

                      .Where(summaryType => typeof (VersionableSummaryBase).IsAssignableFrom(summaryType))

                      .Select(summaryType => (VersionableSummaryBase) EntityCache.Instance.RetrieveIfCached(id, summaryType))

                      .Where(summary => summary != null)

                      .Select(summary => summary.Version)

                      .Any(summaryVersion => ((IVersionable) entity).Version < summaryVersion);

    Even without understanding what my TypeMapper class is doing, or any of the other details you can clearly see, I think that the second version is easier to read and more clearly expresses the underlying algorithm.  If you have an opinion on this, then please leave it in the comments ... I'd love to get other views.

    Here's another gem from R#.  My code:

    var sourceElements = new Dictionary<int, EntityBase>();

     

    foreach (EntityBase element in collectionFromSource)

    {

        sourceElements.Add(element.InternalID, element);

    }

    And the R# version:

    var sourceElements = collectionFromSource.Cast<EntityBase>()

                                             .ToDictionary(element => element.InternalID);

     

    I didn't even know that that particular extension methods existed until R# suggested I use it!  And perhaps with R# 5.0 in my toolkit, I'll be able to get the edge over some of the other devs at work.  At least, until someone blogs about it ... oh bother!  Wink

     

     

  • Sharding into the cloud

    EDIT: I became a SharpFellow and so this blog post has moved  

    NHibernate.Shards is an extension to the well-known ORM which allows a logical database to be partitioned across multiple physical databases and servers.  It's a port of the Hibernate.Shards project, as with lots of thing in NHibernate.  I thought it would be interesting to see how well it worked against SQL Azure.  It turned out to be not interesting at all ... just plain easy!  Big Smile

    Step 1: Register with SQL Azure
    Turnaround on token requests is pretty quick right now (<24 hours in my case).

    Step 2: Setup some SQL Azure databases

    Step 3: Setup appropriate logins, users
    The SQL Azure team have done a great job to allow SQL Server Management Studio to connect a query window to an Azure database, but I'm a bit SQL-phobic at the best of times. This was the most challenging bit for me!

    Step 4: Download and compile NHibernate.Shards from NHContrib Subversion

    Step 5: Set your connection strings in the config file

    Step 6: Press play.  Really, that's all there is to it!

    Now you may notice that I neglected to create any schema in the Azure databases - that's because NHibernate can do that for me.  Did I mention that I'm a bit SQL-phobic?  Wink

    The code I was using was the standard example that comes with NHibernate.Shards, which records WeatherReport objects, which I've attached.  It's the same example that Ayende dissected, so you can also pick up his discussion of the workings of NHibernate.Shards.  The code looks like this (click to enlarge):

    And the results are as follows (click to enlarge):

    Some of the features of NHibernate.Shards that really stood out for me:

    • It can query all shards in parallel or sequentially.  For SQL Azure, that's quite useful!  A sequential query my single-record shards took 601ms, whereas a parallelized query took 411ms (almost 33% less).
    • New records can be allocated to shards based on either the data (e.g. surname starts with A-M or N-Z) or some other scheme (e.g. round-robin).
    • If the correct shard can be identified based on an object's identity, then only that single shard is queried to retrieve the entity (this is based on your own IShardResolutionStrategy implementation).
    • If you sort by a property, then this sort will be applied even when data is merged from multiple shards.

    Overall though, it all just works tremendously well.  Congratulations really must go to:

    • The Microsoft SQL Azure team
    • Dario Quintana, for his work on NHibernate.Shards
    • Fabio, Ayende and the rest of the NHibernate committers

    EDIT: Querying data from the shards is done using code like the following.  You should notice that this code makes no references to the shards, and in fact is "normal" NHibernate code.  The sharding is all handled transparently in the ORM.

  • Google Chrome: First impressions (and a few benchmarks)

    EDIT: I became a SharpFellow and so this blog post has moved

    Google Chrome has now been released for download - see Derek's post for some opinion on this or the "leaked" information from Google.  I've installed it and I have to say that I like it a lot - the minimalist UI is rather nice (although IE7 has drifted in a similar direction), the "omnibox" (was previously the address bar) seems to actually work in terms of how it handles it's auto completion and the initial start page is a great idea.  But the thing that really got to me was just how fast it is.  And I mean ...

    FAST

    There's lots of numbers below where I try to measure just how fast Google Chrome is compared to IE 7, but what really impressed me was when my wife (who is non-techie) browsed a few sites using Chrome and noticed the difference in speed.

    To see just how real the speed increase was, I visited a number of benchmarking sites.  QuirksMode have a benchmark for creating HTML table elements via JavaScript.  As the following table outlines, IE 7 took 4,652 ms to complete all the tests and Google Chrome took 186 ms.  That's literally an order of magnitude faster.

    Celtic Kane has a benchmark which attempts to measure the core JavaScript engine.  Again, Google Chrome is literally an order of magnitude faster than IE 7 and it looks to me as if Chrome would probably come top of his overall performance table.

    As a final test, I loaded up the SunSpider test from WebKit - this is a test which purports to target real-world usage and avoid "useless" micro-benchmarks.  I expected Chrome to do well against this, since Google say that Webkit forms a big part of the Chrome browser, but Chrome managed to beat my already high expectations.  It came in 16.9 times faster than IE 7 and some of the differences were simply staggering.

    Overall, this is quite an amazing first drop of code and I didn't have a single crash or notice any rendering errors.  I'll leave others to speculate on exactly what this means for Microsoft's Internet Explorer, but I think it's fair to say that Google have raised the standard of what to expect from a browser quite considerably.

    [EDIT: Rory has also posted about Google Chrome.  The interesting thing is that he also includes some numbers about memory usage.]

  • ReSharper 4.0 from JetBrains is released

    EDIT: I became a SharpFellow and so this blog post has moved  

    The JetBrains team have been working hard at getting functionality and bug fixes into version 4.0 of ReSharper.  I'm very excited to see that it's finally reached RTM status and now fully supports Visual Studio 2008 and all the C# 3.0 goodness!  Go get it here.  For those who have been involved in the EAP program, it's actually build 819.

    For those who've never tried R#, I strongly suggest that you take it for a spin.  The improvements it brings to productivity are just immense.  For the full list of features the JetBrains site has all the info, but here are a couple of my favourite features:

    Go To File / MemberGo To File / Type / Member
    This functionality is brilliant at quickly navigating around large solutions.  You can type in the full name of the class / method / file that you are after, just the capital letters, you can use wildcards or you can combine all these techniques.

    Refactoring Options
    Yes I know that Visual Studio has included some refactoring functionality for a while now, but this one of ReSharper primary strengths.  It includes options such as:

    • Rename class / method / variable / parameter / field / property (optionally searches within comments and strings)
    • Change signature
    • Extract / inline a method
    • Extract interface / superclass
    • Push members up / pull members down
    • Introduce parameter
    • Introduce field
    • Introduce variable (I esp like the way it detects multiple occurrences of an expression of offers to replace them all)
    • Convert anonymous delegates to / from lamdas
    • Set field values from constructor arguments

    There's so many of these - these are just the ones I can think of right now.  In fact, there are so many that I always keep a copy of the ReSharper keyboard mappings on my desk.

    Coding in Reverse
    Undoutebdly the most powerful feature available within ReSharper, JetBrains picked it out as the primary skill of the ReSharper Jedi.  This is a technique where you use variables / methods / classes before they exist.  ReSharper will then infer their definition from your usage and allow you to actualize them with a couple of keystrokes.  It's immensely powerful, but it's really got to be seen to be fully appreciated.

    And More
    I strongly ReSharper to all developers who want to improve their productivity ... which should be all developers.  I also strongly suggest that you take some time out to learn the featureset and some of the options available within ReSharper.  Joe White's blog series The 31 Days of ReSharper is a great place to start this journey.  Just be warned that you might get seriously hooked.

  • Design-time perf improvements in Visual Studio 2008

    EDIT: I became a SharpFellow and so this blog post has moved  

    Some metrics that we captured on my project: (I think the numbers speak for themselves)

    Operation     VS 2005     VS 2008           % Improvement
    Start the IDE 00:30 00:09 70%
    Load solution 03:45 00:45 80%
    Get Latest (no changes) 00:13 00:05 62%
    Rebuild solution 02:21 01:58 16%
    Run all tests 05:29 03:44 32%
    Start the application 00:19 00:18 5%

    FYI our solution has 33 projects in it (including a database project, a web application project, numerous DLLs, an EXE and a WiX installer) and there are almost 1,600 unit and integration tests.

  • Altnetconf UK: First round of registration is closed

    EDIT: I became a SharpFellow and so this blog post has moved  

    Registration to the first ALT.Net UK conference was recently announced by Michelle.  Unfortunately it's already full, so if you're name isn't on the participants list of people who have registered then I'm afraid you're a bit late for this round.  Ian Cooper says that another batch of registrations will open soon, so those who watch closely may still be able to attend.  I'm pleased to announce that I will be attending the conference as a Conchango representative.
  • Exploring quality in software architecture

    EDIT: I became a SharpFellow and so this blog post has moved  

    Strength, utility and beauty.  Here we will be exploring a number of the traditional “ilities” of software architecture and seeing how they can be related to these three architectural qualities.  These three qualities have been around for quite a while, under their Latin names of firmitas, utilitas and venustas, and were first written about by Vitruvius.

    Now architecture is always created with the intention of supporting something, e.g. an application (in the case of application architecture) or a business (in the case of enterprise architecture).  For brevity, I’ll refer to “the thing which the architecture supports” as “the system”, although I believe that my points here relate to all types of software architecture.

    Utilitas, or Utility: Functional and behavioural aspects of the architecture

    The architecture needs to guarantee that the system can perform operations in a certain manner.  Architectural aspects which achieve this are:

    ·         Availability – expected levels of uptime that the architecture can provide

    ·         Auditability – keeping a log of changes and operations within the system.

    ·         Correctness and verifiability – sometimes operations within the system can be externally verified.  The architecture needs to support and pass such verification.

    ·         Environmental compatibility – the architecture needs to fit into its environment, e.g. there may be a high latency network which needs to be considered

    ·         Performance – how quickly operations can be performed

    ·         Security and confidentiality – authentication and authorisation

    ·         Transactionality – the architecture needs to ensure that operations are atomic

    A person can only really be called an architect if they can design an architecture that works, i.e. displays these aspects.

    Firmitas, or Strength: Non-functional aspects of the architecture

    In addition to supporting the operations of the system, there are a number of further considerations for architecture:

    ·         Adaptability – how well the architecture can cope to evolving situations without being changed

    ·         Efficiency – how well does the architecture use its resources such as CPU, memory, bandwidth, etc

    ·         Extensibility – how easily can the architecture be extended and changed

    ·         Maintainability – this is really just a combination of extensibility and understandability.  If an architecture is easy to understand and easy to change, then it is easy to maintain.

    ·         Recoverability – is it possible to reconstitute the state of the system after a disaster

    ·         Reliability – how stable is the architecture under normal circumstances

    ·         Resiliance – how stable is the architecture under abnormal circumstances

    ·         Scalability – can the throughput of the system be increased without requiring changes

    ·         Understandability – how easy is it to comprehend the architecture

    Really good architects manage to incorporate these aspects into architecture they design.

    Venustas, or Beauty: Aesthetic aspects of the architecture

    Beauty, as a quality, is practically impossible to define objectively.  “Beauty is in the eye of the beholder”, as the saying goes.  However, you do know beauty when you see it.  Here are some points which I think contribute to making architecture beautiful:

    ·         Conceptual integrity – sometimes called the principle of least surprise, there should be an underlying theme or vision that unifies the design of the architecture at all levels

    ·         Elegance – closely related to simplicity, elegance implies a certain understated effortlessness

    ·         Simplicity – an architecture should be as simple as possible, but not simplistic

    An architect that can incorporate these aspects into a design that also displays utility and strength, is really one of the greats.

    And so what?

    And so we have a bit of a framework for inspecting the quality of architecture.  I don’t regard all of these aspects as quantitative, but at least we can discuss architecture in qualitative terms.  In my next post, I’ll be discussing some of the specific considerations of iterative development of software and how these points here should influence that process.

  • What makes a good (software) architecture

    EDIT: I became a SharpFellow and so this blog post has moved  

    Lately I've been investigating software architecture with regard to how it can impact on an agile development project. I recently read (here) a very short list that resonated really powerfully with me and describes key architectural virtues (explanations are mine):

    • Strength - reliable, secure, resilient to change
    • Utility - must deliver either business value or (more likely) developer productivity
    • Beauty - easy to understand and communicate, clean design, minimal

    It turns out that these ideas have been around for quite a while, under their Latin names of firmitas, utilitas and venustas.

    I hope to produce a series of blog posts detailing my thoughts and expanding on some of these points, including why I think this question is especially relevant to iterative development.

  • SAPI: Speech synthesis on Vista

    EDIT: I became a SharpFellow and so this blog post has moved  

    The MIX07 Keynote includes a brief screen capture from the Daily Mail eReader and reminded me that I had meant to blog about the speech synthesis portion of the app.  It's something which many users might not have seen, because it's only available on Windows Vista.  Vista includes the Speech API (SAPI) version 5.3 which provides a text-to-speech (TTS) engine which is greatly superior to SAPI 5.2 which shipped with Windows XP.

    Speak the News with the Daily Mail eReader

    How it looks 

    The way the UI works is pretty straightforward - it's meant to mimic an autocue.  So a user will trigger the functionality and the window you see on the right will appear.  As the user's computer begins speaking the news story, the text will slowly scroll up.  The word currently being spoken will always be bold and will always appear in the letterbox.

    I'm presonally a bit tickled that this bit of UI made it into Ray Ozzie's keynote presentation (even if it was only for about a quarter of a second) because I developed this part of the eReader and wrote this UI.

    Getting SAPI to produce speech

    The TTS functionality is actually quite easy to kick off.  All it takes is a call to the appropriate function, passing in a string holding the text to be read, and SAPI will begin to speak.  Specifically, .Net 3.0 provides a System.Speech assembly which does all the hard work for you.  This assembly includes the class System.Speech.Synthesis.SpeechSynthesizer which has a method public void Speak(string textToSpeak).  This is easy to use if all you want is text-to-speech.

    The problem is that this is a synchronous call.  So the call will block until the speech rendering is complete.  To get around this, the SpeechSynthesizer class also includes a method SpeakAsync.  This does pretty much what you'd expect and runs the TTS activity on a background thread.

    Getting updated with TTS progress

    Now the SpeechSynthesizer class even provides some helpful events relating to the progress of the speech rendering.  However, it turns out that the SAPI libraries regard these events as sort of incidental to their main job - i.e. they will raise the events when they can.  So there is every possibility that these events will occur some time after the actual speech rendering of a word (or phoneme, etc) has started.  The SAPI library also seems to stop raising the events altogether, if the event handlers are consuming too much time.  This was probably a design decision made by Microsoft that the quality of the speech shouldn't be affected by calls to user code.

    This last point means that you need to be very careful how you write your event handlers.  I suspect that a fair amount of time is consumed with the transition from the unmanaged SAPI libraries back into the System.Speech assembly, which doesn't leave much time for your C# code to do anything useful.  It certainly doesn't leave enough time to update a XAML UI.  The initial approach I used would update the UI with about 2 or 3 words and then UI updating would cease altogether.

    The solution was (a) to be very, very careful to write efficient code; (b) use the Output window for debug info rather than trying to break into the running code; and (c) make good use of asynchronous delegates.  The SAPI events are called on a background thread, which means that a Dispatcher.Invoke call is needed before code can update the UI at all.  So the simplest solution was to replace this with a Dispatcher.BeginInvoke call which then updated the UI asynchronously to the event handler.

    Constructing the UI

    It took a little bit of trial and error to get a XAML UI that could efficiently update without continually doing a lot of layout work.  Ironically, the grey letterbox with its opacity and the opacity gradient of the textual content were the easy bits!  And getting a thick window border of Vista glass was also pretty trivial. The part which took some effort was working out that to display the content I needed to use a ScrollViewer control with three separate Run elements - one for the text which had been read, one for the text being read and one for the text which is still to be read.  The updates from the TTS engine can then simply be translated into shuffling characters between the various Run elements.

    Getting the highlighted word to stay in the letterbox also took some trial and error.  The solution lay in the following line of code:

    Rect screenPosition = CurrentlyReadingRun.ContentStart.GetCharacterRect(LogicalDirection.Forward);

    This gave me the screen co-ordinates of the currently bold word, which I then used like so:

    _scrollViewer.ScrollToVerticalOffset(screenPosition.Top + _scrollViewer.VerticalOffset - _paddingHeight);

    Posted 10 May 2007 01:11 by john.rayner | 0 Comments
    Filed under: , , ,
Powered by Community Server (Personal Edition), by Telligent Systems