Re: how to check for unnecessary local declarations?
Late to the party, but here's another approach (not fully tested). Iterate the function over the full list of stacks/cards/controls of your stacks. -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig --- function findUnusedLocals pObjRef -- returns a cr-delimited list of handlerName, tLocal --where tLocal is a declared local not used in the handler handlerName put the revAvailableHandlers of pObjRef into hList delete word 5 to -1 of line 1 of hList -- to cope with the odd format of revAvailableHandlers repeat for each line h in hList put word 1 to 2 of h into hName put caseSwitch(word 1 of hName,F=function,M=command,G=getprop,S=setprop,*=*) \ into tType put tType into word 1 of hName put getHandlerFromScript(pObjRef,word 2 of hName, tType) into thisHandler put thisHandler into theLocals filter theLocals withlocal * replacelocal with empty in theLocals replace comma space with cr in theLocals replace comma with cr in theLocals filter thisHandler withoutlocal * repeat for each line L in theLocals if L is among the words of thisHandler then next repeat put hName comma L cr after orphanedList end repeat end repeat delete char -1 of orphanedList return pObjRef cr orphanedList end findUnusedLocals function getHandlerFromScript pObjRef, pHandlerName, pType -- returns the specified handler from the script of pObjRef -- pHandlerName should be the bare name of the handler -- if you have duplicate handler names, eg, a function and a command with --the same name, or getprop and setprop handlers with the same name, --then both/all will be returned, unless you specify the optional pType -- as function or command or getprop or setprop -- if not found, returns no such handler: pType pHandlerName -- by Peter M. Brigham, pmb...@gmail.com — freeware, --based on a discussion on the use-LC list -- requires caseSwitch() put the script of pObjRef into tScript put the revAvailableHandlers of pObjRef into hList delete word 5 to -1 of line 1 of hList -- to cope with the odd format of revAvailableHandlers filter hList with * pHandlerName * -- now we have all lines with the handlerName put caseSwitch(pType,function=F,command=M,getprop=G,setprop=S,*=*) \ into tType if tType empty then -- get only the line with the correct type put cr before hList set the casesensitive to true replace cr P with cr in hList filter hList with tType * end if if hList = empty then put no such handler: pType pHandlerName into tError replacewith space in tError -- in case pType is empty return tError end if repeat for each line h in hList put line (word 3 of h) to (word 4 of h) of tScript cr cr after outScript end repeat delete char -2 to -1 of outScript return outScript end getHandlerFromScript function caseSwitch -- does a quick inline switch/case -- param 1 is checkValue -- params 2+ are in the form matchValue(s)=returnValue --separate multiple matchValues with commas --and enclose each matchValue=returnValue pair in quotes -- if checkValue matches one or more items in matchValue(s), --returns returnValue -- use a matchValue of * to specify a default value, --to be returned if no matches found in the list --if the default is *=* then no match returns the original checkValue --if no match and no default value specified, then returns empty -- examples: --put caseSwitch(len(tZip),5=zip,10=zip+4,*=not a zip code) \ -- into zipCodeType --put caseSwitch(item 1 of the abbr date,Sat,Sun=weekend,*=weekday) \ -- into dayType -- from Ken Ray, use-LC list, originally named stsSwitch() -- revised by Peter M. Brigham, pmb...@gmail.com --to allow for an empty checkValue, eg =no input --or ,4,5=other or 4,,5=other or 4,5,=other --meaning, if checkValue is 4 or 5 or empty, return other put param(1) into tCheckValue set the itemDel to = 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 -- to avoid having to switch itemdelimiters if tCheckValue = empty and tMatch = empty then return tRetVal if tCheckValue = empty and (char 1 of tMatch = = or char -1 of tMatch = = \ or == is in tMatch) then return tRetVal 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 return tDefault end if end repeat end caseSwitch
Re: how to check for unnecessary local declarations?
Thanks Mark. The code to get the script locals looks suspiciously like what I suggested. Are you sure Jerry didn’t use Jacques Time Travel stack to steal my code?? Bob S On Jul 3, 2015, at 11:53 , Mark Wieder mwie...@ahsoftware.net wrote: On 07/03/2015 11:11 AM, Peter Haworth wrote: Nice! Only thing I don't see is dealing with block comments - the things surrounded by /* and */ and possibly spanning several lines. There's some DRY cleanup that could be done as well. Feel free to make it better and submit the changes. It's all on bitbucket, and unfortunately it's a LiveCode stack rather than text files so you can't submit git pull requests, but drop me a note or create an issue. https://bitbucket.org/mwieder/glx2/wiki/Home -- Mark Wieder ahsoftw...@gmail.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: how to check for unnecessary local declarations?
On 07/03/2015 11:11 AM, Peter Haworth wrote: Nice! Only thing I don't see is dealing with block comments - the things surrounded by /* and */ and possibly spanning several lines. There's some DRY cleanup that could be done as well. Feel free to make it better and submit the changes. It's all on bitbucket, and unfortunately it's a LiveCode stack rather than text files so you can't submit git pull requests, but drop me a note or create an issue. https://bitbucket.org/mwieder/glx2/wiki/Home -- Mark Wieder ahsoftw...@gmail.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: how to check for unnecessary local declarations?
On 07/02/2015 08:20 PM, Kay C Lan wrote: Which proves the point that it isn't as easy as you first made out. As you say, cracking the GLX2 code is probably the easiest route to take and I'd be surprise if that code wasn't developed over a long period of time of 'discovering' odd edge cases cropping up here and there, that Jerry never envisage in a single session of coding. Well, here's the easy part from glx2: -- gather the script local variables function getLocals pScript local tTemp, tLocals filter pScript with local * repeat for each line tLine in pScript put word 2 to -1 of tLine cr after tTemp end repeat -- allow for multiple declarations in one line replace , with cr in tTemp repeat for each line tLine in tTemp put word 1 of tLine cr after tLocals end repeat chomp tLocals -- chomp is in the frontscript, removes trailing cr set the tLocals of this card to tLocals end getLocals -- here's the part that looks at usage (watch the lineWrap) --theHandler here could be the entire script of a single handler repeat for each line theLine in theHandler if word 1 to 3 of theLine is repeat for each then put word 5 of theLine into theWord if theTemps is empty then put theWord into theTemps else if theWord is not among the lines of theTemps then put cr theWord after theTemps end if end if next repeat end if if into is among the words of theLine or after is among the words of theLine or before is among the words of theLine or word 1 of theLine is repeat then put 0 into tWordNum repeat for each word theWord in theLine add 1 to tWordNum if char 1 of theWord is # or char 1 to 2 of theWord is -- then exit repeat end if if char 1 of theWord is quote then if theTemps is empty then put theWord into theTemps else if theWord is not among the lines of theTemps then put cr theWord after theTemps end if end if next repeat end if if theWord is among the items of each,with,into,after,before then put word tWordNum+1 of theLine into theNextWord if ( is in theNextWord then next repeat end if put token 1 of theNextWord into theNextWord if theNextWord is not among the lines of theTokens and theNExtWord is not empty then if [ is in theNextWord then replace [ with cr in theNextWord replace ] with in theNextWord end if if theTemps is empty then put theNextWord into theTemps else if theNextWord is not among the lines of theTemps then put cr theNextWord after theTemps end if end if end if end if end repeat end if end repeat -- Mark Wieder ahsoftw...@gmail.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: how to check for unnecessary local declarations?
Hi from Beautiful Brittany (where it is raining, and there is a cool breeze, while the rest of France is in the high 30’s :)) In the same vein, I declare all my variables “global in two ways ; the first which will remain when testing is finished (i.e.. passing info outside the script); the others which will be commented out after testing. If I return to this stack at a later date to modify it, I remove the comments until I have finished testing again. Whenever I “invent” a variable, I always declare it global, either permanent or temporary, and so I cannot end up have unused variables. Declaring all variables as global, especially when I have some math in my scripts, running step by step (debug mode) helps check out my math easily and efficiently. All my variable names begin with “GV or “LV” which helps me not to make mistakes. Its the stupid mistakes which add to development time. Oh ! I forgot ! I sleep little, and so during the night, I plan out my stack development, even to script layout, Next morning I code, and find that I have done much of the debugging in my head, diring the night. Anybody out there got any strange quirks like mine ? (more than 50 years of programming leaves deep scars …. !!!). -Francis ___ 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: how to check for unnecessary local declarations?
Which proves the point that it isn't as easy as you first made out. As you say, cracking the GLX2 code is probably the easiest route to take and I'd be surprise if that code wasn't developed over a long period of time of 'discovering' odd edge cases cropping up here and there, that Jerry never envisage in a single session of coding. On Fri, Jul 3, 2015 at 5:18 AM, Bob Sneidar bobsnei...@iotecdigital.com wrote: If you remove the asterisks, you would fail to find any code that uses the variable. Only lines containing *JUST* the variable name would be found, which wouldn’t work. You could add code to analyze the line by replacing “(“ and “) with space, then filter for “*” variableName “*”. Words at the end of the line would not be found however, so you would have to also filter for “*” variableName. Bob S On Jul 1, 2015, at 23:09 , Kay C Lan lan.kc.macm...@gmail.com wrote: Bob, I think you would need to remove the astrisks otherwise if you have single letter variables (many use them as counters in repeat loops) or words that may appear in other words - lStart, lStartSearch - you could easy miss some. On Thu, Jul 2, 2015 at 5:47 AM, Bob Sneidar bobsnei...@iotecdigital.com wrote: Seems you could write a handler to do it pretty easily. pseudocode — get stack script — find “local “ — get word 2 of found line — filter with “*” word 2 of found line “*” — count number of lines. if only 1 then delete that line — get list of cards — repeat for every card — get card script — what I just said — get list of objects on card — repeat for every object on card — get script of object — do I have to repeat myself again?? /pseudocode It might be a little more complicated if you have multiple local variable declarations, but not much. Bob S On Jul 1, 2015, at 06:44 , Tiemo Hollmann TB toolb...@kestner.de wrote: Hello, I am using the strict compilation mode. When working over longer time on a project it regularly happens that I have orphaned local variable declarations. Actually they don't hurt, but I like to keep my code clean and wonder if there is any hidden feature, which checks for not any more needed local declarations (beside scripting a check myself)? Thanks Tiemo ___ 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 ___ 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 ___ 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: how to check for unnecessary local declarations?
Francis Nugent Dixon wrote: I sleep little, and so during the night, I plan out my stack development, even to script layout, Next morning I code, and find that I have done much of the debugging in my head, during the night. Anybody out there got any strange quirks like mine ? I've had surprisingly good luck with that myself. -- 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: how to check for unnecessary local declarations?
Globals are problematic for me as I design stacks and cards to be modular, so two stacks with the same utility card for example, would be sharing globals. Instead, if I need persistent data, I use properties. I also do not use strict compilation. I have a naming system that prevents my ever using the same variable twice for different things in the same handler. Even in loops that use a counter, the counter variable is very specifically named. That being said, it occurs to me that the GLX2 script editor knows what is a variable because it color codes them, and also keeps track of them for the clairvoyance feature. Crack that code open to see how they do it, and that should give you a great way of tracking them yourself. Bob S On Jul 2, 2015, at 03:20 , Francis Nugent Dixon effe...@wanadoo.fr wrote: Hi from Beautiful Brittany (where it is raining, and there is a cool breeze, while the rest of France is in the high 30’s :)) In the same vein, I declare all my variables “global in two ways ; the first which will remain when testing is finished (i.e.. passing info outside the script); the others which will be commented out after testing. If I return to this stack at a later date to modify it, I remove the comments until I have finished testing again. Whenever I “invent” a variable, I always declare it global, either permanent or temporary, and so I cannot end up have unused variables. Declaring all variables as global, especially when I have some math in my scripts, running step by step (debug mode) helps check out my math easily and efficiently. All my variable names begin with “GV or “LV” which helps me not to make mistakes. Its the stupid mistakes which add to development time. Oh ! I forgot ! I sleep little, and so during the night, I plan out my stack development, even to script layout, Next morning I code, and find that I have done much of the debugging in my head, diring the night. Anybody out there got any strange quirks like mine ? (more than 50 years of programming leaves deep scars …. !!!). -Francis ___ 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: how to check for unnecessary local declarations?
If you remove the asterisks, you would fail to find any code that uses the variable. Only lines containing *JUST* the variable name would be found, which wouldn’t work. You could add code to analyze the line by replacing “(“ and “) with space, then filter for “*” variableName “*”. Words at the end of the line would not be found however, so you would have to also filter for “*” variableName. Bob S On Jul 1, 2015, at 23:09 , Kay C Lan lan.kc.macm...@gmail.com wrote: Bob, I think you would need to remove the astrisks otherwise if you have single letter variables (many use them as counters in repeat loops) or words that may appear in other words - lStart, lStartSearch - you could easy miss some. On Thu, Jul 2, 2015 at 5:47 AM, Bob Sneidar bobsnei...@iotecdigital.com wrote: Seems you could write a handler to do it pretty easily. pseudocode — get stack script — find “local “ — get word 2 of found line — filter with “*” word 2 of found line “*” — count number of lines. if only 1 then delete that line — get list of cards — repeat for every card — get card script — what I just said — get list of objects on card — repeat for every object on card — get script of object — do I have to repeat myself again?? /pseudocode It might be a little more complicated if you have multiple local variable declarations, but not much. Bob S On Jul 1, 2015, at 06:44 , Tiemo Hollmann TB toolb...@kestner.de wrote: Hello, I am using the strict compilation mode. When working over longer time on a project it regularly happens that I have orphaned local variable declarations. Actually they don't hurt, but I like to keep my code clean and wonder if there is any hidden feature, which checks for not any more needed local declarations (beside scripting a check myself)? Thanks Tiemo ___ 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 ___ 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
how to check for unnecessary local declarations?
Hello, I am using the strict compilation mode. When working over longer time on a project it regularly happens that I have orphaned local variable declarations. Actually they don't hurt, but I like to keep my code clean and wonder if there is any hidden feature, which checks for not any more needed local declarations (beside scripting a check myself)? Thanks Tiemo ___ 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
AW: how to check for unnecessary local declarations?
I am talking only about locals WITHIN a handler. -Ursprüngliche Nachricht- Von: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] Im Auftrag von Tiemo Hollmann TB Gesendet: Mittwoch, 1. Juli 2015 15:45 An: LiveCode User Liste senden Betreff: how to check for unnecessary local declarations? Hello, I am using the strict compilation mode. When working over longer time on a project it regularly happens that I have orphaned local variable declarations. Actually they don't hurt, but I like to keep my code clean and wonder if there is any hidden feature, which checks for not any more needed local declarations (beside scripting a check myself)? Thanks Tiemo ___ 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: how to check for unnecessary local declarations?
Seems you could write a handler to do it pretty easily. pseudocode — get stack script — find “local “ — get word 2 of found line — filter with “*” word 2 of found line “*” — count number of lines. if only 1 then delete that line — get list of cards — repeat for every card — get card script — what I just said — get list of objects on card — repeat for every object on card — get script of object — do I have to repeat myself again?? /pseudocode It might be a little more complicated if you have multiple local variable declarations, but not much. Bob S On Jul 1, 2015, at 06:44 , Tiemo Hollmann TB toolb...@kestner.de wrote: Hello, I am using the strict compilation mode. When working over longer time on a project it regularly happens that I have orphaned local variable declarations. Actually they don't hurt, but I like to keep my code clean and wonder if there is any hidden feature, which checks for not any more needed local declarations (beside scripting a check myself)? Thanks Tiemo ___ 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