Expectations Are Everything

Quick Bit

Anyone who has ever debugged a program knows that you tend to see what you expect. I’ve learned that lesson a dozen times, in a dozen ways. 

A classic example is to ask someone to read the following illustration aloud (don’t over-think it but when you’re sure you’re done, see the answer here).

 

ParisInTheSpring

 

 

 

 

 

 

Expectations

Today, I got smacked in the face with the power of expectations.  One of the best dog trainers I ever met recently recommended a new kind of dog harness to us; saying “you never tug or pull the dog; you just walk and it makes it more comfortable for him to come with you than to do anything else.”

So, we plopped down our $20 for a Gentle Leader Easy Walk harness, and then it sat in the mudroom  HarnessOnDog for three weeks before I finally got around to trying it.  I put it on and – wow! what a difference. Just like Jen said, no pulling, no tugging, I didn’t have to “correct” him at all (I hate being corrected, myself).  It was really quite impressive until I got home and took it off him and found I’d accidentally attached his lead to his traditional collar, and the new harness had not been at work at all.

Lesson learned? For about 5 minutes.

 

 

PS: Jen is also the trainer who told me “A tired dog is a good dog, and an exhausted dog is a great dog.”  For two ultra-short movies of Charlie please see here or here.

Posted in z Silverlight Archives | Comments Off on Expectations Are Everything

Building A Product For Real

As some of you know; I’ve been showing a number of Silverlight features in terms of Project Turing.  It was never my intention to finish that project; rather to use it as a mooring point to ensure that the mini-tutorials were realistic about building applications.

The second purpose of the Turing project was as a proof of concept. I now have the green light to go for a full development process, with the clear goal of creating a working application that will be:

  • A complete design to delivery project
  • A source of frequent mini-tutorials and videos
  • An opportunity for much more intense community contribution
  • An opportunity to work with designers and the Expression team
  • A product we can put to use here on Silverlight.net

It just doesn’t get any better than that. 

Who, What, When, Where and Why

Who:  If all goes as planned, this project will be moderated open-source with active participation and contributions from as many in the community as care to participate. Until now, I’ve been doing what I refer to as “glass house” programming; that is, designing and programming myself, but openly and documented.  It is possible that the initial stages will be glass house, but the plan of record is to move to Open Source.

What: The VideoWiki project lends itself to being completed in two discrete phases.  Phase 1 will be the creation of a Silverlight HyperVideo player targeted at enhanced How-Do-I videos. Phase 2, moving from HyperVideo to VideoWiki will follow if time and interest allows.

When:  While I already have a number of postings on HyperVideo, it is time to re-think, redesign and to create a detailed specification.  I’ll deliver that, here on my blog, by November 30. 

Design and Coding begin December 1, 2009 and will be completed by July 1, 2010.

Where: For now the project will live on my blog; but if this is to be truly open source then it must move to CodePlex. That is the goal.

Why:  To meet the needs of both novice and intermediate Silverlight programmers, and if Silverlight 4 comes along during our development time, to provide a great basis for introducing new features.

It shouldn’t be all that hard

The truth is that this is not all that big a project, and a quick look at the work done last year reveals that the tools will do a lot of the work for us. That said, there are some interesting subtleties we should be able to explore along the way.

If you have early thoughts about what should/must/must-not be in the project, be sure to let me know.

With PDC on the way, there will be a short-term drop in the release of videos and mini-tutorials for the next couple weeks., though I will make sure that there are some very substantive posts during that period. Expect a sharp uptick afterwards.

Posted in z Silverlight Archives | Tagged | Comments Off on Building A Product For Real

Time To Update My Favorites

Periodically I take a shot at listing my favorites: some folks find useful items they hadn’t looked at and it forces me to take a long hard look at whether it is time to try something new.

Today: Favorite Utilities

Business success team

Upcoming:

  • Favorite Mac Utilities
  • Favorite iPhone Apps
  • Favorite Programmer Utilities
  • Favorite Non-fiction
  • Favorite Fiction
  • Favorite Programming Books
  • Favorite Music (uh oh)

On the one hand, I can’t imagine why you’d care. On the other hand, building a community is more than just code; and sharing favorites can be more than just utilitarian.  In any case, you (no, really, you) are strongly encouraged, asked, pleaded with;  to comment, add your fave’s and etc.

Favorite Utilities 2009

NB: This list does not include my favorite programming utilities, and  is just those utilities that run on Win 7 (which is now on all my Win machines)

 

Amazon’s Media Library – one of the better ways to share what you’re reading and listening to. Dynamic, configurable, pretty easy to cope with.

Auto Hot Key – Finally! Add macros to a simple text file and they work everwhere.  I have two files: auto-correct (fixes common spelling errors instantly) and my macros. For example “@me” instantly changes to http://www.SilverlightGeek.me  The syntax is simple and adding or modifying a macro takes seconds.

ClipX – Very sweet, small, easy to use clipboard manager, with “yank-pop” and with reserved phrases you can reach easily.  Learning time: 2 min.

Evernote – Create (or clip) notes about anything, organize to the extent you want, find them instantly, access via PC, Mac, phone, web. Truly brilliant. Truly indispensable.  Uses include everything from meeting notes to taking a picture of your car and asking it to lead you back using the GPS. You can also ask “show me every note I wrote in the past 2 years when I was within 50 miles of right here” – great for biz travel.  See iPhone Utilities.

Exam Diff Pro – best I know for examining differences in files and directories.  More coverage under Programming utilities, but I also use it for comparing documents.

FinePrint – print pages 2-up and much more. Can save a lot of paper and a surprising amount of printing time. Installs as a printer.

GoToMyPC – access your pc securely from anywhere. Just great, though I may give it up if the built in functionality in Win7 is sufficient.

GoodSync – Easy, efficient backup or synchronization between computers. 

iMo Hulu Desktop – Changed the way I deal with TV. I’m not much of a TV watcher, but the ability to queue up shows, subscribe and watch on my PC (for which I highly recommend the iMo Pivot 7” USB screen) has meant watching the Daily Shows that I’d otherwise miss.

Hypersnap DX – My screen capture of choice for many years and I still really like it, but it is time to check out Snaggit combined with Paint.Net

Live Writer – Best blog authoring software I know of. Be sure to pick the best of the plugins.

Pandora – The Music Genome Project. Single best music site on the net, now on phones as well and I swear it is getting better. Be certain to find their technical background material and to explore how the service works. This is not “wisdom of the crowds” this is “quantify all you can about music and then find other music that is similar in meaningful ways. See this good intro from the NY Times.

Roboform – Individual passwords for every site, generates strong passwords, master password to protect them all. Easy, fast, effective, customizable and totally reliable. Now supports sharing across multiple PCs. Partial integration Stackswith 1Password (see Mac Utilities).

7Stacks – Nice small utility that lets you create a stack of links on your toolbar. In the image shown, my stack is linked to a folder; anything in the folder pops up in the stack. 

Trillian – All your IM Services in one place. I particularly like the ability to tie actions to events. I’ve set it up so that adding the word urgent to the text causes it to make a special sound. Very flexible.

Virtual Clone Drive Allows you to mount an ISO, BIN or other image file onto what appears to be a physical drive, but is actually a virtual drive. Very slick (and free!)

Posted in z Silverlight Archives | Tagged | 1 Comment

Bayesian Probability

 

Spent the early hours of this morning reading a great blog post by Jeff Atwood which makes reference to a Elizer S. Yudkowsky’s Intuitive Explanation of  Bayesian Probability. The timing was good as I had just finished the (highly recommended) book The Drunkard’s Walk which agreed with Jeff that most humans simply are not wired to deal with probability very well.

The Drunkard’s Walk: How Randomness Rules Our Lives (Vintage) (9780307275172): Leonard Mlodinow: Books
ISBN: 0307275175
ISBN-13: 9780307275172

Yudkowsky poses the following canonical problem:

1% of women at age forty who participate in routine screening have breast cancer. 80% of women with breast cancer will get positive mammographies. 9.6% of women without breast cancer will also get positive mammographies. A woman in this age group had a positive mammography in a routine screening. What is the probability that she actually has breast cancer?

The frightening thing is that according to Atwood, only 15% of doctors get this right. And they’re off by a lot. That is, the average answer is in the range of 80% while the correct answer is 7.8%.  Apparently, there is something about the way we think about the problem that makes 7.8% hard to accept, and Yudkowsky does a great job of walking you through the logic in painfully small steps.

To me, however, there is a pretty straight-forward way to think about this (though it may only be intuitive since I’ve been through this a few times).

What Do We Know & What Does It Imply?

We have three pieces of information:

1% of sample are TRUE  (that is have cancer)

80% of sample who are TRUE will test TRUE

9.6% of sample who are FALSE will test TRUE.

On the face of it, we should guess that the percentage of women who test TRUE who actually are TRUE (test positive and actually have cancer)  is pretty small based on two facts provided: the actual percentage of women from the sample who are TRUE (regardless of testing) is only 1%, and the test has a false positive for 9.6% of those tested.

So, my reasoning to solve this is:

1. Assume we have a sample of 1000 women (I use 1000 to reduce the amount I have to talk about fractional people, but I don’t use 10,000 as I get lost in the zeros).

2. We know that the reality is that of the 1,000 women, 10 will have cancer (1%).

990 = no cancer
10 = cancer

3. Of the 10 who have cancer, 8 will test positive
8 out 1000 women tested will test True and are True

4. Of the 990 with no cancer 9.6% will also test positive = 990 * .096 = 95.04. 
95.04 women out of 1,000 will test True but are False.

5. The total number testing true is 8 + 95.04 = 103.04. 
Of these, 8 actually have Cancer.

6. So the value for tests positive (103.04) versus is positive (8) is 8:103.4 or 0.773  or 7.8% 
(8 of the 103.4 = 8/103.4)

Not Being Misled

The key to this and many problems like it is to realize that what you are trying to find is the relationship between those who Test positive vs. the reality of those who are positive, which is why you need all three numbers.

Probability is Weird and Cancer Is Scary

True story: I have a friend who is the head of breast cancer surgery at a very respected hospital. I was at a dinner party where he mentioned that a “very small percentage of those who show up with a positive test actually have cancer.”  This caused a lot of confusion, and that is because we (a) don’t deal with probability well and (b) don’t understand policy tradeoffs as a result.

