ConfusionableFuture in Java8

Code, Software - No Comments » - Posted on June, 9, 2015 at 2:19 am

We are making use of Java 8’s CompleteableFuture but I was getting very confused about what the difference between thenCompose, thenAccept and thenApply. Thankfully I work with smart people. Here is our discussion.

lw: It’s really simple…
thenCompose takes two promise actions and runs one after the other

readContentsFromAFile().thenCompose(contents -> doSomethingElse(contents))

would read the contents of a file then do something else, all async

me: where the `printContentsToScreen` returns a promise
lw: Yeah

lw: thenApply takes a promise action and a pure function and transforms the output of the promise using that function

readContentsFromAFile().thenApply(contents -> length(contents))

That makes a new promise action that reads the contents of a file and returns the length of it (notice there is only one promise action involved)

thenAccept takes a promise action and a non-promise procedure and runs the procedure non-async on the results e.g.

readContentsFromAFile().thenAccept(contents -> blockingPrintContentsToScreen(contents))

That makes a new promise action that reads the contents from a file asynchronously, then run the blocking print operation on the contents
The main point is that thenAccept only executes one promise then a normal java procedure

me: So

CompletableFuture<int> cf = readContentsFromAFile().thenApply(contents -> length(contents)); 

lw: Correct

me: Where as thenAccept returns CompletableFuture<void>

lw: Yes

me: and thenCompose is like `here, use this one`
So it’s like

CompletableFuture<Whatever> cf = something.thenCompose(contents -> asyncGetWhatever());

lw: Yeh. I prefer to think of `thenCompose` as chaining two promises together, so when the first one finishes it runs the next one

me: Got it, thanks.

Introducing the “Nimble” Software Methodology

Software, Technology - 1 Comment » - Posted on October, 30, 2011 at 9:37 am

I had a comment from someone on a previous rant about the term agile, and it has spurred me on to tell you all about my first encounter with nimble software processes.

In my first job out of Uni I was working on a client site in another country on a project where the delivery date was set based on the owner’s birthday. So I probably should have run a mile based on that alone. But it was new and exciting and I didn’t know what to expect from the real world so I worked my 6 day weeks with 3 hour commute each day. We had a team with an experienced lead and 5 grads straight out of Uni, and the work environment was very unsettled (figuratively and literally, they were building the building around us). We were keen to employ some of the things we’d learned at Uni so we approached our team lead and said:

“The client is changing their mind all the time, instead of just hacking on code each time they do this we should employ some sort of agile process to manage it”.

To which he replied:

“Process is for stupid people, it’s for people who can’t manage themselves. We’re better than Agile, we’re … Nimble.”

And from that day forward any time someone has said they use a process when they are clearly using no process at all, or only the bits that mean they have to do less work, I have labelled them as using a Nimble methodology.

“Agile” considered redundant

Software - 2 Comments » - Posted on July, 29, 2010 at 7:38 am

I have many pet hates, one of them is the term “agile” when talking “agile software methodology” or “agile software process”. It’s not any of the actual processes that I dislike, it’s the use of the term “agile”. I think it’s overused to the point where it no longer means anything. When people talk about agile methodologies they contrast them with “traditional” methodologies, usually the waterfall methodology. This is where it starts to irk me – why is it that there are thousands of agile methodologies, and ONE non-agile methodology. And in fact if you made a process which was essentially lots of shorter waterfall methodologies you could probably pass it off as an agile process. So this is why I think the term “agile” is a completely redundant term.

Anything that is essentially an iterative methodology is labeled as agile. And because most processes are iterative due to the nature of projects (i.e. requirements change, regardless of software industry) pretty much every software process out there is agile. Which of course means that the “agile” is completely redundant and can be dropped and we can return to talking about processes, rather than agile processes.

I thought of an analogy which goes some way to explaining my distaste of the term “Agile”.

 <em>“Agile” is to software process what “award winning pies” is to a bakery. </em>

i.e. What bakery doesn’t have award winning pies?

Essentially any process, agile or not, has a series of steps to follow, and a bunch of techniques and tools which help software quality (e.g. pair programming) or some other software or project attribute (e.g. you measure earned value to predict completion time). If you take anything which is iterative and produces something, and then grab a bunch of these techniques, and give it a process metaphore (e.g. SCRUM has “sprints” etc) and you’ve got yourself a new agile process. No wait, let me take that back, you’ve got yourself a new process. We don’t need the term agile, because it doesn’t mean anything anymore.

An Unfortunate Link & Capital Aquaponics Launch

