Category Archives: news

Functional programming – coming to a compiler near you soon?

We can classify programming languages into a simple taxonomy:

Commercial programmers have overwhelmingly developed software using imperative languages, with a strong shift from procedural languages to object oriented languages over time. While declarative style programming has had some successes (most notably SQL), functional programming (FP) has been traditionally seen as a play-thing for academics.

FP is defined in Wikipedia as:

A programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.

Whereas an imperative language allows you to specify a sequence of actions (‘do this, do that’), a functional language is written in terms of functions that transform data from one form to another. There is no explicit flow of control in a functional language.

In an imperative language variables generally refer to an address in memory, the contents of which can change (i.e. is ‘mutable’). For example the rather unmathematical looking “x=x+1” is a valid expression. In FP there are no mutable variables and no state.

In an imperative language a function can return different values for the same input, either because of stored state (e.g. global or static variables) or because it is interfacing with an external device (e.g. a file, database, network or system clock). But a pure functional language always returns the same value from a function given the same input. This ‘referential integrity’ means an FP function call has no ‘side-effects’ and consequently can’t interface with external devices. In other words it can’t actually do anything useful – it can’t even display the result of a computation to your VDU. The standard joke is that you only know a pure functional program is running because your CPU gets warmer.

The functional language Haskell works around the side-effects issue by allowing some functions to access external devices in a controlled way through ‘monads’. These ‘impure’ functions can call ‘pure’ functions, but can never be called by them. This clearly separates out the pure parts of the program (without side-effects) from the impure ones (with side-effects). This means that it is possible to get many of the advantages of FP and still perform useful tasks.

FP is much closer to mathematics than imperative programming. This means that some types of problems (particularly algorithmic ones) can be expressed much more elegantly and easily as functional programs. The fact that a function has no side effects also means that it’s structure is much easier to analyse automatically. Consequently there is greater potential for a computer to optimise a functional program than an imperative program. For example in FP:

y = f(x) + f(x);

Can always be rewritten as:

z = f(x);

y = 2 * z;

Saving a function call. This is more difficult to do in an imperative language, because you need to show that second call to f(x) won’t return a different value to the first.

Functional programs are also inherently much easier to parallelise, due to the lack of side-effects. We can let the FP interpreter/compiler take care of parallelism. No need to worry about threads, locks, critical sections, mutexes and deadlocks. This could be very useful as processors get ever more cores. However imperative languages, with their flow of control and mutable variables, map more easily than functional languages onto the machine instruction of current (von Neumann architecture) computer. Consequently writing efficient FP interpreters and compilers is hard and still a work in progress.

Elements of FP are steadily making their way into mainstream commercial software:

  • Erlang is being used in commercial systems, including telecoms switching systems.
  • Microsoft Research has implemented F#, a .Net language that includes FP elements based on ML.
  • Work is underway to add elements of FP to version 2.0 of the D programming language.
  • Google’s MapReduce is based on ideas from FP.
  • The Mathematica programming language has support for FP.
  • The K programming language is used in financial applications.
  • The Perl 6 compiler is being written in Haskell. <insert your own sarcastic comment here>.

I recently attended ACCU 2008 which had a whole stream of talks on FP. All the FP talks I attended were packed out. That is quite something given that the audience is primarily hardcore C++ programmers. There seemed to be quite a consensus in these talks that:

  • FP is starting to move out of academia and into commercial use.
  • FP is more suitable than imperative style programming for some classes of problem.
  • FP is not going to replace imperative programming. The bulk of commercial development will still be done in an imperative style, but with FP mixed in where appropriate.
  • Hybrid languages that mix OO and FP will become more common.

I don’t see Haskell replacing C++ any time soon. But I can definitely see the benefits of using FP to tackle some types of problems.

Further reading:

The Functional programming reference in Wikipedia

This article is based loosely on notes I made at ACCU 2008 from attending the following talks:

  • “Caging the Effects Monster: the next decade’s big challenge”, Simon Peyton-Jones
  • “Functional Programming Matters”, Russel Winder
  • “Grafting Functional Support on Top of an Imperative Language”, Andrei Alexandrescu

Any mistakes are almost certainly mine.

planetmicroisv.com

planetmicroisv.pngFloyd Price of Code Spaces has taken over the day-to-day running of microISV blog aggregator planetmicroisv.com from Baruch Even. He has already given it a fresh coat of paint. I appreciate the efforts of Baruch and Floyd to maintain this useful resource. planetmicroisv.com is well worth adding to your RSS feed if you are a microISV (or aspire to be).

RegSoft customers beware

It looks like Digital River have added ‘Reservation rewards’ to at least some of their RegSoft customers’ shopping baskets, as they did earlier with SWREG. If you take the bait and sign up for Reservation Rewards, you will be billed $9 per month forever, and get nothing useful in return. It is an absolute disgrace. If you are with RegSoft (or any other Digital River company) I suggest you check your shopping backet ASAP and seriously consider moving to an non-Digital River alternative.

Windows Vista service pack 1