From a policy point of view, it is too expensive (money, time, etc.) to test everyone with a biopsy, etc.  The preliminary screening is sufficient to move your knowledge from the general 1% probability to the more specific 7.8%, which is enough to pursue. The fact that 20% of women with cancer will get a false negative doesn’t mean that it is better to test everyone, and the fact that out of every 1,000 tested 95 will falsely test positive (and be subjected to needless worry) also does not mean that it isn’t worth using the screening test.

That said, it would be good if, before you took the test, you were told that a positive result means you have less than an 8% chance of actually being positive and that in any case, the test doesn’t change the reality of whether or not you are positive!

This kind of confusion leads to people not flying to countries where there has been a terrorist incident but happily driving across country.

It is estimated that after the 9/11 attack, more people lost their lives by choosing to drive when they otherwise would have flown than were killed in the actual attack.

===

[Migrating the best of Quick Bits to my blog – items of interest to Geeks, tagged Quick Bits]

Posted in z Silverlight Archives | Comments Off on Bayesian Probability

Review: Microsoft Web Cam (QB)

My boss sent me a Microsoft High Def Web Cam, (we do a lot of teleconferencing).  CameraDimensions

I admit to being somewhat skeptical initially; I had a web camera, seemed to work fine.  This new camera blew me out of my seat. 

The overall quality was awesome, and the depth of field extraordinaire (so much so that I had re-tilt the camera so as not to show my messy office!)

The built-in digital microphone appears to be good enough that I can use it with my dictation software and eschew my regular headset, which is very nice. 

I’m particularly fond of the WebCam base. It is made of extremely flexible material, and allows me to attach the camera both to my flatscreen monitor and to my laptop with zero difficulty. WebCamBase

 

This really is the best webcam I’ve seen.

 

 

 

A quick note on Quick Bits:LifeCamHD

I tried the experiment of presenting “Quick Bits” (too large for twitter, too small for the blog) on separate pages. After reviewing usage and listening to reader feedback, I’ve decided to reintegrate Quick Bits back into the main Blog, but with the Quick Bits tag so that you can read (or avoid) them as they appear.  I’ll migrate the existing ones that are worth keeping over the next week or so.

 

 

 

 

Posted in z Silverlight Archives | Comments Off on Review: Microsoft Web Cam (QB)

What Makes A How-Do-I Video Great ?

I have been thinking a lot about how differently each of us (inside and out of Microsoft) approaches creating How-Do-I videos.

Let’s start by agreeing that no one instructor will please everyone, and the best way to create truly excellent videos is to step away from ego and try to zero in on what it is that this community values in instructional videos.

Videos

Create A List, Check It Twice

What follows are the characteristics that I look for and pay attention to, both when I’m creating videos and when I’m watching them. 

One of the things that I hope will come out of this posting is a healthy, strong, ongoing discussion about what makes for "good" videos; that is videos that are worth your time to watch.

 

Depends on whether your meaning of “good” is good. 

We can probably all agree that good sound quality is better than poor sound quality, and even agree on whether a given video has good (or good enough) sound quality. We may not all agree on what makes for good pacing – that is,  some people prefer a faster pace, others prefer a more deliberate pace. 

When thinking about these characteristics, we also need to consider the relative importance of any given characteristic. Once again, we can probably all agree that it is very important that the video have sufficiently good audio and video quality to be watchable and understandable, but we may differ in how much value we assign to the length of the video or smooth transitions.

Thus, if we were doing a survey we might want the user to answer paired questions such as: "Do you prefer to see videos that move along more quickly or more deliberately? " and  "How important is the pacing of the video to you?

Instructional Quality

I’ll arbitrarily break instructional quality into

  • Instructional approach
  • Pacing of the material
  • Signal to noise
  • How well a single topic is encapsulated

Instructional approach.

  • Does the presenter approach the topic in a logical fashion?
  • Does the presenter provide "motivation" (that is, what you’re about to learn and why you care)?
  • Is the example sufficiently clean and simple to understand the key point of the video?
  • Is the example sufficiently "mappable" to your own problem domain that you can see how to go from this example to work you might want to do?
  • Does the presenter (A.) ignore best practices, (B.) follow best practices, (C.) violate best practices.
  • Does the presenter used obscure, esoteric, techniques that lead to confusion?
  • Does the presenter skipped over interim steps, leaving you a bit confused?
  • Does the presenter dwell over-much on the obvious?
  • Does it seem that the presenter knows what he or she is talking about?

Pacing

  • Do you find the overall pacing: too slow, too fast, about right?
  • Is the presenter making the right assumptions about what you already know?
  • Is the instructor speaking: too slow, too fast, about right?
  • Is the instructor adding code to the demo: too slow, too fast, about right?

Signal-to-noise ratio

  • What percentage of the video do wish the presenter had edited out?
  • Was this video worth the time to watch it?

Encapsulation

  • Does this video teaching single topic, or does it cover number of related topics?
  • How well do the name and description of the video map to the content?
  • Does this video makes forward references to other videos?

Production Quality And Other Factors

