Re: A code style question
Shorter still: switch (the platform) case “MacOS” ; put Finder into tReference ; break case “Win32” ; put Explorer into tReference ; break default ; put Desktop into tReference end switch You don’t need a break after default. :-) Bob S On Jan 22, 2015, at 24:08 , René Micout rene.mic...@numericable.commailto:rene.mic...@numericable.com wrote: Easier (clear) / shorter : switch (the platform) case “MacOS” ; put Finder into tReference ; break case “Win32” ; put Explorer into tReference ; break default ; put Desktop into tReference ; break end switch ;-) René ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
Thank you Bob ! :-) René Le 23 janv. 2015 à 23:22, Bob Sneidar bobsnei...@iotecdigital.com a écrit : Shorter still: switch (the platform) case “MacOS” ; put Finder into tReference ; break case “Win32” ; put Explorer into tReference ; break default ; put Desktop into tReference end switch You don’t need a break after default. :-) Bob S ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
Le 21 janv. 2015 à 18:54, Ken Ray k...@sonsothunder.com a écrit : easier/shorter then: switch (the platform) case MacOS put Finder into tReference break case Win32 put Explorer into tReference break default put Desktop into tReference break end switch Easier (clear) / shorter : switch (the platform) case “MacOS” ; put Finder into tReference ; break case “Win32” ; put Explorer into tReference ; break default ; put Desktop into tReference ; break end switch ;-) René ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
On Jan 21, 2015, at 9:54 AM, Ken Ray k...@sonsothunder.com wrote: I use a similar inline switch: put stsSwitch(the platform,MacOS=Finder,Win32=Explorer,*=Desktop) into tReference One line can accomplish that even without invoking a custom function: put item itemOffset( the platform, MacOS,Win32 ) + 1 of Desktop,Finder,Explorer into tReference -- Dick ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
On Thu, Jan 22, 2015 at 1:42 PM, Ben Rubinstein benr...@cogapp.com wrote: Sorry, I've only just realised as I was about to press send that the point you were making was that if it was built-in, then it also wouldn't need to evaluate both outcomes. Good point - though I'd personally still tend to restrict the use to constants or very simple expressions. Agreed that there's the potential for complexity abuse for something like this. The evaluation aspect could come up even in simple situations like: set the left of some control to iff(exists(some other control),the left of some other control,default value) ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
On 21/01/2015 15:53, Geoff Canyon wrote: the obvious drawback of the way it is now is that both outcomes have to be evaluated, where in an if statement, obviously, only one of them is. True, but (coding style preference) I tend to use it pretty much only for constants. If there's a complex expression in there, I prefer to split it out onto lines where there's more whitespace around the expressions to help future-me comprehend the code! Of course there's a speed penalty to using a function in this way (though there wouldn't be if it was built in*) - generally I'm using it to make the code more readable, to avoid the eye+mind tripping over a big expression that's only doing a simple thing, when it will be more comprehensible as e.g. set the spotcolour to ifte(status=good,green,red) To my mind, that makes it more obvious how limited this issue is - I can quickly see that this is just about setting red or green according to the status - whereas the five line if status = good then set the spotcolour to green else set the spotcolour to red end if forces me to read it more carefully to check whether there are other actions being taken depending on the condition, whether it's the same property being set in both, etc. Ben *Sorry, I've only just realised as I was about to press send that the point you were making was that if it was built-in, then it also wouldn't need to evaluate both outcomes. Good point - though I'd personally still tend to restrict the use to constants or very simple expressions. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
I was thinking of doing a switch version, so thanks! On Wed, Jan 21, 2015 at 11:54 AM, Ken Ray k...@sonsothunder.com wrote: local baseID function baseID newID put iff(validID(newID),newID, \ iff(validID(baseID), baseID,this card)) into baseID return baseID end baseID3 Of course you could reduce it one step further: function baseID newID return iff(validID(newID),newID, \ iff(validID(baseID), baseID,this card)) end baseID3 I use a similar inline switch: put stsSwitch(the platform,MacOS=Finder,Win32=Explorer,*=Desktop) into tReference easier/shorter then: switch (the platform) case MacOS put Finder into tReference break case Win32 put Explorer into tReference break default put Desktop into tReference break end switch For anyone interested, here’s the code: function stsSwitch -- does a quick inline switch/case; separate multiple matches with a comma -- param 1 is checkValue -- params 2+ is in the form matchValue(s)=returnValue; if there is a match to one -- or more items in matchValue(s), return returnValue -- otherwise empty is returned (unless a matchValue is *, in which case return the associated value) put param(1) into tCheckValue set the itemDel to = put into tDefault repeat with x = 2 to the paramCount put param(x) into tCheck put item 1 of tCheck into tMatch put item 2 of tCheck into tRetVal replace , with = in tMatch if tCheckValue is among the items of tMatch then return tRetVal if tMatch = * then if tRetVal = * then put tCheckValue into tDefault else put tRetVal into tDefault end if end if end repeat return tDefault end stsSwitch :D Ken Ray Sons of Thunder Software, Inc. Email: k...@sonsothunder.com applewebdata://52553A11-C1AF-4926-9DEF-C77D655DC26B/k...@sonsothunder.com Web Site: http://www.sonsothunder.com/ http://www.sonsothunder.com/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
local baseID function baseID newID put iff(validID(newID),newID, \ iff(validID(baseID), baseID,this card)) into baseID return baseID end baseID3 Of course you could reduce it one step further: function baseID newID return iff(validID(newID),newID, \ iff(validID(baseID), baseID,this card)) end baseID3 I use a similar inline switch: put stsSwitch(the platform,MacOS=Finder,Win32=Explorer,*=Desktop) into tReference easier/shorter then: switch (the platform) case MacOS put Finder into tReference break case Win32 put Explorer into tReference break default put Desktop into tReference break end switch For anyone interested, here’s the code: function stsSwitch -- does a quick inline switch/case; separate multiple matches with a comma -- param 1 is checkValue -- params 2+ is in the form matchValue(s)=returnValue; if there is a match to one -- or more items in matchValue(s), return returnValue -- otherwise empty is returned (unless a matchValue is *, in which case return the associated value) put param(1) into tCheckValue set the itemDel to = put into tDefault repeat with x = 2 to the paramCount put param(x) into tCheck put item 1 of tCheck into tMatch put item 2 of tCheck into tRetVal replace , with = in tMatch if tCheckValue is among the items of tMatch then return tRetVal if tMatch = * then if tRetVal = * then put tCheckValue into tDefault else put tRetVal into tDefault end if end if end repeat return tDefault end stsSwitch :D Ken Ray Sons of Thunder Software, Inc. Email: k...@sonsothunder.com applewebdata://52553A11-C1AF-4926-9DEF-C77D655DC26B/k...@sonsothunder.com Web Site: http://www.sonsothunder.com/ http://www.sonsothunder.com/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
I believe dBase/Foxpro had an iif function. That is because they also had an if control structure command and the compiler needed to discern between the two. Bob S On Jan 21, 2015, at 07:15 , Ben Rubinstein benr...@cogapp.com wrote: On 21/01/2015 01:58, J. Landman Gay wrote: On 1/20/2015 7:33 PM, Geoff Canyon wrote: The nested if statements in the first one, and the duplicated set the baseID of this stack to this card offend my eye. There's two of us then. Me three. Also I was glad to see you also have a reflex of defining function iff X,T,F if X then return T else return F end iff (I usually name my version ifthenelse - I like the conciseness of yours, but I studied logic some decades ago, so for me iff is already a word, and it means something different - if and only if.) I don't we think should be proposing fundamental additions to the language very often, but this is such a useful one that I think it should be considered. What do you think? Ben ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
I know iff means in-and-only-if, but I have a habit of taking things that are not functions and making them into functions by appending an f so I went with it. I agree that it would be a very useful thing to have -- the obvious drawback of the way it is now is that both outcomes have to be evaluated, where in an if statement, obviously, only one of them is. On Wed, Jan 21, 2015 at 9:15 AM, Ben Rubinstein benr...@cogapp.com wrote: On 21/01/2015 01:58, J. Landman Gay wrote: On 1/20/2015 7:33 PM, Geoff Canyon wrote: The nested if statements in the first one, and the duplicated set the baseID of this stack to this card offend my eye. There's two of us then. Me three. Also I was glad to see you also have a reflex of defining function iff X,T,F if X then return T else return F end iff (I usually name my version ifthenelse - I like the conciseness of yours, but I studied logic some decades ago, so for me iff is already a word, and it means something different - if and only if.) I don't we think should be proposing fundamental additions to the language very often, but this is such a useful one that I think it should be considered. What do you think? Ben ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
On 21/01/2015 01:58, J. Landman Gay wrote: On 1/20/2015 7:33 PM, Geoff Canyon wrote: The nested if statements in the first one, and the duplicated set the baseID of this stack to this card offend my eye. There's two of us then. Me three. Also I was glad to see you also have a reflex of defining function iff X,T,F if X then return T else return F end iff (I usually name my version ifthenelse - I like the conciseness of yours, but I studied logic some decades ago, so for me iff is already a word, and it means something different - if and only if.) I don't we think should be proposing fundamental additions to the language very often, but this is such a useful one that I think it should be considered. What do you think? Ben ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
A slightly corrected/modified version. To set the baseID: set the baseID of this stack to baseID(newID) To get the baseID get the baseID of this stack. The function(s) then become function baseID newID if newID is empty then return baseID_newIDempty() else return baseID_newIDnotempty(newID) end if end baseID function baseID_newIDempty if not exists (the baseID of this stack) then return this card else return the baseID of this stack end if end baseID_newIDempty function baseID_newIDNotEmpty newid if exists newID then return newID else return this card end if end baseID_newIDNotEmpty Pete lcSQL Software http://www.lcsql.com Home of lcStackBrowser http://www.lcsql.com/lcstackbrowser.html and SQLiteAdmin http://www.lcsql.com/sqliteadmin.html On Tue, Jan 20, 2015 at 8:45 AM, Peter Haworth p...@lcsql.com wrote: I'd go with the first one. The second one makes my eyes glaze over! Plus I think there should be an else before the second if in the second function. I might consider something like this. function baseID newID if newID is empty then baseID_newIDempty else baseID_newIDnotempty end if Return the baseID of this stack end baseID The two subsidiary handlers would have the logic from your first function for empty/not empty. Pete lcSQL Software It would be good to post code that works: function baseID newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if newID is not empty then set the baseID of this stack to newID return the baseID of this stack end baseID ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
I'd go with the first one. The second one makes my eyes glaze over! Plus I think there should be an else before the second if in the second function. I might consider something like this. function baseID newID if newID is empty then baseID_newIDempty else baseID_newIDnotempty end if Return the baseID of this stack end baseID The two subsidiary handlers would have the logic from your first function for empty/not empty. Pete lcSQL Software It would be good to post code that works: function baseID newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if newID is not empty then set the baseID of this stack to newID return the baseID of this stack end baseID ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
It would be good to post code that works: function baseID newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if newID is not empty then set the baseID of this stack to newID return the baseID of this stack end baseID ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
The first is slightly faster, but they don't return the same result - running the code below I always get: 6 8 false this card 1000 Did I mess up the test somewhere? on mouseUp put 1000 into tIterations -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID1(1000) into r1 end repeat put the millisecs - t into t1 -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID2(1000) into r2 end repeat put the millisecs - t into t2 -- put t1 t2 (r1=r2) cr r1 r2 end mouseUp function baseID1 newID if newID is empty then if not exists(the baseID of this stack) then set the baseID of this stack to this card end if else if exists( newID) then set the baseID of this stack to newID else set the baseID of this stack to this card end if end if return the baseID of this stack end baseID1 function baseID2 newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then\ set the baseID of this stack to this card if newID is not empty then set the baseID of this stack to newID return the baseID of this stack end baseID2 -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
okay, I think this is correct for both versions (gah) function baseID newID if newID is empty then if not exists (the baseID of this stack) then set the baseID of this stack to this card end if else if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then set the baseID of this stack to newID else set the baseID of this stack to this card end if end if return the baseID of this stack end baseID function baseID newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then \ set the baseID of this stack to newID return the baseID of this stack end baseID ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
Thanks for the fix. Once I took care of the email line wrap it ran well. The first version is still slightly faster, and to my eye more readable, so I'd go with that. on mouseUp put 1000 into tIterations -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID1(1000) into r1 end repeat put the millisecs - t into t1 -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID2(1000) into r2 end repeat put the millisecs - t into t2 -- put t1 t2 (r1=r2) cr r1 r2 end mouseUp function baseID1 newID if newID is empty then if not exists (the baseID of this stack) then set the baseID of this stack to this card end if else if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then set the baseID of this stack to newID else set the baseID of this stack to this card end if end if return the baseID of this stack end baseID1 function baseID2 newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then \ set the baseID of this stack to newID return the baseID of this stack end baseID2 -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
I figured the first version would be faster, since it only checks each thing once, where the second version tests some booleans twice, but this isn't going to be called repeatedly, so maximum performance isn't an issue. I was more curious about the readability, because I thought I might be the odd one out here, and it seems I am. The nested if statements in the first one, and the duplicated set the baseID of this stack to this card offend my eye. Once I realized I needed to test for exists OR is among more than once I used a separate function for those. Along with an inline if function I already had, and switching from a stack property to a local, I came up with: local baseID function baseID newID put iff(validID(newID),newID, \ iff(validID(baseID), baseID,this card)) into baseID return baseID end baseID3 function iff X,T,F if X then return T else return F end iff function validID I return ((I is among the items of this card,card list,background list,stack list) or exists(I)) end validID Maybe not everyone's cup of tea, but clear to me. On Tue, Jan 20, 2015 at 1:14 PM, Richard Gaskin ambassa...@fourthworld.com wrote: Thanks for the fix. Once I took care of the email line wrap it ran well. The first version is still slightly faster, and to my eye more readable, so I'd go with that. on mouseUp put 1000 into tIterations -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID1(1000) into r1 end repeat put the millisecs - t into t1 -- set the baseID of this stack to empty put the millisecs into t repeat tIterations put baseID2(1000) into r2 end repeat put the millisecs - t into t2 -- put t1 t2 (r1=r2) cr r1 r2 end mouseUp function baseID1 newID if newID is empty then if not exists (the baseID of this stack) then set the baseID of this stack to this card end if else if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then set the baseID of this stack to newID else set the baseID of this stack to this card end if end if return the baseID of this stack end baseID1 function baseID2 newID if (newID is not empty and not exists(newID)) or \ (newID is empty and not exists(the baseID of this stack)) then \ set the baseID of this stack to this card if exists(newID) or \ newID is among the items of this card,card list,background list,stack list then \ set the baseID of this stack to newID return the baseID of this stack end baseID2 -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: A code style question
On 1/20/2015 7:33 PM, Geoff Canyon wrote: I was more curious about the readability, because I thought I might be the odd one out here, and it seems I am. The nested if statements in the first one, and the duplicated set the baseID of this stack to this card offend my eye. There's two of us then. I tend toward combining as many statements as possible too. But if a handler gets too snarly to grasp quickly, I pull it back apart. Yours was pretty snarly. :) -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode