Scott Hanselman

The Weekly Source Code 34 - The Rise of F#

September 25, '08 Comments [14] Posted in Source Code
Sponsored By

First, let me remind you that in my new ongoing quest to read source code to be a better developer, Dear Reader, I present to you thirty-fourth in a infinite number of posts of "The Weekly Source Code."

F#, everyone is agog over F# and getting all functional. Again. ;) The F# September 2008 CTP came out a few weeks back and folks I'm talking to are digging it. Here's the goal:

"F# developed as a research programming language to provide the much sought-after combination of type safety, succinctness, performance, expressivity and scripting, with all the advantages of running on a high-quality, well-supported modern runtime system."

Looks like it's more than a research language as it's inside Visual Studio and looking pretty with syntax highlighting and intellisense and everything. This might be old news to you, Dear Reader, but F# is reaching a very significant level of polish. This release is moving F# to the level of being a peer of C# and VB. It's got its own F# DevCenter at MSDN. How's that for legit?

Here's a great one paragraph explanation from Vertigo's Rick Taylor about what/why/how F#:

"Unless you specify otherwise, everything in F# is immutable, much like the string construct in C#. This extends to areas that you might not expect. For instance, once you set an int to some specific value, that's it – you can't change it, unless you have marked it as mutable. The reason for this is because the language is primarily a functional one. Programs in functional languages contain functions which return values, which are then further used, etc – but each value or set of values is its own entity, and to change it while within a function is to produce a side effect, something undesirable in a functional language. In the strictest sense, functions return values but do not alter their parameters, or the outside world (which, incidentally, gives rise to the monad pattern mentioned earlier). F# follows these rules of functional programming, but also allows you to break those rules with the mutable keyword."

What's the best way to jump into F#? Well there's a few great ways. First, a little blatant self-promotion. I've done two F# podcasts with smart F# fanboys and there's great .NET Rocks and Herding Code episodes too.

Books

  • I enjoyed Robert's "Foundations of F#" book very much.
  • Also, if you're a freaking ninja rocket scientist, you can always read "F# for Scientists." Seriously. I dare you to buy that, in person, at Borders. Freaking scientists. (Seriously, though, it's a fabulous book and you can get some free excerpts here)
  • Don Syme, the creator of F# has "Expert F#" available and it's very highly rated.
F# Blogs

Code

F# Eye for the C# Guy

However, as a F# newbie with a few years of Haskell in the back of my head, the presentation that has clicked with me the most was Leon's F# eye for the C# guy PowerPoint. Scandalous, I know, as you may know Leon as the cruel bully who called me Hanselgirl in public recently at TechEd Australia. I promptly boxed his ears (it was more of a slap-fight actually) and there was also a public arm-wrestling. Between the two of us I'm sure there was the potential to splice together one normal-sized male arm, but I digress. You can download his deck here, but I've also taken the liberty to put it on SlideShare and embedded it here.