Aquaponics, Dreams, Environment, Software - No Comments » - Posted on November, 30, 2009 at 11:05 am

I’ve recently told some people about my blog on Aquaponics, and that they can just search for “Aquaponics Canberra” in google and it’ll come up. Well, it does, but unfortunately it comes up with my old system, where the vegetables looked lanky at best and the fish were at their worst. I have since solved that problem, and for the last year have had great success with both the old system and pro system, but still “Aquaponics Canberra” links directly to the blog containing sick fish.

Normally I wouldn’t really care, but I’ve just launched a business: Capital Aquaponics – I figured that I’ve learnt so much over the last 3 years (and there is a LOT to know) that I am now able to design a system that effectively side steps all those pitfalls that most people fall for when they’re starting up. Not only that, but I figure I am now able to go over someone’s house and pick out the best locations for all the components such that we can utilise any sloping land, light and shade sections of the yard, thermal masses etc etc. So I’m going to provide a service to those who just want to skip the painful startup and learn by mistake methods of building systems and help them design and install a system which will maximise the chance of a succesfull crop. Oh, and because I have built systems from all sorts of materials (bathtubs and IBCs, barrels, BYAP systems), I can pretty much do it for any budget.

I’m going to be selling my knowledge rather than kits, because I think kits are going to become more and more common as this Aquaponics thing really takes off. I’m all for someone going and building their own, it’s a fantastic hobby (gardening for engineers/blokes really), but if someone just wants to produce edible fish and vegetables on their backdoor in a really cool, sustainable and ecenomic way and NOT have to learn everything about the different techniques then I can do it for them.

Anyway, we’ll see how it goes. The site is pretty rudimentry at this stage.

AI Just Search of Blogs?

Ideas, Ponderings, Software, Technology - No Comments » - Posted on November, 15, 2008 at 12:50 pm

Here’s an interesting idea: I reckon there are so many blogs out there that the first Artificial Intelligence (AI) will simply be a modified search engine. Tthe more obscure and convolouted the topic, the more likely someone is to blog on it. I reckon there’s probably a blog on just about everything. What about an Amish blog – yep (well kinda). What about a blog on cleaning sewers – yep (kinda). Pick a subject, google it, I bet it’s there.

And why am I picking blogs instead of just the web in general? Well blogs are opinions. To be declared an AI, the machine/software must pass The Turing Test – in short it must fool a real person into thinking that it’s a person through text based chat (e.g. IRC, MSN Messanger etc). Of course real people participate as the “control” and sometimes the judges pick the real people as machines and the machines as real people, but nobody has claimed the prize as yet (though apparently there were a few that were close this year).

So what I’m trying to say is that this software that is undergoing the test must act like a human – i.e. have an opinion. What’s the best way to do that? Data mine the millions of human opinions floating in the World Wide Web. Basically if the judge asks a question, the software would look up that question on the web (blogs only) and find someone who’s had an opinion or thought about it somewhere out there, do a bit of syntactic juggling and pass the result back to the judge.

It’s not really an AI, because it’s not really thinking for itself – it’s more like a global consciousness. It just takes the opinions of the people out there and uses them as it’s own.  I know I’ve glossed over some pretty complex stuff – how could you properly take input and find the right answer? What is this syntactic juggling? Google has technology which pretty much knows what you’re asking even when you mis-type it, so I think the technologies are out there.

I wonder how hard it would be to do this, and I wonder how good the results would be.

Mad H4x0rs

Site, Software - 1 Comment » - Posted on December, 5, 2007 at 8:14 pm

One of the fantastic things about having a blog that nobody reads is that any anomoly quickly shows up. If I hit up the statistics page for my domain, I see this:


Search Keyphrases (Top 10)
14 different keyphrases Search Percent
pps til exe 6 31.5 %
replacing 306 cabriolet hydraulic roof hoses 1 5.2 %
bernard hill 1 5.2 %
everquest midi download 1 5.2 %
replacing 306 cabriolet hydraulic roof houses 1 5.2 %
peugeot 306 cabriolet hydraulic ram 1 5.2 %
vp62 codec download 1 5.2 %
download decode for pps 1 5.2 %
vray plugin rhino error 1 5.2 %
how to fix peugeot 306 cabriolet roof 1 5.2 %
Other phrases 4 21 %

So my site was found 6 times by searching for pps til exe.