Audio/ Video quality.

  • Is the quality of the video high enough that you can easily see what is being described?
  • Is the quality of the audio high enough that you can easily hear every word?
  • Is the video, unobtrusive (no sudden and unexplained jumps, no dropouts, etc.).
  • Is there anything in the video or audio that is distracting (background noises, instructor chewing, etc.).
  • Did the presenter take the time to make sure that the most important part of the screen is easily visible without making you dizzy with excessive zooming?
  • Does the presenter take the time to add callouts (circles arrows etc.), where that is necessary to understand what the presenters say?
  • Are transitions smooth?

Entertainment/charisma value

  • Is the video: so boring you want to claw your eyes out/ reasonably interesting/ a fair amount of fun?
  • Overall, is the instructor interesting to listen to?

Duration

  • Given the topic, was this video too long, too short, or just about right?
  • Overall be fine if the presenters videos are: too long, too short, or just about right?

Questions For You:

  • What am I missing in this list?
  • Which of these are very important?
  • Which of these are nearly irrelevant?
  • To what extent is all of this secondary to having videos on the right topics?
  • When a new version of Silverlight appears, would you rather see more videos of lower quality, or fewer videos of higher quality?
  • What have you seen in other videos that you wish we would do here?
  • What are we doing in our videos that you wish we would stop?

What?  No survey?

It’s tempting at this point to create a survey based on these questions; but that would presume that I already know what all the right questions are, and more important, that would kill the discussion before it even begins.

While blog comments are not the ideal discussion framework, I invite you please to respond in any way you like; answering one or more questions; adding, deleting or otherwise editing my lists; or just commenting on the overall topic.

Posted in z Silverlight Archives | Comments Off on What Makes A How-Do-I Video Great ?

RIA: Data Source Control

MiniTutorialLogo
ProjectTuringLogo Turing Project Page: [Novice: 11 | Advanced: 8 ]
FAQ | Table of Contents | Definitions
What is this and where do I start?

Part 3 of 3

This is the last of a three part sub-series on using Entity Frameworks and RIA Data Services to move data from our Sql Server database to our Silverlight Application’s DataGrid.

In Part 2, we explored returning an object graph by using the Entity Frameworks and by decorating the metadata for the RIA Services with the properties we wanted to retrieve from the contained object.

Until now, however, all of our code has instantiated via RIA Services context programmatically, invoked the query function programmatically, and assign the returned collection to the items source property of the data grid programmatically. In this post, I’ll look at a declarative approach.

Using the RIA Services DomainDataSource Control