F# Eye for the C# Guy
View SlideShare presentation or Upload your own. (tags: f# c#)

I had intellectualized slides 42 through 45, but the way he described it clicked. He did what I would do:

"I worked this out using Reflector. I did not work this out from reading books or papers or listening to podcasts or quizzing intelligent people. A simple let statement is a static function, under the hood. When you see let, think function."

Check out those few slides,. It's a great deck, and I'm sure Leon wouldn't mind YOU, Dear Reader, showing his talk at your local User Group or having a Programmer's Lunch at work and taking complete credit for it. That's what I fully plan on doing. ;) Suck it Bambrick!*

Let's see three bits of code.

First, something basic.

Remember there are no variables. No side-effects.

#light

let sqr x = x * x
let multiply x y = x * y

print_int (sqr 3)
print_int (multiply 3 4)

// recursive function fibonacci series using pattern matching
let rec fib x =
match x with
| x when x <= 0 -> failwith "An integer greater than 0 is required."
| 1 -> 1
| 2 -> 1
| x -> fib (x - 1) + fib (x - 2)

print_int (fib 15)

// functions as values
let add x y = x + y
let a1 = add 3
let a2 = a1 4

print_int a2

Second, something shiny.

Units of Measure in F#. What? Andrew Kennedy's PhD thesis from 13 years ago just happens to be a feature in F#. He's done a three part series:

Basically they've added static checking and inferences for units-of-measure. Not any specific ones, but the concept itself.

"As far as F# is concerned, ft and m have nothing to do with each other. It's up to you, the programmer, to define appropriate conversion factors."

Here's a screenshot from his blog that says a thousand words and showcases the FSharp.Math.PhysicalConstants namespace, along with the International System of Units (SI) namespace.

image

Also from Andrew's blog:

"You can define mutually recursive measures using "and" to connect them and placing the Measure attribute immediately before the name of the measure:"

type [<Measure>] km = 
static member toM = 1.0/1000.0<m/km>
and [<Measure>] m =
static member toKm = 1000.0<km/m>

Third, something silly.

A fun little 2D Tron-Clone game from last year, written in only 182 lines of F# by Phil Trelford. You can download it from hubFS and read how he wrote it on the Applied Games Group Blog. The game even supports Xbox 360 controllers! Sweet.

image

Here's all 182 lines, not counting the first 4 lines of comments.

//-----------------------------------------------------------------------------
// LightCycles.fs Mini game using windows forms
// 2007 written by Phillip Trelford
//-----------------------------------------------------------------------------

#light

#if DIRECTX
#R @"C:\WINDOWS\assembly\GAC_32\Microsoft.DirectX\2.0.0.0__31bf3856ad364e35\Microsoft.DirectX.dll" // Feb 206
open Microsoft.DirectX.XInput // Required to read XBox 360 controllers
#endif

open System
open System.Drawing
open System.Windows.Forms

/// Game states
type GameState = | Start | Play | Over

/// Form key handler type
type KeyHandler (form:Form) =
do form.KeyPreview <- true
let keys = Enum.GetValues (type Keys) :?> (Keys [])
let keysDown = Array.create keys.Length false
let FindKeyIndex code = keys |> Array.find_index (fun x -> code = x)
do form.KeyDown.Add (fun e -> keysDown.[FindKeyIndex e.KeyCode] <- true)
do form.KeyUp.Add (fun e -> keysDown.[FindKeyIndex e.KeyCode] <- false)
member this.IsKeyDown (keyCode:Keys) = keysDown.[FindKeyIndex keyCode]
member this.AnyKeyDown () = keysDown |> Array.exists (fun x -> x)

/// Player direction type
type Direction = | Left | Right | Up | Down

/// Player type
type Player (color,startX,startY,direction,keys,keyHandler:KeyHandler) =
let mutable x = startX
let mutable y = startY
let mutable d = direction

member this.Color = color
member this.X = x
member this.Y = y
member this.Keys = keys

/// Reset player to start values
member this.Reset () = x <- startX; y <- startY; d <- direction

/// Updates player position
member this.Update i =
// Read keyborad
let mutable newD = d
let up, down, left, right = keys
if keyHandler.IsKeyDown(up) then newD <- Up
if keyHandler.IsKeyDown(down) then newD <- Down
if keyHandler.IsKeyDown(left) then newD <- Left
if keyHandler.IsKeyDown(right) then newD <- Right
#if DIRECTX
// Read XBox 360 controller
let state = Controller.GetState(i)
if state.IsConnected then
let pad = state.GamePad
if pad.UpButton then newD <- Up
if pad.DownButton then newD <- Down
if pad.LeftButton then newD <- Left
if pad.RightButton then newD <- Right
#endif
/// Don't allow suicide move
match (d,newD) with
| (Left, Right) | (Right, Left) | (Up, Down) | (Down, Up) -> ()
| _ -> d <- newD
/// Update position with direction
match d with
| Up -> y <- y - 1
| Down -> y <- y + 1
| Left -> x <- x - 1
| Right -> x <- x + 1

/// Main form
let form = new Form (Text="Light Cycles", Width=680, Height=544)

do /// Layout for game window and status panel
let layout = new TableLayoutPanel(Dock=DockStyle.Fill, ColumnCount = 2)
layout.ColumnStyles.Add( ColumnStyle(SizeType = SizeType.Percent, Width = 100.0f ) ) |> ignore
layout.ColumnStyles.Add( ColumnStyle(SizeType = SizeType.Absolute, Width = 128.0f) ) |> ignore
/// Play area in pixels
let playArea = 500
/// Game play area bitmap
let bm = new Bitmap(playArea, playArea)
/// Clears screen
let ClearScreen () =
using (Graphics.FromImage(bm)) (fun graphics -> graphics.Clear(Color.Black))
/// Draws text to screen
let DrawText s =
using (Graphics.FromImage(bm)) (fun graphics ->
let rect = new RectangleF(0.0f,0.0f,float32 playArea,float32 playArea)
let align = new StringFormat(Alignment=StringAlignment.Center, LineAlignment=StringAlignment.Center)
graphics.DrawString(s, form.Font, Brushes.White, rect, align)
)
// Initialise screen
ClearScreen ()
DrawText "Press any key to start"
/// PictureBox to contain game bitmap
let pictureBox = new PictureBox(Dock=DockStyle.Fill)
pictureBox.Image <- bm
layout.Controls.Add(pictureBox)

let keyHandler = KeyHandler (form)

/// Players array
let players =
[| Player (Color.Red,playArea/2+20,playArea/2,Down,(Keys.Q,Keys.A,Keys.Z,Keys.X),keyHandler);
Player (Color.LightBlue,playArea/2-20,playArea/2,Up,(Keys.P,Keys.L,Keys.N,Keys.M),keyHandler) |]
players |> Array.iter (fun player -> bm.SetPixel(player.X,player.Y,player.Color))

/// Display player controls
let statusPanel = new TableLayoutPanel(Dock=DockStyle.Fill, ColumnCount=1, BackColor=Color.DarkGray)
players |> Array.iteri (fun i player ->
let name =
[| ((new Label (Text=sprintf "Player %d" i, ForeColor=player.Color)) :> Control) |]
let up, down, left, right = player.Keys
let controls =
Array.combine [|"Up";"Down";"Left";"Right"|] [|up;down;left;right|]
|> Array.map (fun (name,key) -> (new Label (Text=sprintf "%s '%O'" name key)) :> Control )
Array.append name controls
|> statusPanel.Controls.AddRange
)
layout.Controls.Add(statusPanel)
form.Controls.Add(layout)

/// Game play - returns true if there has been a collision otherwise false
let PlayGame () =
let collisions = players |> Array.mapi (fun i player ->
player.Update i
let x, y = (player.X, player.Y)
let wall = x < 0 || x >= playArea || y < 0 || y >= playArea
if wall then
true
else
let bgColor = bm.GetPixel(x, y)
bm.SetPixel (x, y, player.Color)
players |> Array.exists (fun player -> let c = player.Color in c.R = bgColor.R && c.G = bgColor.G && c.B = bgColor.B )
)
pictureBox.Refresh ()

match collisions |> Array.tryfind_index (fun x -> x = true) with
| Some(i) -> i
| None -> (-1)

/// Current game state
let gameState = ref GameState.Start
let gameOverWaitCount = ref 200
let r = new Random()

/// Timer instance
let timer = new Timer()
timer.Interval <- 1000/50
// Timer event
timer.Tick.Add (fun _ ->
match !gameState with
| Start ->
if keyHandler.AnyKeyDown () then
ClearScreen ()
gameState := GameState.Play

| Play ->
let i = PlayGame ()
if i>=0 then
gameState := GameState.Over
gameOverWaitCount := 200
DrawText (sprintf "Game Over - Play %d Lost" i)
pictureBox.Refresh ()
| Over ->
// Shake screen
form.Left <- form.Left + if !gameOverWaitCount > 150 then r.Next(5) - 2 else 0
// Decrement Game Over wait
decr gameOverWaitCount
if !gameOverWaitCount <= 0 then
gameState := GameState.Start
players |> Array.iter (fun player -> player.Reset ())
ClearScreen ()
DrawText "Press any key to start"
pictureBox.Refresh ()
)
timer.Start ()

[<STAThread>]
do Application.Run(form)

Try to learn ONE new language each year!

Related Posts

* Oh, relax, Dear Reader. Leon and I are, like, totally, BFF. We're peas and carrots. Truly. The bastard.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Update on .NET Framework 3.5 SP1 and Windows Update

September 23, '08 Comments [53] Posted in ASP.NET | ASP.NET Dynamic Data | Bugs | Programming | Windows Client
Sponsored By

The .NET Framework 3.5 SP1 included a bunch of new features, but as a Service Pack it also included a number of bug fixes and many improvements. These fixes included all aspects of the .NET Framework from ASP.NET to WPF and the CLR.

Will the .NET Framework 3.5 SP1 break my 2.0 apps?

Almost certainly not.

Why Not?

Remember that 3.5 (and 3.0 before it) all have the 2.0 CLR at their core. If you want excessive detail on this, I've got it. Because the 2.0 CLR is the engine underneath and 3.0 and 3.5 are primarily additive*, there's inherently high application compatibility between these releases.

Realize that 2.0, 3.0 and 3.5 are not different products, no matter what anyone says. They are not different "Side By Side" releases, like 1.x and 2.0 were. They are evolutionary; if anything, our naming could have been better (you think?), but rather each adds functionality to the one before it. They are really additive releases to the same core product.

But, I've hit an edge case…

We’re committed to application compatibility. However you may have heard or reported issues or bugs around 3.5 SP1 and I’ll go into how we’re dealing with those below. Most of these are corner-case/edge-case situations.

It may be cold comfort when it’s your bug and your company and it sounds like a marketing line, but it’s true. There are a lot of resources working to minimize impact to you.

I’ve now been on both sides, when working in a large ISV and trying to get a hotfix, and now on the inside trying to keep compatibility while keeping things secure and correct. There is a massive amount of unit and integration testing that goes into the .NET Framework (that includes all technologies under that umbrella).  That means that every effort is made not to break stuff. That’s why Visicalc still runs nicely on my Vista x86 machine (although I can’t run OS 9 apps on OS X anymore, interestingly ;) ) 