Pages-URL (Top 10)
16 different pages-url Viewed Average size Entry Exit
/grandad/feed/ 23 35.17 KB 23 22
/gemmell/replacing-306-cabriolet-hydraulic-roof-hoses/ 17 21.53 KB 11 9
/gemmell/gallery/tmp/download-freeware-.pps-to-.exe.html 11 13.82 KB 6 6
/gemmell/ 7 35.03 KB 3 5
/ 2 1.37 KB 2 2
/gemmell/2007/04/14/goals-dreams-needs-and-lucid-dreams/ 1 16.00 KB 1
/gemmell/gallery/aquaponics 1 20.71 KB
/gemmell/replacing-306-cabriolet-hydraulic-roof-hoses 1 21.53 KB 1 1
/gemmell/gallery/css/base.css.default 1 6.63 KB 1
/gemmell/gallery/tmp/vray-plugin-for-rhino-serial-number.html 1 17.25 KB 1 1
Others 6 16.67 KB 4 2

The number three most visited page on my domain is “gallery/tmp/download-freeware-.pps-to-.exe.html”. That is,  someone has used an exploit for Gallery V1 (or maybe just my mismanagement) and is using my site to host their illegal goodies. I’ve since deleted all traces of Gallery v1 and am hoping Gallery v2 is more robust. However, if I’d had more than say 100 people viewing legitimate things on this site, those hack entries wouldn’t have made it into the list and I’d have been none the wiser. Finally, I have found a good reason to be unpopular.

The Problem with Software Quality

Software - No Comments » - Posted on May, 9, 2007 at 6:38 pm

For those who arn’t in the Software business, now’s probably a good time to go to another website. For those that are, I’m going to have a rant about Software Quality.

We are far too familiar with term “crash” than we should be. I pride myself on creating good quality software (and my job requires that I do since I work with safety critical systems). But the amount of crap out there is just phenomenal.

I was talking to a friend of mine who was about to roll out a software product at a customer site and I asked him:

“Is it well tested? Are you confident?”

He replied with:

“No and No”

Where I work we use DBC (Design By Contract) and find it immensely useful for finding defects. Basically we have functions like this:

bool AddItem(ListItem* item)
REQUIRE(item != NULL);
//add the item
ENSURE(list.size() > 0);
//return result;

If a REQUIRE or ENSURE is ever violated an onAssert__ function is called with a file name and line number.

This means that I can write a function and be damned sure that if it’s ever used in a way that wasn’t intended we’ll know straight away. See the problem is generally that a fault in code occurs, say something returns a 0, and then sometime later that value causes the application to crash. Unfortunately this may be 30 function calls later leaving you with a stack dump nowhere near your original problem. In my experience DBC allows you to catch the error when it occurs, and thus saves you time. If you use it, you’ll find that you get a DBC error and think “Thank god for DBC, that would have been a bitch to find otherwise”.

Anyway, I digress. I asked him whether he’d like our implementation of DBC and he said “nah, it’d be impossible to institute here anyway” and then he listed a two main reasons:

  • There is no emphasis on quality. In his line of work time to market is way more important than correctness and quality (which I find hard to fathom). So it doesn’t matter if you deliver a wrong product thats full of bugs, just so long as you’ve delivered something.
  • There is general apathy for quality in the workplace. People don’t want to improve things. They’re happy hacking away and since there is no requirement from above, why would they want to change?

Why don’t people want to improve the quality of their code? Because:

quality == boredom.

Code reviews/inspections are by far the most efficient method of finding defects (see any of Humphreys texts), but I find reviewing someones code horrendously laborious and boring. Software is notorious for having out of date or non-existent designs, why? Because documentation is boring. Testing? Boooorrrrrring. Coding however is lots of fun! Thats why I became a Software Engineer. Thats why we have a thriving open source community. Thats why there is so many really bad quality products out there.

The problem with Software Quality is that it is not FUN. I don’t know if it can be fixed, but thats the way I see it.

When Installers Go Bad

Linux, Software, Technology - 2 Comments » - Posted on November, 30, 2006 at 11:35 pm

I recently bought a brand new Core2 Duo. With this new CPU I decided I would install the 64bit distribution of Gentoo onto a free partition I have on the current hard drive. This would allow me to then use my previous installation in 32bit mode if I needed to go back to my old setup.

So I downloaded the 2006.1 Gentoo live cd and whacked it in. Firstly, because of issues with motherboard makers not including native ATA devices on the board (just SATA to ATA converters), it could not detect the cd drive (which is funny because it’s booting off it….). This wasn’t too hard to fix, a trip to the Gentoo forums and the kernel line “all-generic-ide” and she booted sweet.