We’ll begin with the program as we left it after the previous blog post, but we’ll immediately remove the three lines in blogs.xaml.cs that manipulates the data context.

   1: public partial class Blogs : Page

   2: {

   3:     //  private readonly BlogsContext bc = new BlogsContext();

   4:   public Blogs()

   5:   {

   6:     InitializeComponent();

   7:     //    bc.Load( bc.GetBlogsQuery() );

   8:     //    this.blogsDataGrid.ItemsSource = bc.Blogs;

   9:   }

Having removed the programmatic interface to the data context, let’s now open up blogs.xaml  and provide it with information about the data context by way of teh DomainDataSource  control, which we must first add to the toolbox. To do so, right-click on the Silverlight Xaml Controls tab, and then click on Choose Items.

Within the Choose Toolbox Items dialog box click on the Silverlight Components tab, and then click the browse button. Navigate to your program files ->Microsoft SDKs -> RIA Services, pick the folder for the latest version, within that:  Libraries-> Silverlight.  Double-click on System.Windows.RIA Controls.dll 

You should find that the DomainDataSource control has been added to the bottom of your list of controls; you may want to right-click and choose to sort them alphabetically.

Drag a DomainDataSource control onto the Xaml page just above the DataGrid.  By dragging it on rather than writing it yourself Visual Studio will create the namespace for you set up your using statement and your references.

The four attributes you’ll typically want to set, if no others, are the Name , LoadSize, QueryName, and the AutoLoad property. We will examine each of these in turn below.

You will also want to set the domain context property which you will do it explicitly as shown in the code that follows:

   1: <riaControls:DomainDataSource x:Name="BlogsDataSource"

   2:                               LoadSize="15"

   3:                               QueryName="GetBlogs"

   4:                               AutoLoad="True">

   5:    <riaControls:DomainDataSource.DomainContext>

   6:       <ds:BlogsContext />

   7:    </riaControls:DomainDataSource.DomainContext>

   8: </riaControls:DomainDataSource>

 

The LoadSize property instructs the DomainDataSource control as to how many records to get for each query to the database.  This allows you to fine tune the performance of your application (too small load size, and you are making many calls to the database, to larg a load size and there will be a noticeable wait for the data to arrive).

The QueryName parameter references the query We created in the RIA Services class, you will remember setting GetBlogs to include bloggers. Notice that here you use the name of the method (GetBlogs ).  Rather than “GetBlogsQuery()” as you did in C#.

Setting Autoload to true tells the DomainDataSource control to load the first set of data when it is initialized.

Note that the namespace for BlogsContext is DS as opposed to RIAControls the namespace for the DomainDataSource.  DS is a namespace that refers to the Web project (you’ll need to add that to the top of the file)

Build and run the application.  The results, that is the running application, are identical to what you had before.  However now you are not creating this programmatically but rather declaratively in the Xaml.

Sorting

Is relatively straightforward to add sorting declaratively as well. You do so by adding a sort descriptor to your DomainDataSource control.  In the case shown below (Lines 9 through 11), we are setting the SortDescriptor property explicitly, and having it sort on BlogName.

 
   1: <riaControls:DomainDataSource x:Name="BlogsDataSource"

   2:                               LoadSize="20"

   3:                               QueryName="GetBlogs"

   4:                               AutoLoad="true">

   5:    <riaControls:DomainDataSource.DomainContext>

   6:       <ds:BlogsContext />

   7:    </riaControls:DomainDataSource.DomainContext>

   8:    <riaControls:DomainDataSource.SortDescriptors>

   9:       <riaData:SortDescriptor PropertyPath="BlogName"

  10:                               Direction="Ascending" />

  11:    </riaControls:DomainDataSource.SortDescriptors>

  12: </riaControls:DomainDataSource>

Sending the sort column in this way it causes the data grid to open with that column sorted.  The user, of course, can sort on any column by clicking on the column header.

Filtering

Before we leave the DomainDataSource control, let’s take a quick look at filtering, which works much like sorting. Sorting the grid In this case rather than explicitly putting into our filter what it is we are filtering on, we will instead set the “Control Parameter” to point to another control on the same page that will provide the text on which to sort.

To begin, we’ll add a text box into which the user can type the desired filter.

<StackPanel Orientation="Horizontal"

            HorizontalAlignment="Right"

            Margin="0,-16,0,0">

   <TextBlock VerticalAlignment="Center"

              Text="Name Contains Filter" />

   <TextBox x:Name="filterText"

            Width="75"

            FontSize="11"

            Margin="4"

            Text="Silverlight" />

</StackPanel>

 

This code can be placed directly above the DomainDataSource, and as you can see it provides a textblock with a prompt and a text box, which will gather in the desired filter. Next We’ll add a FilterDescriptors element to the DomainDataSource control, and tell it to get its value from that text box:

   1: <riaControls:DomainDataSource x:Name="BlogsDataSource"

   2:                               LoadSize="20"

   3:                               QueryName="GetBlogs"

   4:                               AutoLoad="true">

   5:    <riaControls:DomainDataSource.DomainContext>

   6:       <ds:BlogsContext />

   7:    </riaControls:DomainDataSource.DomainContext>

   8:    <riaControls:DomainDataSource.SortDescriptors>

   9:       <riaData:SortDescriptor PropertyPath="BlogName"

  10:                               Direction="Ascending" />

  11:    </riaControls:DomainDataSource.SortDescriptors>

  12:    <riaControls:DomainDataSource.FilterDescriptors>

  13:       <riaData:FilterDescriptorCollection>

  14:          <riaData:FilterDescriptor PropertyPath="BlogName"

  15:                                    Operator="Contains">

  16:             <riaData:ControlParameter ControlName="filterText"

  17:                                       PropertyName="Text"

  18:                                       RefreshEventName="TextChanged" />

  19:          </riaData:FilterDescriptor>

  20:       </riaData:FilterDescriptorCollection>

  21:    </riaControls:DomainDataSource.FilterDescriptors>

  22: </riaControls:DomainDataSource>

 

The filter descriptors begin online 12 and run through line 21.  Notice on lines 14 and 15 that you are indicating which property is being filtered on and that you have your choice of operators such as contains, is, etc.  On lines 16 through 18, you indicate the name of the control that has the filter, the name of the property of the control from which to extract the filter, and the event on which you will update the filter.

N.B.: the code is showing updates each time a letter is typed in the text box.  This will cause a call to the database for every letter that’s typed.  You can solve this by using the Load Delay parameter.  Of course having a low delay will make the page initially load more slowly, so you may want to add the load delay programmatically after you initialize the page.

 

Finally to give it a bit of polish, let’s add a DataPager, just below the DataGrid.  Note that the binding for the DataPager is identical to that for the DataGrid, and that the DataPager retrieves 10 records at a time; we’ll go up so that and change the DomainDataSource load size to 30, so that it will retrieve 3 pages-worth at a time.

<data:DataPager PageSize="10" 

  Source="{Binding Data, ElementName=BlogsDataSource}"  />

 

SortedAndFiltered

 

 
 
 
 
 
 
 
 
 
 
 
 
 
Posted in Mini-Tutorial | Tagged | 1 Comment

Mini-Review of Code Rush

These days I’m very much in the market for anything will cut down on manual typing.  Thus I’m dictating more of what I write (using speech recognition), and today I began to explore CodeRush: a highly extensible Visual Studio plug-in

Being very smart marketers, DevExpress offers a free version: CodeRush Express, which is a somewhat stripped down, but fully useful product, and they offer a 30 day trial of the full CodeRush product. The trial, however, allows you to install both the trial of CodeRush and the free CodeRush Express.  Of course, trying out CodeRush is like driving the turbo enhanced model of the car you want.  Once you do, it’s mighty hard to go back to four unassisted cylinders, and I suspect it will be mighty hard to step down to CodeRush Express.  But stay tuned.

 

Some of what CodeRush does is not immediately intuitive (at least not late at night), but  the documentation is excellent, and includes some surprisingly useful animations.  My biggest complaint is that while they tell you how to do many things, they don’t always tell you why you might want to (hey, does that sound familiar?)  A classic example of this is that you can have "Smart paste" where, for example, you copy “a < b” and when you paste you get “a = b.” This to me was not obviously useful, but I tried it out and the light bulb lit:

if ( theValue < minValue )
{
theValue = minValue;
}
 
To create this I copied the condition, and pasted it as the action, and that was very sweet.

You can of course create your own Smart paste constructs; which I suspect I’ll do quite a bit.

What You See Is What You Will Get

What moved me to write this brief review before fully exploring this product, however, was the following wicked cool experience.  In a bit of sample code I wrote:

public class foo
{
int age;
public foo()
{

}
}

I then used the template expansion for initializing the member variable

InitializeMemberVariable

 

With one click, this initialized the member variable “age” to zero.

MemberInitialized

[highlighting added]

That was really nice, I could see doing that.

I have chosen the option of having a value next to each method indicating its relative complexity (the pale red 5 to the right of the method name) and I’ve asked it to display the architecture of the program by drawing faint lines between connected braces.

 

CodeRush then indicated that there was more that could be done with the member variable age (you may be way ahead of me)

EncapsulateField

 

The three blue dots under the member varaible “age”  Eare CodeRush’s equivalent to a smart tag (this like everything else is configurable) and notice that the re-factor dialog offers two CodeRush refactor options as well as three Visual Studio modifications.

As you would guess, with one click you are able to encapsulate the member variable into a field.  What I find particularly nice is that before committing to the change,  CodeRush shows you what it’s going to do:

 

BeforeSettingTheProperty

 

Note that I’ve done no drawing on this image; everything shown here appears inside the Visual Studio editor, complete with the arrows indicating that the member age will be replaced by the property, etc. 

The graphical preview is enormously useful for making sure that the changes your expect are what you’ll get, and also for learning about new technology (e.g., switching back and forth between anonymous methods and lambda expressions) and for instructing others.

Hints

Immediately upon accepting this change, a blue "hint" indicator appeared, letting me know that CodeRush felt the code could still be improved.  Hovering on the hint opened a box that told me what the issue was, and offered a one click solution

 

IssueIndicator

 

Once again, the change was graphically displayed before I committed to it:

ProposedAutoProperty

Clicking on the link implements:

AfterAcceptingAutoProp

It was all much faster to do then to explain. It was also an entirely pleasant experience, without any opportunity for confusion.

 

It’s early days, but this software looks like a keeper.

Posted in z Silverlight Archives | Comments Off on Mini-Review of Code Rush

Silverlight and Sunday night football

My fascination with Silverlight

Is not strongly determined by the video aspects, though they can be the most immediately compelling.  That said, it is certainly an indicator of the impacted Silverlight is having, that Silverlight was chosen for the online Olympics experience, the online presidential inauguration, and now for the entire season of Sunday night football.

It was announced today that  The NFL and NBC will be delivering the entire Sunday Night Football season utilizing Silverlight 3.0 and IIS Smooth Streaming and that the first game of the opening season will be broadcast tonight with the Tennessee Titans vs. Pittsburg Steelers game starting at 5:30pm PST and can be viewed online for free:

There’s no way to escape that this is a pretty big deal, and it includes a host of extraordinary features including:

 

· A full screen video player that is capable of delivering 720p HD video.

· A main HD video feed, plus 4 user selectable alternate synchronized camera feeds that allows users to switch camera angles themselves.

· Adaptive smooth streaming of live HD video, which enables the video player to automatically switch bitrates on the fly depending on networking/CPU conditions.

· DVR support of the live video, including Pause, Instant Replay, Slow Motion, Skip Forward/Back

· Play-by-play data (touchdowns, fumbles, etc) inserted as tooltip chapter markers on the scrubber at the bottom allowing you to quickly seek to key moments.

· Highlights of major plays created within minutes of the play.

· Live stats in real-time

· live chat with the TV broadcasters

Posted in z Silverlight Archives | 1 Comment

Oops

While we are transitioning to the new design, there are some minor problems with my blog, and so for now I will be dual posting to here (http://SilverlightGeek.me) and to http://geekswithblogs.net/SilverlightGeek 

 

Thank you for your patience.

Posted in z Silverlight Archives | Comments Off on Oops

Project Turing: Multiple Tables & RIA Services

MiniTutorialLogo

ProjectTuringLogo

Turing Project Page: [Novice: 10 | Advanced: 7 ]
FAQ | Table of Contents | Definitions

What is this and where do I start?

In the previous listing in the Project Turing series, I examined extracting data from a single table and displaying it in the DataGrid.  This time we’ll modify the program by including data from related data (the Blog and its author) retrieved from two (joined) tables.

Let’s start by opening the project as it was after the previous posting (source available here). Delete the Data Entity Frameworks and the RIA Services projects by removing the four associated files from the project.

DeleteProjects

Displaying Data From Two Tables In The DataGrid

Return to Blogs.xaml, replace the DataGrid with the following code

<data:DataGrid x:Name="BlogsDataGrid"
               MinHeight="150"
               IsReadOnly="True"
               AutoGenerateColumns="False" >
   <data:DataGrid.Columns>
      <data:DataGridTextColumn x:Name="BlogName"
                               Binding="{Binding BlogName}"
                               Header="Blog Name" />
      <data:DataGridTextColumn x:Name="BlogURL"
                               Binding="{Binding BlogURL}"
                               Header="URL" />
      <data:DataGridTextColumn x:Name="First"
                               Binding="{Binding First}"
                               Header="First Name" />
      <data:DataGridTextColumn x:Name="Last"
                               Binding="{Binding Last}"
                               Header="Last Name" />
      <data:DataGridTextColumn x:Name="Email"
                               Binding="{Binding Email}"
                               Header="Email" />
      <data:DataGridTextColumn x:Name="Phone"
                               Binding="{Binding Phone}"
                               Header="Phone" />
   </data:DataGrid.Columns>
</data:DataGrid>

Obtaining The Object Graph

The two most common ways to obtain the data from joined tables is to delegate that responsibility either to the database, by creating the view, or by using the ability of the Data Entity Framework to return the entire object graph.

Remember that our database design creates a one to many relationship between Bloggers (one) and their Blogs (many). This is reflected in the database diagram, and will be reflected in our Data Entity Model by having each Blog object contain a Blogger object.

As you did previously, right-click on the web project choose add new, select the data, select ADO.net Entity Data Model and mean the new model Blogs.emdx.

As you did previously, indicate that you want to build your model from the database, choose the appropriate connection string, click okay and in the Entity Data Model Wizard expand and choose both the Blogs and the Bloggers table. Name the Blogs model and click on the finish button.

It is instructive to compare side-by-side the SQL Server diagram of the tables and the Data Entity Model you just created, as shown in the next illustration with the Data Entity objects on the bottom

RelationalAndObject

In this case, because of the simplicity of the design, there is an isomorphic mapping from the relational database tables to the data objects. It is important to note that this need not be true, and that a given data object may be composed from numerous tables, and may contain a subset or superset or a composite of the values stored in the database.

In this case, the most important thing brought forward into the data object model is the one to many relationship between Bloggers and Blogs. This is manifested in the Blogs class by the navigation property Bloggers, which serves as a reference to all of the Bloggers who own this Blog (by design that will always be one object as in our design while one Blogger may own many Blogs, each Blog is owned by a single Blogger)

The key point, is that when we retrieve the Blog, we can instruct the data model either to return a reference to each Blogs Blogger, or, via containment, to return each logger object within each Blog object.

In this case, so that we can display information in the data grid about both the Blog and the Bloggers, rather than thinking about joining the tables as a database programmer might, we will instruct the data Entity Frameworks to return the object graph: that is to return each Blog will have its Blogger via containment.

Using attributes in the metadata

To accomplish this, first build the web project so that your new data model will be available. Next right-click on the project and choose add new, in the Categories choose Web, and in the templates area choose Domain Service Class.

Give it the name Blog service and click the add button, and in the Add New Domains Service Class dialogue be sure to check all of the checkboxes before pressing okay.

The RIA Services framework will generate both the Blogs service and a file with its metadata. Open the metadata file where you will find classes representing the Bloggers metadata and the Blogs metadata. The last few lines of the Blogs metadata class represents the public properties the first of which is of type Bloggers. You will need to decorate that property with the include attribute to indicate which fields you want included in to the Blogs class from the Bloggers object as shown in the next snippet of code

[Include( "alias", "Email" ), Include( "FirstName", "First" )]

[Include( "LastName", "Last" ), Include( "phone", "Phone" )]

C#

public Bloggers Bloggers

VB.Net

public Bloggers as Bloggers

Notice that I am including four fields: alias, FirstName, LastName, and phone, and while I’m at it I am indicating that alias should be returned as “Email,” FirstName as “First,” LastName as “Last,” and phone with a lowercase P. as Phone with an P.

Having indicated in the metadata what fields of Bloggers to return, I now must modify the get Blogs query to ensure that Bloggers are returned as entities rather than references. To do so open the BlogsService.cs file and navigate to the GetBlogs method, which you will modify as indicated in the next listing

C#

public IQueryable<BLOGS> GetBlogs()
{
     return this.Context.Blogs.Include("Bloggers" );
}

VB.NET

Public Function GetBlogs() As IQueryable(Of Blogs)
     Return Me.Context.Blogs.Include("Bloggers")
End Function
Be sure to rebuild the project. Note, you may have to temporarily comment out the BlogsService lines in Blogs.xaml.cs)

Modifying Blogs.xaml

Return to Blogs.xaml.cs and make sure that the context there is named BlogsContext or change it to be so. In any case the logic is unchanged from the previous version:, we will instantiate a BlogsContext object, use that to load the results of our now modified GetBlogs query, and assign the results to the DataGrid’s ItemsSource property:

C#

private readonly BlogsContext bc = new BlogsContext();
  public Blogs()
   InitializeComponent();
   bc.Load( bc.GetBlogsQuery() );
  this.blogsDataGrid.ItemsSource = bc.Blogs;

VB.Net

Private ReadOnly bc As New BlogsContext()
  public Blogs() InitializeComponent()
   bc.Load(bc.GetBlogsQuery())
  Me.blogsDataGrid.ItemsSource = bc.Blogs

Build and run the application

MultiTableRunning

(Click on image to enlarge)

This entire post was dictated and translated by computer; apologies in advance for any resulting absurdities.

Completed Code    DataBase Backup

Novice Previous:  Ria Services Part 1 Next: Domain Data Source Control
Advanced Previous:  Ria Services Part 1 Next:  Domain Data Source Control
Posted in Mini-Tutorial, z Silverlight Archives | Tagged , | 2 Comments

Complexity Isn’t Simple

It is very rare for me to respond to comments in follow-on blog post, in fact I don’t think I’ve ever done so before. However the response to my previous blog entry about Dot Net Rocks show number 476 was so overwhelming, and so many good points were made, that I couldn’t resist having another go at some of these issues.

Center of Attention

N.B.: I’ve taken the liberty™ of paraphrasing user comments.  The original comments can be seen here.

Too Much To Keep Up With?

Nate Jackson wrote that he felt, even as a seasoned developer, that the pace at which technology is coming out of Microsoft is too fast for him to reasonably keep up with or even use to provide context for future projects.

My response is that I don’t disagree that with so many new technologies it’s terribly difficult to keep up. Rather, my position is that I’d rather live in a world where there are constantly improving technologies and run the risk of feeling that I’m falling behind then live in either of the alternative worlds: the one where we forgo rapid technology improvement, or the one in which we prematurely deprecate technology that developers are still using.

Rapid Deprecation?

Guerchele objected that if we continued to advance the technology without deprecating,  we wii inevitably end up with too many technologies. He rejected my idea of a “gizmo” because it does not enforce adoption of the latest technology for new projects

While I embrace the evolution of development technology, the solution cannot be to “forbid” the use of platforms we released only a few years ago. While it is in my own experience that applications that would’ve taken me months or even years to finish with the technology available five years ago can today be completed in months while providing a more robust and better UI, I have to also recognize that other developers do not necessarily feel the need to move from the technology with which they’re most comfortable.

And it may well be that for them the opportunity cost of forgoing the potential in the new technology is outweighed by the benefit of not having to take the time to make that move,  given that they’re already fully productive in a technology they know.

No, actually  that’s a lie. If the truth were known, my actual opinion is that the anticipated cost of adopting a new technology is over-estimated by those who feel this way (and under-estimated, I suppose by people like me!); and the real world gains of moving to a new technology like Silverlight are in fact far higher than might be anticipated. But I really do understand that many developers disagree with me.

Full Projects Please

rickj1 wrote that our training and material has suffered from a lack of a “full-featured step-by-step end to end real world tutorial.” I fully agree, which is why I find the touring project very satisfying, though I think it’s extremely important to put each component into context and also to point out a generalized set of uses that transcend any individual project.

Note to rickj1, every part of project touring will be fully annotated and all the source code will be available as we move forward.

Others have commented, and once again I agree, that my tutorials and videos would be improved by providing more motivation for each technique; that is,  “don’t just show me how to do something, tell me when I might want to do it.”

A Few Words From Josh

“Nitwit! Blubber! Oddment! Tweak!” – A.D.

Josh Holmes, RIA evangelist for Microsoft, who was on the original panel, made the following points in a private correspondence(which he has permitted me to copy here):

You’re right, we can’t support the extraordinary train of technologies including everything from Access 3 to.NET 4.0….My biggest frustration with the show was that we never really defined “Complexity” and who things were complex for. I think I tried to make the point at least once that things were getting simpler to create for professional programmers but harder and harder for non-programmers (the so-called hobbyist). Even with the Getting Started posts and the like, you have to be a technologist to write an application these days with Microsoft technologies. This is one of many reasons that we are losing share to technologies such as PHP.

While I agree that we are not fully serving the needs of the so-called hobbyist — and parenthetically if we mean by that people who program but for whom programming is not their day job, then I think we need a different term; Programming Artisan comes to mind — I’m not sure there is anything like universal agreement that things are getting simpler for professional programmers.

There’s no doubt that with the latest technology, once mastered, we can do things more quickly, better, more simply than we could just a few years ago, however you have to factor into that equation the cost of learning the new technology, and the perceived “complexity” of myriad overlapping choices.

As to the hobbyist, or even the technologist attempting to transfer to .Net,there is no doubt that the learning curve has grown, if not steeper, then at least longer. That said, we all remember how much of the plumbing we used to write, and  few of us want to back.

Josh continues,  The second part of complexity that we never covered is that the software that we build is far too complex for our users. We have all of the opportunity to do something amazing but there are few firms that do. Silverlight and WPF are enabling technologies but unless the devs and designers really push it to its limits, my grandma still can’t use her applications…

It is certainly true that we are a long way from software that is as easy to use as a toaster, but that has been true for a very long time. I would argue that it was worse in the so-called “good old days” before things got so “complex.”  In fact, I would argue, we are slowly learning how to make software that is more intuitive, easier-to-use out-of-the-box, and that appeals to a broader audience. While we absolutely have a long way to go, I don’t think we should lose sight of the enormous strides that have been made towards more intuitive interfaces in products both from within Microsoft and from numerous other software vendors.

The bottom line for me is that the overall experience of being a programmer requires that you know more than was needed when I started, but that’s because we’re being asked to build much better products. And given that, I’d far rather have today’s tools than the tools I had in the 1980s.

Please note, this post was produced through dictation; my apologies for any absurdities. It turns out that carpal tunnel syndrome is a whole lot less fun than you might expect.

-jesse

Posted in z Silverlight Archives | Comments Off on Complexity Isn’t Simple