Software testing is a combinatorial problem, and as such all software has bugs, but sometimes when a bug comes back it’s called a “regression.” That means it was fixed before, and now it doesn’t. Sometimes folks call a new bug a regression their software worked before and it doesn’t now. This might be because they relied on an incorrect behavior that was later corrected, or that it was just a bug.

It IS possible that something could break, so as with all SP’s you should do compatibility testing to make sure you’re not hitting an edge case.  If you are affected by a bug at some point, we’re trying to get you a very fast response. Notice in the table below there’s a “How Found” column. You can report on Forums, contact PSS or use Connect to report bugs.

When will the .NET Framework 3.5 SP1 be pushed to Windows Update?

Later this year, probably November-ish, the .NET Framework 3.5 SP1 will begin show up on Windows Update in a rolling and throttled fashion so that all machines that have .NET 2.0 or higher will be automatically upgraded to 3.5 SP1.

If you’re an ISV or Hoster, you might be concerned that you’d wake up one day and find machines updated to 3.5 SP1 via Windows Update before these bugs are fixed.

There will be an update/patch made to .NET 3.5 SP1 before it goes live on Windows Update. We are holding SP1 on Windows Update (Microsofties call it “WU” or “Woo”) until this patch is finalized. 

That patch is called a GDR, or General Distribution Release, coming for .NET 3.5 SP1. A GDR is a Microsoft TLA (Three Letter Acronym) for an update that is for everyone. This update’s goal is to fix bugs that have been found in .NET 3.5 SP1. Many of these bugs were found by the community and reported on the Connect site.

