Benefits of functional programming

A couple of linked articles with a strong story on the benefits of choosing F# over C# for reducing the bug count and reducing the size of the codebase.

Simon Tyler Cousins compares two similar projects with F# clearly superior to C# in every category for those projects.

Don Syme opines that a key benefit of F# is that nulls are all but eliminated in the code and references the manifesto for Not Only O-O:

We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value:

Functions and Types over classes
Purity over mutability
Composition over inheritance
Higher-order functions over method dispatch
Options over nulls

That is, while there is value in the items on the right (except for nulls), we value the items on the left more.

Leave a comment

Filed under Programming

GCC 4.8 released

GCC 4.8 has been released. This version uses C++ in its implementation (previously it was C only).

Leave a comment

Filed under C++

How to use smart pointers in C++

Good question about how to use c++ smart pointers posted on Stack Overflow. I haven’t used std::weak_ptr, but the idea of using it to return an “observing” pointer that you can later check for expiry and obtain a std::shared_ptr sounds like a better approach that returning a raw pointer.

Leave a comment

Filed under C++

Book Review: The Proteus Operation, James P Hogan

The Proteus OperationThe book has all the bases covered – history (much is set during World War II), science fiction (time travel) and action (crack troops storming the secret bases of their enemies). I think the plot was excellent, but something was lacking – I found the story telling stodgy in places (particularly at the beginning) and the characters were bland.
ThreeAndAHalfStars

Leave a comment

Filed under Book Review

Book Review: Accused, Mark Gimenez

20130418-195930.jpgReally enjoyed this, it kept me guessing until the last page, with plenty of suspense and excitement. The author interspersed some funny passages too, particularly between the lawyer and his young daughters. This was the first book I’d read by Gimenez, but I will be back for more.

FiveStars

2 Comments

Filed under Book Review

WordPress App mangles my code!

I’ve noticed that whenever I use the WordPress App on my iPhone or iPad to edit a technical post that includes some code, the snippet I’ve carefully slaved over gets mangled. In particular, anything that uses templates in C++ (or generics in F#) will be affected, for example

vector<int> myData;

becomes

vector; myData;

The only answer at the moment is to be disciplined and restrict myself to editing code-based posts in the Web editor, which doesn’t destroy my content.

1 Comment

Filed under C++, Technology

How to recover a dead iPhone

I got out my my iPhone this evening and it was dead.  No response from it, not even when I plugged it in to the mains (which has worked before when the battery ran out of charge).  Attaching to a PC via USB did not revive it either.  Very mysterious, given that it was working just fine on the way home from work.

Fortunately, this post had the answer – hold down the Power button and Home (square) button until the Apple logo appears.  And you have to believe – no point counting to ten and giving up, really believe and the iPhone will come back to life.  Worked for me (after 14 seconds).  This article has even more tips in case the first doesn’t work.

Some might say that any hardware that relies on the user to google an obscure combination of buttons to turn on their phone has a screw loose – but I’m just happy to have my phone back.

Leave a comment

Filed under Technology

Stephan Lavavej’s make_unique proposal

Stephan Lavavej has submitted a proposal to the C++ Standards committee for make_unique (the std::unique_ptr equivalent to std::make_shared for std::shared_ptr).

make_unique’s presence in the Standard Library will have several wonderful consequences. It will be possible to teach users “never say new/delete /new[]/delete[]” without disclaimers. Additionally, make_unique shares two advantages with make_shared (excluding the third advantage, increased efficiency). First, unique_ptr<LongTypeName> up(new LongTypeName(args)) must mention LongTypeName twice, while auto up = make_unique<LongTypeName>(args) mentions it once. Second, make_unique prevents the unspecified-evaluation-order leak triggered by expressions like foo(unique_ptr<X>(new X), unique_ptr<Y>(new Y)). (Following the advice “never say new” is simpler than “never say new, unless you immediately give it to a named unique_ptr”.)

It’s a really useful utility as demonstrated in this video.

Leave a comment

Filed under C++

Primer on Credit Default Swaps

This is an excellent introduction to CDS’s, aimed at developers.

Now consider the case where we buy a General Motors bond. We then enter into a credit default swap to the maturity of the bond as well. This acts as insurance against General Motors defaulting on the bond. We receive interest from the General Motors bond, but pay some of it away in insurance on the credit default swap. Suppose the interest rate on a US Government bond is 5% and the interest rate on a General Motors bond of the same maturity is 8%. We’d expect the premium on a credit default swap on General Motors for the same period to be about 3%. Note that the 3% premium is also called the ‘spread’ on a credit default swap, since it is the spread between the government bond and the corporate bond interest rates.

In summary, a credit default swap is a contract where one party to the contract pays a small periodic premium to the other, in return for protection against a credit event (financial difficulty) of a known reference entity (company).

I wish there were more articles on financial products like this, written in plain English for non-Quants.

Leave a comment

Filed under Finance

Equality and Comparisons in F#

This blog post from Don Syme is really useful when considering options for customising equality and comparisons in F#. Having said that, with F# 2.0, it looks like you don’t need to put attributes on your type, it’s enough to follow Don’s overrides of GetHashCode, Equals and CompareTo.

Leave a comment

Filed under Programming