Showing posts with label Duncan Cumming. Show all posts
Showing posts with label Duncan Cumming. Show all posts

Saturday 18 October 2014

PHP: getting AspectMock to work

First things first: Luis, Brad, everyone at Ortus Solutions: I bloody love you guys. Working with TestBox and MockBox is an absolute pleasure compared to getting their PHP equivalents installed and working properly.

Over the last coupla weeks, meself and Duncan have been investigating unit testing on PHP, and specifically how to mock dependencies. On our old CFML code base, we have 1000s of test, and we use MockBox heavily, as we have rather a lot of dependencies which interfere with testing if they're not mocked. We only ever really moved to TestBox as a proof-of-concept before our CFML codebase was put into maintenance mode, and we shifted to PHP. Prior to that we had been using MXUnit for a number of years.

PHPUnit is a bit rough-and-ready in comparison to TestBox, but it's solid and will do the trick. However we both had an arsehole of a time getting AspectMock to work. And we both failed and moved on to other things. Earlier I'd looked at Mockery as a solution for mocking - its docs are better than AspectMock's (both a recommendation for Mockery, and an indictment of AspectMock), but it did not do something things we expect to need to be doing, whereas AspectMock claims it can (mocking static methods).

Anyway, this afternoon I found myself furrowing my brow and thought "I'm going to get that bloody thing to work... or else". Fortunately after a lot of swearing and wondering if I can hunt down and punish AspectMock's author... I finally noticed what I had been doing wrong. I presume Duncan was doing the same thing wrong, but don't know. Anyway, I got it working.

So here's my AspectMock mission from this afternoon.

Saturday 11 October 2014

PHP: Inspired by Duncan: palindromes via generators

My mate Dunc is making a habit of being my muse @ the moment. I guess it's cos we're both learning PHP at the same time, and he's blogging about it as well. This morning he has a new article following his foray into translating his CFML (and Python occasionally) knowledge into PHP: "Project Euler: problem 36 (PHP)".

Friday 26 September 2014

PHP: another generator example: primes

Duncan has mused me again. He's reworking his Project Euler exercises that he'd previously done in CFML, and is now implementing in PHP. In yesterday's exercise he was looking at prime numbers: "Project Euler: problem 7 (PHP)". I thought there was scope for another exercise in using PHP generators in this for me (see previous: "PHP: generators").

Saturday 20 September 2014

PHP: generators

Duncan's my muse today. Like me, my mate Duncan has recently moved from our defunct CFML team to the PHP team. And like me, Dunc now needs to learn PHP. He's logging his progress as well, and if this sort of thing interests you (following our progress), then maybe keep an eye on what he's doing too.

Thursday 15 May 2014

Regarding regex: two things I'd like everyone to do

Today my mate / colleague Duncan Cumming is my muse. But - sorry Daddy Duncky - not in a good way.

There was a question on StackOverflow over night "Need regular expression to insert a numeric value between filename and extension?". Dunc's given a reasonable answer, but also perpetuated an old trope which seriously needs to be put to rest:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
Thanks for that, Jamie Zawinski. And also thanks to Peter Boughton for giving Duncan a smack down on this. Peter is probably the chief CFML-community regular expression guru I know. Yes: more so than Ben Nadel.

The thing is... using regexes isn't that hard. Obviously one can do some incredibly complicated and impenetrable with them, but this is the same as with any technology. But I think stupid (if slightly amusing, granted) quotes like the above have gone a long way to making regular expressions seem mystical and complex to people. It's not. It's just pattern matching. They're no where near as complex as the CFML programming logic we work with every day.

Monday 13 January 2014

Using "undocumented" methods

Today, my mate Duncan is my muse. That comment should make him feel pleasingly uncomfortable.

Dunc was revisiting some code, and he saw something along the lines of this (disclosure: it was my code):

numbers = queryNew("id,number", "integer,varchar", [[1,"tahi"],[2,"rua"],[3,"toru"],[4,"wha"]]);

