Quick post about a Coldfusion oddity I came across this week, whilst attempting to use CF's built in StructCopy function.
Coldfusion has two primary mechanisms to clone a Struct (that's a map to Java folk): StructCopy() and Duplicate(). StructCopy is a shallow copy, where as Duplicate is a full blown deep copy - so if you are attempting to clone a complex nested struct then duplicate is probably the function for you (although, beware, as you may expect it comes with some performance penalty!).
What I actually wanted to do was clone the URL scope (which is for all intents and purposes is just a Struct of key/value pairs of query string params in the URL). I just wanted to clone the current URL scope struct of query params so I could alter the struct (add additional params etc) without actually affecting the URL scope (normal FP type stuff). As the URL scope is always just going to be a struct of String key/value pairs (Strings being immutable), I figured the shallow copy StructCopy function would do (the struct would always be a simple single level struct, and all key/values would be Strings - so any changes to them would not affect the original URL scope).
Oh no. It doesn't work.
To be fair to CF, the URL scope isn't a straight forward Struct - it is actually a Coldfusion URLScope object - but just masquerades as a Struct most of the time, writeDump()'ing it labels it as a Struct, passing it to a function that requires a Struct argument - no probs.
Here is some example code:
In the above scenario, after the structDelete - both Structs output as the same thing. The key "rob" has been removed from both Structs. Well actually, just the one. But actually the cloned struct isn't cloned at all, it's just the original URL scope again.
To me, that sucks. Really.
Like I said, I get that URL is not really a true struct, so I don't blame CF for not wanting to play nicely (although duplicate( url ) will work), but returning the URL structure? not cool.
There are a few options that I see can happen if CF doesn't want to StructCopy:
- Throw an exception. To me, this is the best option. Everyone knows where we are, and really it is an exception - if we are saying truly, that StructCopy cannot copy a URLScope object, then its an exception.
- Return an empty struct - not ideal, but again, forces handling of this potential - kind of StructCopy saying, look guys, I tried to copy but failed, so here's an empty struct.
In no circumstance is it cool to just silently return the URLScope object. Appearing to be working correctly (you get a what looks like a struct back, with all the same keys/values as your original struct, so all good right?) but actually providing the exact opposite functionality you actually want. Dangerous.
I was lucky that the code I was writing flagged up the errors immediately in an obvious fashion - but if you are cloning just to avoid an unusual edge-case, you may be in for an unpleasant suprise.
I'm not sure if we should be pleased with the UK Governments Year of Code or not. Sure, it's a train wreck, it has been a shambles in term of organisation and PR - sometimes in a spectacular fashion, like when the well connected but not so well informed "Director of Coding" appeared on Newsnight - and undoubtedly from what we have seen, it will be poorly executed.
But on the plus the initiative is there. The government have recognised the importance of the tech industry to the country and its economy, which has got to be a good thing?
Every now and then the Government suprises us, with positive, forward thinking iniatives such as David Cameron embracing and pushing Silicon Roundabout (London's answer to Silicon valley) and spending time and energy on pushing the tech agenda for the city and country, or their design principle guidelines. And I think this opportunity has a lot of potential.
Did Lottie Dexter (the founder/director of Year of Code) make an ass of herself on Newsnight? Sure. But that is really just about her being poorly prepared/thought through. Were her comments about learning to code in a day worrying and possibly betraying a deeper lack of understanding of the task at hand? Sure. But all she needs is people around her who do understand these things - I have no problem at all with Lottie Dexter not knowing how to code - it's a classic pattern of non-tech CEO and tech co-founders that has been common place in Silicon Valley for years. It's great for her saying she wants to learn to code, and its undoubtedly good PR for the initiative, but that should be all it is - PR. She is not the CTO or Head of Engineering or anything else vaguely tech related. And the good news is she has got a lot of smart tech folk on board, who will have a deep understanding of tech and code, take a look at some of the board:
The list goes on. A lot of smart tech folks.
Really though, I would have liked to have seen more. I would have liked to seen the government take a leaf out of Obama's book and just hand it over to the startup ecosystem altogether - Obama completely handed over his election campaign tech to a bunch of great tech startup guys and left them to it, and it turned out pretty great (that's a long read, but well worth it). Really incentive-ise and provide the means to startup folks to really be creative with some ideas. If there is an industry that is just waiting to be disrupted it's got to be education - and whilst the government won't be opening up the whole education system for innovation and disruption any time soon, these changes to the tech curriculum are a real opportunity to start testing the waters with alternative and innovative approaches to education and inspiring children to become life-long learners.
On the whole, it's a positive step. The government has recognised that the tech curriculum is important and have an initiative with lots of smart folks on board. The main concern I have is the tech curriculum and what happens with it - with all this emphasis on learning to code, and curiculums that get kids making e-cards. I have my doubts that coding or low level computing should be taught at primary school level. The best would probably be something like starting actual programming at comprehensive/secondary school level. If you want a good grounding in tech, teaching kids at primary school to create e-cards is probably not the way to do it. Teaching basic logic and reasoning would, in my oppinion, be a much better grounding. And I'm not talking Formal Logic, I mean just thinking through puzzles, thinking rationally to work things out. It may sound odd, but I would love to see us start teaching kids from a young age about logic and problem solving through play. Lego, Brio, etc. are great tools for learning to think logically, whilst also being creative
As a thought experiment, how about we give a bunch of primary school classes a Brio train set. Get kids in to teams, give them each a bunch of track and set the following objectives:
- Make a train track that uses all the pieces (give them lots of pieces, including the various track switching pieces and merging/splitting pieces)
- Design a track whereby every piece of track can be driven down in either direction without ever taking a train off the track (this is actually quite hard - I quite often find tracks I build with my son to end up with segments whereby once you take a particular junction you are destined to follow the same track route for ever)
- Move the teams around and get the kids to try and find flaws in the design as per the point above.
One exercise doesn't make a curriculum, but it's an approach - it takes rational thinking, team working, problem solving and hopefully, is engaging and fun. Getting children enjoying learning and problem solving is a good grounding for going on into tech - after all, being able to design train tacks to a particular specification and being able to identify flaws in them is not that much different from designing code - understanding the use of track switches and considering the different implications/paths of multiple switches/junctions is exactly the same as being able to understand and think through conditional routing through code but without the syntax. I might be missing something on this "design an e-card" curriculum, but Brio is already sounding a whole lot better.
The re-think of the tech curriculum offers an ideal opportunity to shake up the way we think about education and take a step away from traditional test-focused, memorising of information approach and a step towards a more engaging approach that also helps teach children the joys of learning.