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.
Igal Sapir
Lucee Core Developer
Lucee.org
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/016001d052b0%24380ca960%24a825fc20%24%40lucee.org.
For more options, visit https://groups.google.com/d/optout.
in other words, let's say that before the assignment the init key points to a struct with the key "uniqueId". the inline construct will lose it. the original construct (the one you're trying to avoid) will keep it. what would the new construct do?
string function something(required struct stConfig) {
with(arguments.stConfig.fileConfig.init) {
.initPath = "/";
.initTimeStamp = true;
.initUseCounter = request.fileConfig.counter + 1;
}
}
also, would the proposed construct result in an atomic operation (like the inline struct) or not (like the original construct)?
In JS I often setup a struct to hold default values then use _extend() (in node, with client side I use jQuery's $.extend() method)
are you saying that defining inline structs is slower at runtime than the dot method?
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/38a8c910-c4dc-43d5-8e19-f650e50edcc8%40googlegroups.com.
Well it is just a shorthand notation to the following. And yes I agree that assigning a {} would replace the construct so it is unusable. But this code would be identical:
arguments.stConfig.fileConfig.init.initPath = "/";
arguments.stConfig.fileConfig.init.initTimeStamp = true;
arguments.stConfig.fileConfig.init.initUseCounter = request.fileConfig.counter + 1;
and
with(arguments.stConfig.fileConfig.init) {
.initPath = "/";
.initTimeStamp = true;
.initUseCounter = request.fileConfig.counter + 1;
}
Sincerely
Gert Franz
RASIA GmbH
Spittelgasse 7
5103 Moeriken-Wildegg
Email: ge...@rasia.ch
Skype: gert.franz
Phone Switzerland: +41 76 5680 231
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/54F0AC66.9060007%40lucee.org.
Igal Sapir
Lucee Core Developer
Lucee.org
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/018301d052bc%24686a9890%24393fc9b0%24%40rasia.ch.
No what I meant is that using this:
arguments.stConfig.fileConfig.init several times is slower than assigning it to a temporary variable stTmp and then use the short variable after that. Which is obvious because at runtime there have to be many evaluations taking place with the arguments notation instead of one with stTmp.
Sincerely
Gert Franz
RASIA GmbH
Spittelgasse 7
5103 Moeriken-Wildegg
Email: ge...@rasia.ch
Skype: gert.franz
Phone Switzerland: +41 76 5680 231
Von: lu...@googlegroups.com [mailto:lu...@googlegroups.com] Im Auftrag von Abram Adams
Gesendet: Freitag, 27. Februar 2015 19:24
An: lu...@googlegroups.com
Betreff: Re: [Lucee] Another idea
Interesting idea, if I follow what you are trying to demonstrate. Like Igal said, the behaviors are quite different and what it sounds like to me is you need something like an "extend" method. In JS I often setup a struct to hold default values then use _extend() (in node, with client side I use jQuery's $.extend() method). This merges the two without having to do "arguments.stConfig.fileConfig.init =" repeatedly.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/38a8c910-c4dc-43d5-8e19-f650e50edcc8%40googlegroups.com.
arguments.strConfig.fileConfig.init.append({
initPath: "/", initTimeStamp: true, initUseCounter: request.fileConfig.counter + 1
},true);
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/50591358-2423-4ce9-9f2c-2808989ba395%40googlegroups.com.
then given the fact that it doesn't add anything I personally will not use this construct.
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/771DE67F-0B9A-427D-8B2B-44EC28908A40%40corfield.org.
string function something(required struct stConfig) {
with(arguments.stConfig.fileConfig.init) {
.initPath = "/";
.initTimeStamp = true;
.initUseCounter = request.fileConfig.counter + 1;
}
}
Well for me (again personally) I don’t like to use additional variables. Hence. Every dump then could be full of temporary variables.
Sincerely
Gert Franz
RASIA GmbH
Spittelgasse 7
5103 Moeriken-Wildegg
Email: ge...@rasia.ch
Skype: gert.franz
Phone Switzerland: +41 76 5680 231
Von: lu...@googlegroups.com [mailto:lu...@googlegroups.com] Im Auftrag von Igal @ Lucee.org
Gesendet: Freitag, 27. Februar 2015 20:07
An: lu...@googlegroups.com
Betreff: Re: [Lucee] Another idea
as written very clearly in my statement, "I personally will not use".
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/54F0C050.6020504%40lucee.org.
Actually what I just wanted is a shorter notation for long deep structures.
Sincerely
Gert Franz
RASIA GmbH
Spittelgasse 7
5103 Moeriken-Wildegg
Email: ge...@rasia.ch
Skype: gert.franz
Phone Switzerland: +41 76 5680 231
Von: lu...@googlegroups.com [mailto:lu...@googlegroups.com] Im Auftrag von Jochem van Dieten
Gesendet: Freitag, 27. Februar 2015 20:14
An: lu...@googlegroups.com
Betreff: Re: [Lucee] Another idea
On Fri, Feb 27, 2015 at 6:09 PM, Gert Franz wrote:
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CABPCP-3X7-%3DzdOcrUKOniVqnYZjz6Vcr2Ffx2QdfyaK6O%2BO3ng%40mail.gmail.com.
I would echo Sean and say that the starting . looks weird.
with myObj {
.doSomething( args );
.key = someExternalFunc( .getSomething() ); // where .getSomething() returns a value from the current state of myObj after whatever .doSomething() did.
.doSomethingElse( moreArgs );
.andDoAnotherThing( stuff );
}
User = new model.User();
with User{
.firstName = rc.fname;
.lastName = rc.lname;
.closure = function(){
var fullName = .firstName & " " & .lastName;
return .doSomething( fullName );
};
.addPet( new model.Pet( type = "dog", name = "Rover" ) );
.addPet( new model.Pet( type = "cat", name = "Tom" ) );
.save();
}
In JS I often setup a struct to hold default values then use _extend() (in node, with client side I use jQuery's $.extend() method)in Lucee you can do the "jQuery.extend()" with ".append( required struct, boolean overwrite=true)".
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.
I'm against it.
They already deprecated the with statement in JS strict mode for good reasons.
It can get really confusing for human readers especially when they dont know in which scope of the scope chain the key is.
Let's have a look at the following example:
function foobar(foo, bar) {
with (bar) {
dump(foo);
}
}
If you forget to define foo in the passed object, you wont get an error but unexpected results.
According to my opinion we don't need a completely new statement to achieve this. How about self executing functions?
They can solve the problem as well:
(function (v) {
dump(v.name.first & " " & v.name.last);
}(variables.foobar.users.user.susi));
You could use this approach multiple ways.
Example of how it could be written in CFML:
--
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/5QzTC7MXmX0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/db3c8109-b958-40d6-b562-b87fba341463%40googlegroups.com.
Personally I would not prefer a closure approach
but a context approach much how transaction and lock work. They denote context and the syntax is not as verbose.
and the syntax is not as verbose.
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/ef6dda0c-04d5-4904-a6b6-55ad16cde83e%40googlegroups.com.
|
|
CONFIDENTIAL AND PRIVILEGED - This e-mail and any attachment is intended solely for the addressee, is strictly confidential and may also be subject to legal, professional or other privilege or may be protected by work product immunity or other legal rules. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. Pixl8 Interactive Ltd Registered in England. Registered number: 04336501. Registered office: 8 Spur Road, Cosham, Portsmouth, Hampshire, PO6 3EB |
I prefer the code block style syntax over a generic closure syntax. Feels cleaner and the intent of context within the braces is more obvious I think.
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/b9e6a111-fa30-4b9d-a973-199b9c3a3559%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAEYvUxkPrjKtFmNcwqk3gwMh32uZqFH0kthGoMVf0x2h45LZVw%40mail.gmail.com.
My issue with the closure approach is, that it is slower in execution.
While I basically agree with Adam I think it is good to know that one solution offers better performance over the other.