The original idea come about when I was doing a one off script that will get some data, check some stuff and write a response. Itās a script. Not going to become an app so I dont have to āscience the shit out of itā
As an aside, I tend to see parsing docs in the sense of
a) Pass data to object
b) Ask object to return a particular part of it
c) Profit
So in the script I could have just created it in a REPL and done my work and be done with it. But I had to create a new file, (I know, such labours) but with that it exited the REPL scenario. And it wasnāt a nice little script to do X.
In Java you CAN define inline objects, but they have to implement another class which in CFML is useless and un-required. Interfaces work in IDEās and compile time, and CFML has neither of those.
I like @adam_cameronās suggestion, which is how I should have gone about it before, so itās more closure type (and of course only available after instantiation, which is fine)
I also like the idea of being able to have inner components/classes within CFCās . I can see use-cases, for example the base components , such as HTTP and Query, in lucee all need a Result object. It is never used by anything else and is 100% only related to that component. No one should be calling or using it (ok, itās consumed when returned, but that is another story)
With regards to access: it should be limited to the file they are created in basically.
With regards to making code messier: pfft. Too late. People will manage to make messy code out of anything.
Other usecases I can think of are of overriding classes at runtime (you can do that already of course) but it would be a nice feature to see the whole code within one editor window.
An example (from where I had this idea from):
<cfscript>
//Parse incoming requests
Reqs = DirectoryList(Expandpath("."), false,"array", "*.json");
for(f in Reqs)
{
result = new component(Fileread(f)) accessors=true {
property name="result";
function init(result){
this.result = DeSerializeJSON(arguments.result);
return this;
}
function getUserName(){
return this.result.pull_request.user.login;
}
...
};
username = result.getUserName();
otherPullRequests = result.getPullRequests();
}
//Do something with the username
</cfscript>
I hope this has helped to get some background on a simple idea.
Also with regards to the naming of the components, in opposition of @adam_cameron 's idea of inline creation, itās the idea of being to shove all the components at the bottom and then use them as named items. In the same way you can use functions (they automatically get moved to the top at compile time), so you can create multiple instances within your script.
Anyway, just an idea.