Looking back at 2011

Well, we’re a few days into 2012 and no armageddon yet, so it’s probably safe to take a quick glance back over our shoulder at some of the technical stuff that’s flashed past in the preceding 12 months.
Read More »

Posted in F#, iOS, Software Development, WPF | Tagged , , , , , , | Leave a comment

Drawing animated shapes and text in Core Animation layers

Star and text

Star and text

The other day I was overcome by the desire to create an animated start-burst, price-tag type graphic with iOS. Time to break out some Core Graphics and Core Animation code. On the way to getting it going, I came across some interesting gotchas, which I thought it’d be useful to talk about here.
Read More »

Posted in iOS, iPhone, Mac, Software Development | Tagged , , , , , , , | 2 Responses

Creating a physics-based OpenGL iOS app

puppet_grabWith the success of iOS games like Angry Birds and its flocks of imitators, there are lots of people looking at creating physics-based games, so I decided to try and create a simple demo using OpenGL ES and the Bullet physics engine.
Read More »

Posted in C++, Graphics, iOS, iPhone, Software Development | Tagged , , , , , , | 12 Responses

C++: The oldest new kid on the block

TastyNobody could have failed to notice the recent resurgence of interest in the C++ programming language. In particular, the recent Build conference was the most we’ve seen Microsoft talking about C++ for several years. Why has a language that’s been languishing in the “prehistoric irrelevance” category for so long suddenly come back into vogue?
Read More »

Posted in C++, Rant, Software Development, Windows | Tagged , , , | 4 Responses

Kinect SDK with F#

Just what do you think you're doing, Dave?

Just what do you think you're doing, Dave?

I finally got around to taking a look at the Kinect SDK the other day, partly because I was interested to see how the API looked from F#. Unfortunately getting it going turned out to be more of a pain than I was expecting.

The first bit was easy: I’m “lucky” enough to have one of the older Xboxes, which meant I’d had to get a Kinect with separate power, which is the one required by the SDK. Now all I needed was a Windows machine to develop on.
Read More »

Posted in .NET, F#, Graphics, Software Development, WPF | Tagged , , , , | 3 Responses

Am I being called from DllMain?

Lock; literal images 'r' us

Lock; literal images 'r' us

While Googling for an obscure Windows function the other day, I came across this fantastically useful repository of undocumented WinAPI functions, put together by Geoff Chappell. I’m not sure how I hadn’t discovered it before.

One of the functions that immediately caught my eye was LdrLockLoaderLock. I’d previously spent quite a few frustrating hours trying to figure out how to determine whether some code was being executed from DllMain, i.e. while in the loader lock, so I could avoid doing anything dodgy – or indeed, anything at all.

The case I was looking at was some logging library code that was used, amongst other things, to record the fact that DLLs were being unloaded. Unfortunately when this was called from DllMain, it sometimes caused a deadlock, for all the reasons we already know about. The library code was called from lots of DLLs, so it wasn’t feasible to fix all of the call sites, instead I had to make the logging a no-op when it’s not safe.
Read More »

Posted in .NET, Debugging, Visual Studio, WinDbg, Windows | Leave a comment

F# Async: Plays well with others?

OK, quick Async pop quiz: How long does the run function below take to execute?

module Test = 
    let work i = 
        async { 
            System.Threading.Thread.Sleep(500) 
            return i+1 
        }
    let run _ = 
        [1..1000] |> List.map work 
        |> Async.Parallel 
        |> Async.RunSynchronously

(Waits for people to start FSI and paste in the code…)

My guess would’ve been something just over 500ms; each of the 1000 async tasks would surely sleep in parallel, and then the operation itself is trivial. The additional elapsed time would be dominated by the overhead of thread management, and depend on the number of threads that can physically run in parallel (I’m using an 8-core machine). But still, something close to 500ms…

The actual result? 28000ms. Yes, you read that right: 28 seconds. What on earth did we do wrong?
Read More »

Posted in .NET, F# | Tagged , , , , | 1 Response

Mixing it up: when F# meets C#

Simples?

Simples?

If it were a perfect world, we’d all exist in a happy little bubble of our favourite programming language and you’d never have to worry about the nasty details of interacting with something written by – gasp – someone else in a – double-gasp – different language. But unfortunately that’s precisely what we have to do all the time. And that means that one day all of your fancy-pants algorithmic, highly parallel, functionally pure F# code is going to meet the world of “enterprise” C# development head-on.

Of course the idiomatic way to avoid problems at the boundary between your F# code and the outside world is to ensure that you only expose a small set of compatible types. This works pretty well if your clients are also .NET languages. For instance you can do things like exposing your collections as seq, rather than say, a native F# list, and this will mean your collections can be consumed as IEnumerable. The only problem is it means you’ve got the added burden of maintaining this mapping layer, because you’ll no doubt want to use the F# “native” types internally.

So, what options do we have if some of our F# types happen to leak into our public API? Luckily, lots. Let’s take a look at how some of the common F# constructs can be called from C#.
Read More »

Posted in .NET, F#, Software Development | Tagged , , , | 3 Responses

Not dead, just busy

Well, the title says it all really. I just wanted to let everyone know that I’m not dead – despite what you may be thinking based on my lack of blog output – it’s just that I’ve been insanely busy on a project in the day job. Yep, it’s that old excuse of real paying work getting in the way of the fun stuff again.

Hopefully soon I’ll manage to post some new stuff, possibly more ‘transitioning to F#’ posts and bit more iOS development malarkey. In the meantime, keep on keeping on.

Posted in F#, iOS | Leave a comment

Beginning F#: Positive Discrimination

(or “Discriminated unions for dummies like me”, or “Tagged unions for the rest of us”)

Discriminated unions are one of those things in the lexicon of functional programming that can often sound baffling to “outsiders”; it’s almost up there with monads and currying. But in practice they’re simple and incredibly useful. I thought I’d try and show a concrete example of where they can be used in a way which is more powerful and robust than the equivalent OO approach.
Read More »

Posted in .NET, F#, Finance | Tagged , | 4 Responses
  • Follow me on Twitter Follow me on Twitter @voyce

  • Check out Wordz my new fast-paced make-a-word game for iOS.
  • Categories

  • Archives