May 2010 - Posts

Learning F# Using Project Euler

I’ve decided that immersion is the best way for me to learn new programming concepts. My exposure to WPF came 4 years ago when I started at a new employer and was told that my first assignment was to learn the application codebase and create a WPF Datagrid that could display data from our application (the view of the data was dynamically composed using metadata from an EAV database). Needless to say, the effort helped bring me up to speed quickly with both the internal codebase and WPF.

I want to learn F# and have been looking for a way to immerse myself in it. Enter Project Euler, an online collection of math/computer science puzzles. I’m using F# to solve the problems one by one, purposefully using the functional aspects of the language rather than the OO aspects. Here is my solution for the first problem in F#

let list =
    [1..999]
    |>List.map(fun n ->
               if n % 3 = 0 || n % 5=0 then
                n
               else
                0)
    |>List.sum

printfn "Sum of integers %d" list

I’m trying to figure if there’s a way for me to remove the if…then…else clause (possibly using pattern matching). But I guess it’s a good start for now.

Posted by Mike Brown | 4 comment(s)

What is MVVM?

There has been a lot of confusion lately over just what MVVM is and what it isn’t. I think this confusion has led many to throw their hands up in disgust and/or frustration and swear off MVVM altogether. I think the confusion comes because people aren’t clear about the delineation between the pattern itself and the details of implementing the pattern. So here is my definition of MVVM.

Model-View-ViewModel (aka Presentation Model)

Problem: You have a UI with complex, interdependent interactions.
Solution: Separate the UI from the UI logic using a ViewModel that encapsulates the interactions and provides properties for a View to retrieve its state (and the state of its elements).

This is the long and short of MVVM Nothing more nothing less. Everything else is an implementation detail. If you use INPC or not, if you use Code-Behind in ASP.NET or Data binding in WPF/Silverlight. If you use DelegateCommands, RelayCommands, or RoutedCommands. If you use attached behaviors or Blend behaviors, VSM, or data triggers is not a concern of the pattern. The pattern is overkill for "Calculator Examples" (unless of course your calculator is storing a stack of historical operations for undo/redo). The pattern is not mutually exclusive of using a Front Controller for navigation.

I think the majority of frustration regarding MVVM comes from a lack of this fundamental knowledge of what it is and what it isn't. So there, I've spelled it out. HOW the pattern is implemented is up to the individual.

Posted by Mike Brown | 8 comment(s)