Hi all,
When thinking of posting this idea I already feel Adam’s or Sean’s breath in
my neck and reminding me of what stupid idea I might come up with.
The following code snippet is something I do very often:
This is just sudo code.
string function something(required struct stConfig) {
local.stTmp = arguments.stConfig.fileConfig.init;
stTmp.initPath = "/";
stTmp.initTimeStamp = true;
stTmp.initUseCounter = request.fileConfig.counter + 1;
}
The code really doesn’t make sense and I know one can write it by setting an
inline struct like this:
arguments.stConfig.fileConfig.init = {
initPath: "/",
initTimeStamp: true,
initUseCounter: request.fileConfig.counter + 1
};
But that is not the idea here. What I do in order to speed up the runtime
(and not having to resolve a multi-level struct is time consuming) and
readability (you can’t tell me that this is easier to read:
arguments.stConfig.fileConfig.init.initPath = “/”;
arguments.stConfig.fileConfig.init.initTimeStamp = true;
arguments.stConfig.fileConfig.init.initUseCounter =
request.fileConfig.counter + 1;
)
I tend to assign a long hierarchy of subkeys to a temporary variable (stTmp)
and then use only that one. But this seems kind of odd. So I remembered the
good old Delphi and GFABasic days where one could write a statement like
this:
with variable do {
.key = something;
}
What would you think of the following code instead of the above:
string function something(required struct stConfig) {
with(arguments.stConfig.fileConfig.init) {
.initPath = "/";
.initTimeStamp = true;
.initUseCounter = request.fileConfig.counter + 1;
}
}
Or somehow similar. That would immediately speed up the execution and the
writing of the code.