We won’t push .NET 3.5 SP1 to WU until everyone feels confident it’s solid.

I know if you have a particular bug on Connect that you’re watching, you might be a little frustrated and be wondering what its status is. We’re working on getting the Connect Bugs updated and lots of folks (myself included) are trying at every turn to increase transparency. This blog post is an example. If they stop abruptly, I’ve finally been fired for them. ;)

Transparency

Sometimes your app might break and the issue isn’t “fixed,” but closed with “By Design” or “Workaround.” This can be frustrating (believe me, I know) but some fixes can break other things, and there’s always security to consider. In the near future I’m going to try to dig into some really icky details of a few of the more interesting bugs and get some color commentary on them. I’m going to encourage the other teams to do the same. I know the BCL team had a few interesting issues and have expressed an interested in digging in and blogging some wonky technical details.

If you don’t want a bunch of details, you can stop reading now.

Wonky Technical Details

In the interested on transparency, here’s some of the bugs I’m tracking for this GDR. Note you can find most, if not all, of these bugs/issues on Connect and each team will be updating those with as much details as they have. Watch the issues there for the most up-to-date information we've got. If you feel something isn't getting attention, let me know and I'll poke the right manager.

Title

Product Unit

Details

How Found

.NET 3.5 issue - Dynamic Data Issue

ASP.NET

Dynamic Data fails on Entity Framework data models that contain 1->0..1 and *->1 database relations with an error like "'System.Web.UI.WebControls.EntityDataSourceWrapper' does not contain a property with the name 'Orders.OrderID'". These types of relationships occur in many databases including Northwind and AdventureWorks.

The error is caused by a naming mismatch that Dynamic Data has with the wrapper objects being returned by the EntityDataSource. We have a temporary fix available at: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16367 which replaces the data model provider with one that names the properties correctly.

3rd party Forum

Hidden files/folders inside App_Browsers are not ignored

ASP.NET

This customer applied FrontPage Server Extensions (FPSE) to the site.  Normal behavior is to add metadata files inside _vti_cnf folders for each file in the site.  Therefore, inside App_Browsers folder, after applying FPSE, we get a hidden folder called _vti_cnf that contains the file called BrowserFile.browser
Trying to parse that file will result in this error, since this is not a real .browser file, but instead just a metadata file.

The workaround for now is to delete _vti_cnf folder, but we'll fix this.

PSS DTS Issue

After installing .NET 3.5 SP1, a web site using a derived version of the UpdateProgress control may encounter the following exception: “A ProgressTemplate must be specified on UpdateProgress control with ID ‘id’.”

ASP.NET

