G'day:
Apropos of not much, here's a badly exposed photo of the cf.objective() bods who have come along to the Twins v Red Sox game:
What a very very shady bunch they are.
We're currently sitting at the bar at the game. Great fun, great new friends, great conference.
Time for another pint...
--
Adam
Adam Cameron's ColdFusion Blog
Sunday, 19 May 2013
Saturday, 18 May 2013
Another Railo feature for developers: linked structs
G'day:
This extends from my article about a Railo enhancement to replace(), yesterday.
One of the things I observed about the new replace() feature is that given it takes a struct to map its replace-tokens with its replace values, one cannot guarantee which order the replacements are made. This is because structs have no sense of order in their keys, so one ought not infer one or write any code which depends on a sense of ordering in the struct. Here's an example of what I mean:
This results in:
last
second
initial
two
one
three
Note that the key-ordering that comes out when looping is not the same as the order they went in. Also note if one uses <cfdump>, then one gets a false sense of ordering, because internall dump alphabetises the keys:
So - in theory - one can't pass a struct with a set of tokens that need to be processed in sequence to replace() because the sequence won't necessarily be respected. I say "in theory", because as far as I can tell Railo magically does remember the sequence keys were added to a struct when said struct is used in a call to replace(). Here's a tweaked version of that code:
Output:
last
second
initial
two
one
three
What flummoxes me slightly is that the loop over the keys outputs them in one order, however the replace() operation uses them in a different order (and that order is that which they were created in the struct). This is convenient, but it ought to be nothing more than coincidence. Especially for what I am trying to write about in this article...
So, yeah... um... the ordering of keys in a struct is not guaranteed, which can be inconvenient at times. Railo solves this by having different types of structs that one can use, one of which maintains key ordering.
In Railo one can do this:
Note there are three types of struct one can create. The "normal" one we know about, but "linked" and "weak" are explained as follows:
(copied from the Railo Google Group... I cannot find the actual documentation for these).
So that's quite cool. I'm just focusing on the "linked" option here (maybe I'll do the "weak" one in a different article).
Have a look at the difference between a "normal" and "linked" structs:
This results in:
SECOND
INITIAL
SECOND
LAST
Note how in the "linked" example, the key-order is maintained. This is great!
One interesting thing though, look at this:
Output:
I was kinda expecting them to be different types. I guess the difference is hidden away within the instance of StructImpl, which makes sense now that I think about it.
One last thing that I noticed when plugging a linked struct through ClassViewer, I noticed this:
/*** FIELDS ***/
public static final int TYPE_WEAKED
public static final int TYPE_LINKED
public static final int TYPE_SYNC
public static final int TYPE_REGULAR
public static final int TYPE_SOFT
So it seems there a coupla other types of struct one can use too: sync and soft. Google can't find any docs for these, but I'll hunt some out and have a look at them later.
That's it. I oughta be paying attention to the presentation I'm sitting in.
--
Adam
This extends from my article about a Railo enhancement to replace(), yesterday.
One of the things I observed about the new replace() feature is that given it takes a struct to map its replace-tokens with its replace values, one cannot guarantee which order the replacements are made. This is because structs have no sense of order in their keys, so one ought not infer one or write any code which depends on a sense of ordering in the struct. Here's an example of what I mean:
eg1 = {
initial = "one",
second = "two",
last = "three"
};
for (key in eg1){
writeOutput(key & "<br>");
}
writeOutput("<hr>");
eg2 = {
one = "one",
two = "two",
three = "three"
};
for (key in eg2){
writeOutput(key & "<br>");
}
This results in:
last
second
initial
two
one
three
Note that the key-ordering that comes out when looping is not the same as the order they went in. Also note if one uses <cfdump>, then one gets a false sense of ordering, because internall dump alphabetises the keys:
| Array | ||||||||||||||||
| 1 |
| |||||||||||||||
| 2 |
| |||||||||||||||
So - in theory - one can't pass a struct with a set of tokens that need to be processed in sequence to replace() because the sequence won't necessarily be respected. I say "in theory", because as far as I can tell Railo magically does remember the sequence keys were added to a struct when said struct is used in a call to replace(). Here's a tweaked version of that code:
eg1 = {
initial = "second",
second = "last",
last = "final"
};
for (key in eg1){
writeOutput(key & "<br>");
}
original = "initial";
result = replaceNoCase(original, eg1);
writeDump([original, result]);
writeOutput("<hr>");
eg2 = {
one = "two",
two = "three",
three = "final"
};
for (key in eg2){
writeOutput(key & "<br>");
}
original = "one";
result = replaceNoCase(original, eg2);
writeDump([original, result]);
Output:
last
second
initial
| Array | |||
| 1 |
| ||
| 2 |
| ||
two
one
three
| Array | |||
| 1 |
| ||
| 2 |
| ||
What flummoxes me slightly is that the loop over the keys outputs them in one order, however the replace() operation uses them in a different order (and that order is that which they were created in the struct). This is convenient, but it ought to be nothing more than coincidence. Especially for what I am trying to write about in this article...
So, yeah... um... the ordering of keys in a struct is not guaranteed, which can be inconvenient at times. Railo solves this by having different types of structs that one can use, one of which maintains key ordering.
In Railo one can do this:
normal = structNew("normal");
linked = structNew("linked");
weak = structNew("weak");
Note there are three types of struct one can create. The "normal" one we know about, but "linked" and "weak" are explained as follows:
structNew("linked")
The order of the keys in the struct is guaranteed.
see also:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedHashMap.html
structNew("weak")
The content of the might be flushed by the garbage collector. Weak
structures can perfectly be used as caches. In case of a memory
emergency the JRE garbage collector removes elements of weak structures
with a higher priority.
see also:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/WeakReference.html
(copied from the Railo Google Group... I cannot find the actual documentation for these).
So that's quite cool. I'm just focusing on the "linked" option here (maybe I'll do the "weak" one in a different article).
Have a look at the difference between a "normal" and "linked" structs:
writeOutput("<h2>Normal</h2>");
normal = structNew("normal");
normal.initial = "one";
normal.second = "two";
normal.last = "three";
for (key in normal){
writeOutput(key & "<br>");
}
dump([
{dump=normal},
{keyarray=structKeyArray(normal)}
]);
writeOutput("<hr>");
writeOutput("<h2>Linked</h2>");
linked = structNew("linked");
linked.initial = "one";
linked.second = "two";
linked.last = "three";
for (key in linked){
writeOutput(key & "<br>");
}
dump([
{dump=linked},
{keyarray=structKeyArray(linked)}
]);
writeOutput("<hr>");
This results in:
Normal
LASTSECOND
INITIAL
| Array | |||||||||||||||||||||
| 1 |
| ||||||||||||||||||||
| 2 |
| ||||||||||||||||||||
Linked
INITIALSECOND
LAST
| Array | |||||||||||||||||||||
| 1 |
| ||||||||||||||||||||
| 2 |
| ||||||||||||||||||||
Note how in the "linked" example, the key-order is maintained. This is great!
One interesting thing though, look at this:
original = structNew();
normal = structNew("normal");
linked = structNew("linked");
weak = structNew("weak");
literal = {};
dump([
{original=original.getClass().getName()},
{normal=normal.getClass().getName()},
{linked=linked.getClass().getName()},
{weak=weak.getClass().getName()},
{literal=literal.getClass().getName()}
]);
Output:
| Array | ||||||||
| 1 |
| |||||||
| 2 |
| |||||||
| 3 |
| |||||||
| 4 |
| |||||||
| 5 |
| |||||||
I was kinda expecting them to be different types. I guess the difference is hidden away within the instance of StructImpl, which makes sense now that I think about it.
One last thing that I noticed when plugging a linked struct through ClassViewer, I noticed this:
/*** FIELDS ***/
public static final int TYPE_WEAKED
public static final int TYPE_LINKED
public static final int TYPE_SYNC
public static final int TYPE_REGULAR
public static final int TYPE_SOFT
So it seems there a coupla other types of struct one can use too: sync and soft. Google can't find any docs for these, but I'll hunt some out and have a look at them later.
That's it. I oughta be paying attention to the presentation I'm sitting in.
--
Adam
Friday, 17 May 2013
OK, another handy new Railo feature
G'day:
I have some downtime @ cf.Objective() at the mo', so looking at some of the stuff Gert showed us in his presentation. It's that or have a beer... but it's perhaps slightly too early for that. Maybe... hmmm. Anyway, whilst I mull over having a beer, I have this article in my head, so I'll type it in.
I have some downtime @ cf.Objective() at the mo', so looking at some of the stuff Gert showed us in his presentation. It's that or have a beer... but it's perhaps slightly too early for that. Maybe... hmmm. Anyway, whilst I mull over having a beer, I have this article in my head, so I'll type it in.
Enhancement to replace() in Railo 4.1
G'day:
Gert Franz has just given a very impressive presentation on some new features Railo has added in 4.0 and 4.1. There's too many to go through, but here's one that interested me.
In Railo, the replace() function can now take a struct containing key/value pairs which represent the substitution tokens / values to replace. EG:
Gert Franz has just given a very impressive presentation on some new features Railo has added in 4.0 and 4.1. There's too many to go through, but here's one that interested me.
In Railo, the replace() function can now take a struct containing key/value pairs which represent the substitution tokens / values to replace. EG:
cf.Objective() day 1 - brain dump
G'day:
OK, I'm fed up with staring at the ceiling fr the last 3h since I woke up around 4:30am (or "9:30am, you lazy bastard, get up" as my still-UK-homed brain was telling me), so I'll knock out a quick article on my thoughts on yesterday's Day 1 of cf.Objective().
OK, I'm fed up with staring at the ceiling fr the last 3h since I woke up around 4:30am (or "9:30am, you lazy bastard, get up" as my still-UK-homed brain was telling me), so I'll knock out a quick article on my thoughts on yesterday's Day 1 of cf.Objective().
Tuesday, 14 May 2013
Improving ColdFusion CFML's OO-ness
G'day:
This has probably done the rounds before, but it's just put itself back within my sphere of attention, so I thought I'd mention it. It's also a good quick article to write from bed as I desperately try to ditch a cold I picked up in Ireland; before I have to sit on a plane for 9h tomorrow, to get to cf.Objective() (cue: sympathetic violins). I'm buggered if I'm gonna be hamstrung in my networking (read: beer consumption and general revelry) by a bloody sniffle.
Anyway, I just raise an enhancement request (3559652) for ColdFusion, thus:
This has probably done the rounds before, but it's just put itself back within my sphere of attention, so I thought I'd mention it. It's also a good quick article to write from bed as I desperately try to ditch a cold I picked up in Ireland; before I have to sit on a plane for 9h tomorrow, to get to cf.Objective() (cue: sympathetic violins). I'm buggered if I'm gonna be hamstrung in my networking (read: beer consumption and general revelry) by a bloody sniffle.
Anyway, I just raise an enhancement request (3559652) for ColdFusion, thus:
Saturday, 11 May 2013
Interface inheritance what one can and what one cannot do
G'day:
Today's article is brought to you via my baby netbook, as I sit on my bed in my hotel room in Portumna, Co. Galway in the the Republic of Ireland. My ex-wife and my son (25-months-old) live in Portumna, and this is why I pop across to Ireland every two or three weeks (you might have heard me mention it on Twitter or elsewhere). I get to see my boy for four hours on Sat and Sun, every - as I said - 2-3wks. This sux, but that's the way it is.
I only have internet here if I go sit halfway down the stairs, and despite that being doable as I'm the only guest here this weekend, it's a bit cold for that today. So I'm writing this article without the benefit of docs or fact checking! Wish me luck. Or enjoy picking apart whatever it is I end up getting wrong. Heh: in reality I will check everything before I publish... the internet works in the bar downstairs, so I'll proof-read and publish over an early evening Guinness.
Today's article is brought to you via my baby netbook, as I sit on my bed in my hotel room in Portumna, Co. Galway in the the Republic of Ireland. My ex-wife and my son (25-months-old) live in Portumna, and this is why I pop across to Ireland every two or three weeks (you might have heard me mention it on Twitter or elsewhere). I get to see my boy for four hours on Sat and Sun, every - as I said - 2-3wks. This sux, but that's the way it is.
I only have internet here if I go sit halfway down the stairs, and despite that being doable as I'm the only guest here this weekend, it's a bit cold for that today. So I'm writing this article without the benefit of docs or fact checking! Wish me luck. Or enjoy picking apart whatever it is I end up getting wrong. Heh: in reality I will check everything before I publish... the internet works in the bar downstairs, so I'll proof-read and publish over an early evening Guinness.
Subscribe to:
Posts (Atom)