Silicon Valley Code Camp material

Huge thanks to everyone who came to my presentations at Silicon Valley Code Camp this year – and to the organizers. It’s amazing to me how the event has been growing up year after year, and yet retains its friendly atmosphere, and smooth organization.

For Those About to Mock

I uploaded the entire code sample, illustrating how to roll your own, and how to achieve the same result with Moq, Rhino and NSubstitute here. The slides are included as well. Note that it assumes you have installed NUnit on your machine. If this isn’t the case, some of the projects won’t build.

An excursion in F#

The code sample is uploaded here. I must say, I was very pleasantly surprised by the level of enthusiasm of the audience, especially so because it was very late in the program. Sorry again for the string of technical glitches, and thank you for being really awesome, this session was a memorable one for me, thanks to you all!

Notes:
1) one of the projects (FSharp.StockReader) will not build unless you have the F# PowerPack installed on your machine, because it uses the Async extensions which come with it. Either install it, or unload FSharp.StockReader and CSharp.ConsoleClient.

2) In Stocks.FSharp.Scripts, you will have to modify the first line of the code to point to the location of FSharpCharts.fsx on your local machine.

That’s it! I haven’t added material for the TDD session because all the code was written live, and the slide deck can be largely summarized with Red, Green, Refactor – if you want me to add that as well, let me know!

More...

Coming up soon: Silicon Valley CodeCamp 2011

headCodeCamp

It’s this time of the year again: on Saturday & Sunday October 8 + 9, Silicon Valley CodeCamp is taking place at Foothill College in Los Altos Hill. There are currently over 200 sessions listed, and 2000 people signed up already. I am expecting lots of fun - again.

I’ll be giving 3 talks this year

  • Sat, 11:45: Beginning TDD for C# Developers.
  • Sun, 1:15: For Those About to Mock.
  • Sun, 2:45: An excursion in F#

Hope to see you there, and also that I will have some energy left to attend some of the other talks!

More information about my talks here.

More...

Code sample from the North Bay .NET meeting

As promised at the meeting, here is the code I used in the presentation at the North Bay .NET user group last week. Let me know if you have comments or questions!

More...

Fun with List comprehensions

I had the pleasure to present at the North Bay .NET user group this week on F#, where people asked me all sorts of great questions. At some point, we got into List comprehensions – a convenient syntax to generate lists - via an example along these lines (which returns a list of the multiple of 2, from 2 to 40):

let list = 
   [ for i in 1 .. 20 do yield 2 * i ]

While slightly more complex, the actual example is in essence equivalent. A question followed: how complex can the code within the brackets be?

Well, pretty much as complex as you want it to be. Take this for instance:

let list =
   [
      for i in 1 .. 10 do yield 2 * i
      for i in 1 .. 10 do yield 3 * i
   ]

This will return a list of the multiples of 2 from 2 to 20, followed in the same list by the multiples of 3 from 3 to 30. Nice.

But you can go much wilder, and start putting code in there, too. For instance, we can expand the previous example a bit and morph it into a nice and concise FizzBuzz:

type Fizzbuzz = Fizz | Buzz | FizzBuzz | Number of int

let fizzBuzz n =
   [
      let fizzBuzzConvert number =
         if number % 2 = 0 && number % 5 = 0 then FizzBuzz
         elif number % 5 = 0 then Buzz
         elif number % 2 = 0 then Fizz
         else Number(number)
      
      for i in 1 .. n do yield fizzBuzzConvert i
   ]

We declare a discriminated union, covering all the possible outcomes of FizzBuzz, declare inside the comprehension itself a function that maps an integer to a FizzBuzz result, and generate the list of results from i to n. Running this in the interactive window results in the following:

let fizzBuzz n =
   [
      let fizzBuzzConvert number =
         if number % 2 = 0 && number % 5 = 0 then FizzBuzz
         elif number % 5 = 0 then Buzz
         elif number % 2 = 0 then Fizz
         else Number(number)
      
      for i in 1 .. n do yield fizzBuzzConvert i
   ];;

type Fizzbuzz =
  | Fizz
  | Buzz
  | FizzBuzz
  | Number of int
val fizzBuzz : int -> Fizzbuzz list

> let f = fizzBuzz 20;;

val f : Fizzbuzz list =
  [Number 1; Fizz; Number 3; Fizz; Buzz; Fizz; Number 7; Fizz; Number 9;
   FizzBuzz; Number 11; Fizz; Number 13; Fizz; Buzz; Fizz; Number 17; Fizz;
   Number 19; FizzBuzz]

I would classify List comprehension under the “nice to have” features – it’s perfectly possible to write excellent code without it. At the same time, it’s a very, very convenient way to work with Lists, which I now miss in C#…

More...

New release of Microsoft Solver Foundation

Just saw that version 3.1 of Microsoft Solver Foundation has been released. I haven’t had time to try it out yet, but the list of improvements looks promising. A better non linear solver, better MIP and MIQP – sounds like Santa has come early! And I am curious about the faster bindings with LINQ…

More...