In the .NET Framework 3.5, the UpdateProgress control enforced the requirement of a ProgressTemplate from its PreRender routine. A derived UpdateProgress control could subvert that requirement by overriding OnPreRender in the derived control, and avoiding calling base.OnPreRender. In the .NET Framework 3.5 SP1, the UpdateProgress control now uses CreateChildControls to instantiate the ProgressTemplate, causing the requirement to be enforced at a different point in the page life cycle, and preventing the OnPreRender technique from subverting the check.

Other

SGEN and Obsolete attribute

WCF

ASMX web methods do not return serialized results. What the customer does is to SGEN an assembly that contains some types with [Obsolete(IsError = true)].  What he sees is SGEN throwing an error and  refusing to generate a serialization assembly. 

Here is the message you get from SGEN:
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.1432]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: Unable to generate a temporary class (result=1).
error CS0619: 'SGenTest.Program' is obsolete: ‘Testing.'
error CS0619: 'SGenTest.Program' is obsolete: 'Testing.'

Other

.NET 3.5 SP1: JIT generates incorrect code in managed C++ edge case

CLR

This is caused by JIT optimization changes we made in 3.5SP1. We promote some fields to registers when we shouldn't. Limited to structs or classes with four or fewer scalar fields, none of which are managed object references.The scope is additionally reduced in that this bug only manifests when using the cpblk or initblk instructions, which are only emitted by the managed C++ compiler.The issue does apply to both JITted and NGEN'd code.

MSConnect

Obfuscated 1.1 assemblies may fail if they override certain methods in the Framework

CLR

1.1 code that used to run successfully on 2.0 will no longer run on 3.5 SP1 (throws a MissingMethodException).

The underlying problem is as follows. Let’s say you have a 1.1 Framework type that overrode a virtual method, then stopped overriding it in 2.0. This should not be a breaking change, because an implementation of the method still exists (somewhere earlier in the inheritance hierarchy). However, if a customer overrode that method, built against 1.1, then obfuscated the code, the obfuscated code no longer works when run against 2.0 SP2/3.5 SP1.

Obfuscators that are using undocumented techniques to accomplish their task tend to get broken when we optimize things. Workaround is to not obfuscate these few methods, usually by marking them with an attribute. Long term workaround is for the obfuscator to play nice.

3rd party Forum

How .Net 3.5 SP1 broke Rhino Mocks (ExecutionEngineException...)

CLR

This bug has been reported to break Rhino Mocks, an open-source, mock testing framework.The specific impact to Rhino Mocks is that it breaks its support for F#, C++ and Spec# It has 71 validations and 119 ratings (avg. 4.9), which is high for a Connect bug
http://www.ayende.com/Blog/archive/2008/08/13/How-.Net-3.5-SP1-broke-Rhino-Mocks.aspx is the blog which discusses the issue with many community comments This is likely the source of much of the validations.

In 3.5 SP1 we removed a null check as a side-effect of changes we made to support ASLR. As a result, a failure case we used to handle now results in an AV in the runtime which manifests as an ExecutionEngineException and process termination

MSConnect

Serialization hangs or throws an OutOfMemoryException

CLR

This issue is also mentioned on the Rhino Mocks web site, where another breaking change in 3.5SP1 was reported. It is unclear as to whether or not this issue also breaks Rhino Mocks test software.

Due to changes in the type system, types with the following criteria:Generic type instantiated with a reference typeImplements ISerializableContains a static field.

MSConnect

AutoCommit behavior change in Oracle Transactions in .Net Framework 2.0 SP2

DPR

Existing applications which rely on transaction behavior to work correctly will break causing data corruption.

MSConnect

EntityDataSource runtime: Not able to display Dynamic Data's FK Ids in a 1:0..1 relationship

DPR

This breaks web sites/applications created with ASP.NET Dynamic Data because Dynamic Data assumes the property descriptors exist and uses them to obtain labels for their links. The only known workaround requires manually editing Dynamic Data's templates (for wich each site/app has private copies) to capture the exception. The exception generally of the form:
[HttpException (0x80004005): DataBinding: 'System.Web.UI.WebControls.EntityDataSourceWrapper' does not contain a property with the name 'Manager'.]

3rd party Forum

SaveChanges doesn't support inserting an entity and binding as a single operation

DPR

If the resource takes part in a relationship (e.g. 1:1), then while inserting a new instance of the resource, we need to send the link also, since the link is required at the database level. The client does not send the links while inserting such resources

3rd party Forum

DataServiceContext: DeleteObject on an entity with a link fails

DPR

This impacts deletion of any resource which has reference properties.

A link for a reference property should never be in Added or Deleted state. Instead, it should always be modified with reference target to null in case of delete/non-null in case of add/update.

3rd party Forum

.NET 3.5 SP1 breaks use of WPF under IIS

WPF

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361469

MSConnect

Relative Hyperlinks inside XPS documents broken and causes app to Crash