while ({
    writeOutput("[numbers.currentRow]# #numbers.number[numbers.currentRow]# <br>");

Sunday 8 December 2013

CFML: For the sake of completeness: createLocalisedDayOfWeekAsInteger(): a closure approach

A coupla days ago I continued my TDD / unit testing series with an article "Unit Testing / TDD - refactoring existing code". This engendered a few comments, none of which paid any attention to the intent article, instead focused on something pretty much irrelevant to what I was discussing. This engendered this reaction from me:

Oh how I love my readership sometimes. But, actually, the comments got me thinking...

That article covered the approval process for CFLib of a function dayOfWeekAsInteger(), which is the reverse of dayOfWeekAsString(): it takes a string (in English only), and returns which day of the week that corresponds to, starting with Sunday as the first day. Why does it start on Sunday instead of Monday (as per ISO 8601)? Because it's the inverse of dayOfWeekAsString(), and that's how that does it. Is that right? Well: no. Is that relevant to either this UDF or the blog article? Also: no.

However James's suggestion for how Simon could rewrite his function to suit James's requirements (James: write your own functions if you want them different from how others have implemented them!) did get me thinking about how to do it. A thought popped into my head that one could leverage closure to create a function which was specific to a given locale. This might not be exactly what James wants, but it was what I decided to look into, because it's slightly interesting, and covers a feature of closure I've not covered anywhere on this blog yet. So it interests me.

Friday 23 August 2013


My mate Duncan did some research for me on the subject of date formats, as feedback to yesterday's article "Not every single string that can possibly be parsed as a date should be treated like a date!".

I had made this claim:
[...]there is not situation in which a string formatted as "xx/xx/xx" should be interpreted as a date "yy/mm/dd". No-one writes dates as "yy/mm/dd".

Well Duncan pointed me at this Wikipedia page: "Date format by country". Wikipedia seems to have pages for everything.

As it turns out there is a country in which the date format is "yy/mm/dd": Kenya. Who'd've known?

That said, I stand by my point. Not for the sake of pigheadedness (well not solely that ;-), but because "Kenyan" (or any approximation thereof) is not a locale that ColdFusion supports (according to the locales listed in server.coldfusion.supportedLocales, anyhow).

So in the context of CFML... there still really is no justification for ColdFusion to ever to consider the string "xx/xx/xx" as a date-parseable value representing the format "yy/mm/dd". For it to do so, IMO, is a bug: 3617365.


Thursday 18 July 2013


I'm a bit late with this as it happened a week or so ago, but I just noticed I've been prattling away on this blog for a year now.

Apropos of nothing, here's some mostly useless information about this blog.

I said in one of my earlier articles that I've learned more about ColdFusion since I started this blog than I had in the preceding few years. This continues to be the case, and I've learned a bunch of good stuff about Application.cfc, ColdFusion regexes, JSON (grumble), REST, interfaces (in general, as well as ColdFusion's inplementation of them), and various other odds 'n' sods. Even some web sockets stuff, whilst troubleshooting that security issue from a coupla weeks back. I've also used Railo a lot more, and had a look at Coldbox. Beyond ColdFusion I've also started dabbling with PHP and Ruby. It's been cool! I hope some of it was useful to you, or at least slightly interesting. Or killed some time whilst you tried to decipher what I was wittering on about.

To close, I'd like to say special thanks to a few people whose participation in this blog has been helpful, interesting or thought-provoking. In no particular order, and it's certainly not an exhaustive list:
  • Chris Kobrzak
  • Sean Corfield
  • Andrew Myers
  • Bruce Kirkpatrick
  • Brad Wood
  • Andrew Scott
  • Adam Tuttle
  • Ray Camden
  • Gavin Pickin
  • Jay Cunnington
  • Simon Baynes
  • Duncan Cumming
  • Brian Sadler
There's been a bunch of great input / correction / sanity-checking / bullshit-detection done by a heap of other people too.  Cheers to everyone who's participated here.

And now on to year 2...


Wednesday 19 December 2012

When functions do too much, and how to get them to do more

After soliciting more UDFs for CFLib a while ago, I've been dead slack at processing the inbound queue, and fixing some bugs people have found. Sorry about that. I started playing catch-up at lunchtime today: you might have noticed a coupla bugfixes bubbling through on Twitter if you follow the @cfbloggers feed.