So the rest of the “live” experience is great – I have a fully functioning GUI and all sorts of other things I don’t need. A tty would have done me fine actually. Anyway, I decided to use the GTK+ installer to install my new Gentoo distro. I have previously installed Gentoo many times, but always by hand. So I tell it to reformat the hdk4 partition and install on there. I assumed it wouldn’t touch any of the others, and that everything would be hunky dory.

So I click the final button, and the installation process starts….”Resizing partitions” it says. Here’s me thinking “What the hell is it resizing? I didn’t tell it to resize…” and then bleep – “Error resizing ext2/ext3 partition”. The installation stops. There is no resume button. There is no restart button. I know for a fact that the only ext2 filesystem I have is the boot partition. I open up a terminal and check my partitions with good ol’ dependable fdisk…..1 partition. HOLY SHIT, IT’S WIPED MY PARTITIONS!

I work in software, so I realise that it’s hard to make things error free, but holy shit, this is MY system THEY just screwed. Thankfully I had backed up all my photos and music, so I didn’t lose anything, but I had a great little setup and it’s all gone.

I went to work the next day and angrily replayed the previous nights events to kindred souls. Fletch said sardonically “….How much did you pay for Gentoo again?”. I reckon he hit the nail on the head right there; I can’t expect people writing code in their back yard for fun (and writing install wizards doesn’t sound like fun to me) to knock something up that is professional, well tested and robust. There just isn’t the driver for it.

Some things are tried and tested, like fdisk, mkfs and tar (which is pretty much all you need for the manual installation) and then there is the bleeding edge GUI installer for my Mum. Gentoo is not meant for my Mum, and given the horrendous mess it made of my hard drive I don’t think they should even TRY to be more user friendly. Leave that up to Ubuntu, Suse and all the others. They already differentiate themselves with the whole “meant for computer dudes” thing, I say they should stick to their guns, and not try to keep up with what the “Mum distributions” are doing. Or if they DO go down that path, do it well instead of half arsed.

Females and Failures

Gender, Software - No Comments » - Posted on November, 15, 2006 at 3:22 am

Further to my rant the other day, I wonder if the shockingly high project failure rate in Software is in any way related to the shockingly low participation of females in the field. Is there some sort of relationship between lack of females and failure?

Sure, other disciplines of engineering have been around for a lot longer than Software, and due to social norms throughought the ages, they have been male dominated fields. So one could argue that it’s more due to the maturity of the field of engineering than to female participation rates.

But very few software projects actually fail because of technical issues. The majority of them fail because of miscommunication and mismanagement (aka requirements and schedule). Women are in general good communicators, and I wonder if the rate of failures would be reduced by an increase in the number of female Software Engineers.

What happened to women in IT?

Gender, Software - 2 Comments » - Posted on November, 13, 2006 at 4:39 am

The only female Software Engineer in the department gave a very interesting talk the other day on how the two genders differ when attempting to communicate. Do women in IT need to communicate in the male way in order to be accepted? No, in fact apparently women who use male techniques are often seen as “bitches” because people don’t expect women to be direct/short/aggressive.

Anyway, I am digressing; after the talk I asked if this difference in communication technique could explain why there are little or no females in the IT industry. Is it that the few females who do attempt to get into the field are met with a solid wall of mis-communication and frustrated, drop out and do something with more of their own kind? This would create a self-perpetuating male dominated field.

One of the old timers at work piped up and said “it hasn’t always been that way”. In my Software Engineering degree, there were 30 dudes, and 3 girls. So certainly in MY time it’s been mostly males, but a bit of history….

  • Ada Lovelace wrote a description of the babbage engine and had the Ada language named after her.
  • Jean E. Sammet was on a comittee that created COBOL and was a lady who worked for 27 years at IBM during the 50’s 60’s and 70’s.
  • Betty Holberton was one of 6 programmers of the ENIAC system back in 1945.
  • More…

So certainly women were a part of it at the start, and if what this old timer was saying is true, there used to be a lot more women in the field 10-20 years ago. So my question is what the hell happened to them all? Is there actually any data showing that the rate of women in IT has decreased?

Futhermore if it isn’t a communication breakdown, or some sort of acceptance complex, is it a brain thing at all? Is it that the female mind doesn’t have the same part of the brain that enables us guys to enjoy programming a fruitful excercise? Or is it a social thing? That from an early age, subconsciously or not, we teach our little boys how to put together lego (which lends itself to programming) and our little girls how to dress barbie dolls (less relevance to programming), and are thus setting the wheels in motion to guide what they do in later life?