WPF

Fixed.

MSConnect

Regression: Geometry.Combine creates more points/segments than before in 3.5 sp1

WPF

Performance regression in scenarios with Geometry (drawn shapes).

Other

Related Posts

* Remember, if you're running around edge cases and are concerned, you can happily target 2.0 and 3.0 from VS2008 and use a CodeAnalysis Rule to make sure you're only calling methods for your targeted framework.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcasts 130 - JavaScript gets Faster: Brendan Eich, CTO of Mozilla Corporation and Creator of JavaScript

September 21, '08 Comments [8] Posted in ASP.NET | ASP.NET MVC | Javascript | Podcast
Sponsored By

ImageBEich.jpg My one-hundred-and-thirtieth podcast is up. I had the pleasure of talking to Brendan Eich about JavaScript this week. Brendan created JavaScript lo these many years ago, and lately his team has been working to make JavaScript even faster with TraceMonkey, their next step in their JavaScript engine. It's an exciting time for JavaScript as it approaches "C" speeds. I chat with Brendan in this episode about where he thinks JavaScript is headed. What does the rise of JavaScript mean to Flash, Silverlight and RIAs in general? We also talk about how TraceMonkey works and how much faster it can get.

Brendan is responsible for architecture and the technical direction of Mozilla. He is charged with authorizing module owners, owning architectural issues of the source base and writing the roadmapthat outlines the direction of the Mozilla project.

Brendan created JavaScript, did the work through Navigator 4.0, and helped carry it through international standardization. Before Netscape, he wrote operating system and network code for SGI; and at MicroUnity, wrote micro-kernel and DSP code, and did the first MIPS R4K port of gcc, the GNU C compiler.

One other change, this week a large number of the questions of Brendan came directly from you, the listener, via Twitter! This is a new thing I'm trying and I really feel it made for a better show and I thank you for it! I'm on Twitter at http://www.twitter.com/shanselman and you can read more about Twitter in my post on Twitter: The Uselessfulness of Micro-blogging if you want to jump in and "follow me." I encourage you to find a Twitter Client that works for you and give it a try.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes 

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show!

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET and Windows Forms. Enjoy the versatility of our new-generation Reporting Tool. Dive into our online community. Visit www.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

Technorati Tags: ,,

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Working Remotely from Home, Telepresence and Video Conferencing: One Year Later

September 20, '08 Comments [24] Posted in Microsoft | Musings | Remote Work
Sponsored By

Microsoft RoundTable Had my one year review at work last week. I met with my boss for an hour and we talked about what I was doing well and what I was doing poorly. I talk to him face to face a few times a week using video conferencing. I also have a mentor at Microsoft who helps me navigate the maze. He didn't have a web camera so I just had one sent to him so that it showed up on his desk one morning. I probably do two or three videos calls per day now.

LiveMeeting - Big Conference Room Meetings

I had a meeting this morning with six manager-types in a conference room and I finally felt like I was contributing and could be heard. I hate doing conference calls these days. You can't be heard, you're constantly asking "who is speaking?"

In the meeting today we used a Microsoft Roundtable for the meeting. In the last ten meetings I've asked all ten organizers to book a room with a Roundtable. Only two have. The belief is that it's hard to hook up, "I've never used it before," or just "I'll see what can we can do," then nothing.

They are SO easy to use. Literally you plug it into your laptop and start a LiveMeeting. That's it. The drivers were already included with Live Meeting so there's literally no setup time.

LiveMeeting with a Panorama view

You can't believe (or maybe you can) how much better the experience is for me when we use this. The Roundtable stitches together 5 cameras at 15fps into a 1056x144 panorama that covers a full 360 degrees. It also has a 640x480 square "active speaker" video. The Roundtable knows where people are in the room physically based on sound and will automatically create a square video view (as if each person had their own personal camera) and will 'cut' between them keeping the active speaker in view. This totally removes the "who's speaking?" factor from meetings.

I'm going to continue to ask anyone who wants to include me in a meeting to book a room with a Roundtable. We've got at least one on each floor, sometimes two, in most buildings.

Chat/IM

Microsoft's got internal chat through Office Communicator which I use to talk to all sorts of folks when email would be "too much." Communicator also acts as an global address book that lets me not only find out if someone is at their desk, but also when their next free block of time is as it's integrated into Exchange/Outlook. It also lets you "tag" someone if their presence changes - like if they've returned to their office.

I also use Communicator to make quick calls to folks in the office. If people configure it correctly, it'll call their desk phones and they won't know I'm calling from my PC.

Distributed Ad-Hoc Meetings