vista.gifMicrosoft have announced that service pack 1 for Windows Vista has been released to manufacturing. Microsoft claim “great progress in performance, reliability and compatibility”. SP1 will be rolled out through Windows update from mid-March.

My own stats show that Vista has been slowly increasing market share at 1% per month. At this rate it will take it another 5 years to reach the 75% share currently held by XP. But perhaps a lot of people have been wisely waiting for SP1 before committing?

I have been using Vista on my main development machine for the last few months. It is OK once you turn the deeply annoying UAC off. But it is still hard to see any compelling reason to upgrade from XP.

Nokia to acquire Trolltech (makers of Qt)

trolltechTelecoms giant Nokia are to acquire Trolltech, the company behind leading cross-platform toolkit Qt. As a fan and long time user of Qt this makes me a little nervous. I hope it will lead to more investment in Qt and lower maintenance fees. The opposite could happen of course. It isn’t unknown for a large company to buy a good product and then ruin it (the purchase of Purify by Rational springs to mind). At least I have the full source code for Qt if it all goes to hell in a handbasket. I learnt long ago (the hard way) that you should never depend on a third party libraries if you don’t have the source.

Having a crack at the crackers

crack siteSoftware cracks are a real problem for software vendors large and small. I have discussed in a previous article some of the ways in which developers can try to mitigate their effects. A fellow ASP member (who might wish to remain nameless) has gone a step further by creating a fake crack site serialsgalore.com . It looks quite convincing, but when you try to download a crack it gives you an ominous message about the error of your ways and logs your IP address. I would have gone for a less confrontational message, but it will be interesting to see how effective this approach is.

I think serialsgalore.com is worthy of support by developers. Please consider giving the site some Google juice by linking to it from your site or blog using link words such as crack, keygen and/or serials. If you don’t want to do this on a main page of your site, link to it only from your site map page. Alternatively create a Google site map (a good idea anyway) and only reference the page with the links from there. I believe the site owner is going to try to cover his costs by donations, Google ads and possibly, referral fees. I certainly don’t begrudge him some return on his efforts. I also don’t feel bad about them playing a little trick on someone looking for illegal cracks. It might even save them from downloading malware.

Business of Software wiki

fogbugzJoel Spolsky has announced a Business of Software wiki based on FogBugz 6. You can view/edit the wiki here.

“The point of this wiki is to bring under one roof as much high quality, useful information as possible about the business of software, whether it’s microISVs selling desktop software, Web 2.0 sites or even the big enterprise kind of outfits.”

This will become a useful resource for software entrepreneurs if enough people contribute. I have added an article from this blog to do my little bit.

47 hats

47hatsBob Walsh (microISV owner, Business of Software forum regular/moderator, blogger and author[1]) has just launched his new microISV consultancy 47 hats. I don’t know how he finds time to sleep!

I have thought about branching out into providing consulting to other software companies myself (micro and macro). It is part of the motivation for starting this blog. But I am really too busy with PerfectTablePlan at present. Anyway I am sure there is plenty of work to go round and I wish Bob the best of luck with his new venture.

[1] Bob’s affiliate link.

SWREG customers beware

swreg upsellIf you are a customer of the ecommerce provider SWREG you should beware that they may be upselling highly questionable ‘discount’ schemes to your customers. From a post on the Business of Software forum:

This unannounced change was placed at the point of order completion where and leads to a $10/mo discount coupon scheme unrelated to the sold shareware. The way the offer is presented is deceptive – after the order is complete, they show a button with the word “Continue” on it. It looks like you are supposed to press the button to complete your order. Instead, you end up paying for something you probably didn’t want – and it’s a recurring charge.

Another posting suggested this only happens if your customer is in the USA.

I am not based in the USA and haven’t bought anything from SWREG recently myself, so I can’t personally verify the above. But these comments are backed up by posts I have seen on other forums from unhappy vendors and their unhappy customers. If you are using SWREG I suggest you buy a copy of your own software and see for yourself (you can always refund the payment later).

Assuming the above is true – what are they thinking? Either they don’t see anything wrong with it (which is very worrying) or they know its completely unethical, but are doing it anyway (which is even more worrying). It reeks of desparation to me. I thought their upselling of a registration backup service was highly questionable (I think vendors should provide this service for free), but at least it was clear what you were getting.

Vendors looking to move from SWREG to a different ecommerce provider might like to consider companies not owned by SWREG’s parent company Digital River. I use e-junkie.com with PayPal and GoogleCheckout. Other people have recommended Plimus and Avangate. You can compare processing fees here.

Google Adwords ‘placement performance’ report

Google Adwords placement reportYou can now find out what sites your Google content ads are appearing on, using the new ‘placement performance’ report. This will alllow you to spot under-performing sites in a content campaign. To exclude a site from your campaign click the ‘excluded site(s)’ link at the top of the appropriate campaign page.

My placement report for June shows that PerfectTablePlan has had 25,309 impressions and 0 clickthroughs from myspace.com. Does that make it officially the least cool software ever? ;0)