ooVoo Video ChatOne of the things that Live Meeting doesn't do easily is quick meetings using video with a bunch of folks that are located all over. For this I tend to use ooVoo. It's recently added 640x480 "High Quality" calls and unlike Skype, you don't need a Logitech special camera to do it. There's rumor (and a disabled menu item) that implies ooVoo will be going even higher-res, perhaps HD?

OoVoo does great through firewalls and most importantly lets me pull in folks from all over, a lot like iChat for the Mac. In fact, ooVoo is also cross-platform.

Screen Sharing

Often I've got to show my screen to someone I'm talking to. Live Meeting works for this, but it's a little heavy. I use both SharedView and CrossLoop, in that order. If SharedView fails to make it through the firewall (rarely happens) then I'll use CrossLoop. SharedView has the benefit that it supports sharing to up to 16 people and they just log in with their Live ID. CrossLoop is based on VNC and is a little slower to react, but I've never seen it not work. If you pay attention to the UI in CrossLoop and click "skip" at the right times, you can use it without creating an account. CrossLoop is great for fixing your parent's computer also.

Future: Putting Feet on my Web Cam - Telepresence Robots?

RoboDynamics ConsoleChris Sells (who also works remotely) and I have been brainstorming and prototyping ideas for smarter telepresence. Chris really wants a high-res camera with an optical zoom so he can see whiteboards.

Chris would be happy "without feet." He would like a computer/device/system that someone could pick up and take to a meeting - basically his disembodied virtual head - so he could participate in meetings.

I'd really like be able to "walk" into someone's office. Just pop in to see if they are there. I want to get involved in hallway conversations.

RoboDynamics RobotChris and I had the opportunity to remotely drive/beta-test a Telepresence robot from RoboDynamics. They've built their software on .NET 3.0 and the robot runs XP.

It was pretty sweet. They've got a 26x Optical Zoom and pan/tilt/zoom on the camera. There's a screen for your "head" so that folks can recognize you as you wander around. I was able to walk all over their office. The control console includes sonar and bumpers so when I got close to bumping into the fridge in their office kitchen I could "see" the distance to the fridge and avoid it.

There's a lot to think about when it comes to letting a virtual beastie into your company. Is it on the network? Which network? What access? Who is it logged in as? What if it's stolen?

As I understand it, RoboDynamics is looking to raise another round of funding so if you know someone, give them a call. Their stuff is REALLY impressive and cleanly implemented. There's video of the robot in action below.

Microsoft's doing a lot around Robotics and Robotics Research. Hopefully there will be a real telepresence solution soon for remote workers.  Maybe some Microsoftie will read this blog and let me beta test a robot or future telepresence platform...hint hint.

Future: Big Screen Cubical Portal?

prod_case_study0900aecd8054c81b-2Cisco has a telepresence platform that's pretty slick. Basically it's a really high res (1080p), really high framerate, low compression, 65-inch flat-screen or series of flat-screens.

If I could have an office with one of these screens set up, then folks could just pop by my office to say Hi. I could have a "portal" between my house and work up on campus in Redmond.

I thought I might be able to cobble something together with Skype or Office Communicator, maybe LiveMeeting, and some automation APIs. I could get a large monitor from Costco, maybe a no-name-brand 42" screen.

However, the bosses nixed buying the screens. It's funny, it costs about $250 to fly me up there, plus maybe $200 for a few nights in a hotel. If I went up just four times, that would be enough to by two 42" LCDs. Then I could just get a few PCs and I'd be in business.

The things that's been taking me the most time is:

  • Equipment: Setting up people who don't have these tools (software, webcams)
  • Patience: Convincing people that setting these things up are the ONLY way I can effectively do my job.

I am absolutely convinced that video conferencing builds relationships almost as much as showing up in person. If you've got the bandwidth to spare, talking to someone in F2F (face to face) via webcam conveys way more information than a phone call. Also, using a 640x480 webcam and software is a breath of fresh air when compared to the video conferencing that you may have used in the past. Another few years and we'll have clear 720p or greater, commodity video conferencing.

Do you work from home? What tools to you use to manage your remote life? What tools would you like to use?

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Back To Basics: Algorithms and Going Back To Virtual School

September 17, '08 Comments [18] Posted in Back to Basics | Learning .NET
Sponsored By

imageBefore I graduated from College/University I was convinced that school was for lamers. Then I graduated from school and decided that NOT going to school was for lamers. That shows you what a wishy-washy person *I* am. ;) School is for some folks and not for others. Wear the shoe that fits you best.

Totally random retrospective self-focused aside: I graduated from OIT with a BS in Software Engineering in 2003. Yes, that's 2003. It took me only 11 years to get a 4-year degree. ;)
I've been a programmer since 1992, so about 16 years, but 11 of those I was going to school at night. Basically I worked 9a-5p and went to school 6p-10p. For the first few years I took a lot of courses, but then work happened and I tapered off to one course a term. This was fine for a long time but then credits started falling off the other side. Basically courses I took 7+ years before became obsolete. I actually lived through four Deans while I was there. I made a deal with one of them that if I taught .NET I could keep my credits longer. That let me keep taking courses while working the whole time. The result took 11 years and two schools. But now I can just say, "I've got my degree and just not mention that I got it 5 years ago. Don't tell. Lots of experience sounds better than "slow learner at school."

Whether you went to school or are self-taught, even though the Internet was originally more a place to put academic papers than a place to meet "friends", there's a LOT more really good academic information on the web than I remember. It also takes more interesting forms than just pages of class syllabi. Here's the syllabus for the CST407 class I taught in Fall of 2003.

You can learn via Googling, you can learn via Book Readin' but you can also setup a more focused "curriculum" for yourself. I know a lot of devs that I admire that do this. They'll pick a discipline, area, language, whatever, and create a mini-class for themselves. Actually that much-teased "Learn Whatever in 24 Hours" books have more structure in this way than most programming books.

These days there's all the good content at iTunesU from colleges that didn't return my calls back in my High School years. There's even 1986 video of the legendary MIT lectures "Structure and Interpretation of Computer Programs" with Hal Abelson and Gerald Jay Sussman. There's MIT's excellent OpenCourseWare Videos of the Introduction to Algorithms class up on Google Video.

Professors are creating better and better tools to visualize things, like this amazing JavaScript-based page on "Animated Sorting Algorithms" by David R. Martin. It's utterly brilliant, not just because it's a Visualizer, but because the code is in Javascript, so you're seeing it happen. It's impressive like when you're playing a video game and you discover a particularly amazing cut-scene isn't prerendered, it's rendered in-engine. (UPDATE: And it would be impressive if it were true. I'm crushed. They ARE prerendered. Well, still. It's cool. Thanks, Adam!)

I recently stumbled on Massimo Di Pierro's site and his code. He's got a CSC309/321 class that he teaches at DePaul University and has a great Python application called "Algorithms Animator." His slides on basic OOP in C++ are excellent but the Algorithms Animator is really cool. There's a video of Algorithms Animator running over at Vimeo.

He's got all sorts of common algorithms, sorts, traversals, searches, etc. The algorithms are all in src/csc321algorithms.py, like this simple binary tree example.

def isNullTree(tree):
if tree is None: return true
if len(tree)==0: return true
return false

rootnode=0
leftchild=1
rightchild=2

def BinaryTree(node,left=[],right=[]):
list=[node,left,right]
if not isNullTree(left):
left[rootnode].parent=list
if not isNullTree(right):
right[rootnode].parent=list
return list

There's also more complex ones like a Huffman encoding example. But it's not the source code that interesting, although it is. The syllabus is really detailed, with the kind of detail you really only see in academia:

Huffman Encoding Definition: A minimal variable-length character encoding based on the frequency of each character. First, each character becomes a trivial tree, with the character as the only node. The character's frequency is the tree's frequency. The two trees with the least frequencies are joined with a new root which is assigned the sum of their frequencies. This is repeated until all characters are in one tree. One code bit represents each level. Thus more frequent characters are near the root and are encoded with few bits, and rare characters are far from the root and are encoded with many bits.

The Program accepts the text to be compresses as input and produces a text report showing compression rules and compressed text. The Program also shows in an animation how the Huffman tree is built.

Huffman encoding provides an example of Greedy strategy.

What's cool about this guy's way of teaching algorithms is that his app uses animation to show the algorithm happening step by step.

For example, if I use Huffman Encoding on the string "Scott Hanselman," here's Frame 0 of the animation.

"First, each character becomes a trivial tree, with the character as the only node."

Huffman Encoding Tree

Here's Frame 15 as the the character's frequencies are counted and the tree is in the process of being built.

"One code bit represents each level. Thus more frequent characters are near the root and are encoded with few bits, and rare characters are far from the root and are encoded with many bits."

Huffman Encoding Tree (2)

Here's Frame 22 as the tree has been built out and the bit values are applied.

Huffman Encoding Tree (3)

...and the result is in the image below showing the compression rules/map and the final bits.

image

I'm not sure about you, but I'm not able to bust out a QuickSort on a whiteboard under pressure anymore (I'm old).  I found this guy's stuff to be a great algorithms refresher, and using the little Python app to explore them made it very enjoyable. I wish we had this kind of stuff when I was in school. It's kind of nice to pretend I'm back in an Algorithms class and tickle the neurons that haven't fired in a while.

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.