Refactoring
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Refactoring
I have a very, very clunky thing called "Devawriter Pro" which I have been developing for about 9 years.
It is clunky in these ways:
1. Orphaned code left over from earlier recensions
[Mainly focussed on the numToChar/ numToCodePoint switchover].
2. Horrible reduplication of code [think 50 buttons using 99% the same code].
3. Other "side-projects" that never got "there" but still lying around under the hood.
According to a conservative estimate I could reduce the size of my main stack by at least 50%.
Questions that inevitably pop up are:
1. Is the time that will be involved in refactoring going to be reflected in terms of a financial increase.
[This question is a load of old "sh*t" as I've never made more that $400 a year for the thing:
I just shoved it in here for completeness.]
2. How much of this can be done automatically?
[Probably in my case, NONE, as LiveCode does not understand the "joys" of
ancient Indian writing systems.]
3. How can I ensure that as I change bits of code in various places it does not have unseen and
unsuspected consequences elsewhere?
4. Version tracking? Should I build an autosave script into the stack prior to doing anything else?
5. Why am I even bothering to think about this and write these questions?
WELL, at least I can answer #5:
AND it comes in 2 parts . . .
Because I am well aware that if I really want to keep going with this thing [think "bottomless pit"]
the cracks are going to start appearing very, very soon if I don't address the fact that, like MacOS 9,
my current version (2.6.0) is floating around on code from version 0.1 which should have gone
the way of the woolly mammoth a long, long time ago.
People are writing all sorts of "jazzy, technical stuff" about refactoring over on the Use-List
in "jazzy, technical" language that makes me feel unco queer because it seems
(possibly unnecessarily jargonised) very difficult for "simple" folk like me to follow.
It is clunky in these ways:
1. Orphaned code left over from earlier recensions
[Mainly focussed on the numToChar/ numToCodePoint switchover].
2. Horrible reduplication of code [think 50 buttons using 99% the same code].
3. Other "side-projects" that never got "there" but still lying around under the hood.
According to a conservative estimate I could reduce the size of my main stack by at least 50%.
Questions that inevitably pop up are:
1. Is the time that will be involved in refactoring going to be reflected in terms of a financial increase.
[This question is a load of old "sh*t" as I've never made more that $400 a year for the thing:
I just shoved it in here for completeness.]
2. How much of this can be done automatically?
[Probably in my case, NONE, as LiveCode does not understand the "joys" of
ancient Indian writing systems.]
3. How can I ensure that as I change bits of code in various places it does not have unseen and
unsuspected consequences elsewhere?
4. Version tracking? Should I build an autosave script into the stack prior to doing anything else?
5. Why am I even bothering to think about this and write these questions?
WELL, at least I can answer #5:
AND it comes in 2 parts . . .
Because I am well aware that if I really want to keep going with this thing [think "bottomless pit"]
the cracks are going to start appearing very, very soon if I don't address the fact that, like MacOS 9,
my current version (2.6.0) is floating around on code from version 0.1 which should have gone
the way of the woolly mammoth a long, long time ago.
People are writing all sorts of "jazzy, technical stuff" about refactoring over on the Use-List
in "jazzy, technical" language that makes me feel unco queer because it seems
(possibly unnecessarily jargonised) very difficult for "simple" folk like me to follow.
Re: Refactoring
I think the financial increase would be reflected in 'dollars per hour', instead of yearly dollars. In other words, refactoring / re-writing / removing useless code, all of those things cut down on how much you have to dredge through each time, so your productivity increases compared to someone that leaves all that cruft in, so you accomplish more when you sit down to code.1. Is the time that will be involved in refactoring going to be reflected in terms of a financial increase.
[This question is a load of old "sh*t" as I've never made more that $400 a year for the thing:
I just shoved it in here for completeness.]
If your doing in 10 minutes what used to take 12, you've increased your per hour financial gain.
Depends on how good you are at writing tools, or whether you have the tools available. Things like finding duplicate code, well finding it is easy. Telling whether it is needed in the entire context of the program is a little trickier. It would also depend on how comfortable you are with the IDEs built in tools for this, like the profiler, or some of the tools made by others.2. How much of this can be done automatically?
Well, there are lots of ways to do that. I use both styles of comments myself. For a code change, I use the block comments to wrap the date of the change and the previous code. Once it is commented, you are sure going to know if you haven't been using it for a while.3. How can I ensure that as I change bits of code in various places it does not have unseen and
unsuspected consequences elsewhere?
A side benefit is that it indicates the biggest problem areas in what your trying to accomplish.
I think so. I rarely only ever have one revision of a program in storage.4. Version tracking? Should I build an autosave script into the stack prior to doing anything else?
Hope that helps a little
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Refactoring
Thanks "bogs": quite a lot of useful stuff there.
-
- VIP Livecode Opensource Backer
- Posts: 7233
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Refactoring
It's always wise to simplify as much as possible, if for no other reason than just to save your own sanity later.
The 50 buttons need to use a behavior, which you can automate. Put the script into a hidden button and use that as the script storage container. Write a temporary handler that loops though all the buttons and sets their script to empty, and sets their behavior to the long ID of the hidden button. There should be no repercussions from that change.
If you need to see if a handler is unused and superfluous, put a breakpoint in it, work with the stack normally, and see if it triggers. Or just use the Find and Replace dialog to do a stack-wide search for the handler name and see if it occurs anywhere outside of itself.
The 50 buttons need to use a behavior, which you can automate. Put the script into a hidden button and use that as the script storage container. Write a temporary handler that loops though all the buttons and sets their script to empty, and sets their behavior to the long ID of the hidden button. There should be no repercussions from that change.
If you need to see if a handler is unused and superfluous, put a breakpoint in it, work with the stack normally, and see if it triggers. Or just use the Find and Replace dialog to do a stack-wide search for the handler name and see if it occurs anywhere outside of itself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Refactoring
I am trying to work out what is the difference between Refactoring
and just rewriting some code so it is more efficient.
and just rewriting some code so it is more efficient.
Re: Refactoring
The difference is you can use one word, 'refactoring', to replace 8 words, 'rewriting some code so it is more efficient'.
It probably comes out to a lot more words, since the code that results from refactoring is (usually) more condensed as well. From someone a lot smarter than I ~
It probably comes out to a lot more words, since the code that results from refactoring is (usually) more condensed as well. From someone a lot smarter than I ~
https://en.wikipedia.org/wiki/Code_refactoring wrote: Code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity; these can improve source-code maintainability and create a more expressive internal architecture or object model to improve extensibility.
Typically, refactoring applies a series of standardised basic micro-refactorings, each of which is (usually) a tiny change in a computer program's source code that either preserves the behaviour of the software, or at least does not modify its conformance to functional requirements. Many development environments provide automated support for performing the mechanical aspects of these basic refactorings. If done extremely well, code refactoring may help software developers discover and fix hidden or dormant bugs or vulnerabilities in the system by simplifying the underlying logic and eliminating unnecessary levels of complexity. If done poorly it may fail the requirement that external functionality not be changed, introduce new bugs, or both.
By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you'll find that it is easier to extend and maintain code.
— Joshua Kerievsky, Refactoring to Patterns[1]
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Refactoring
AUTOSAVE seems to be a "pain in the bum" on Macintosh.
LC 8.1.10, macOS 10.14.3 beta 4
This:
bit, instead is saving backups inside my Macintosh app-folder (i.e. inside the LC 8.1.10 app).
LC 8.1.10, macOS 10.14.3 beta 4
This:
should be saving time-stamped backups into my external drive "X1"on openStack
set the defaultFolder to "/Volumes/X1/DWP autosaves"
backSave
end openStack
on backSave
save this stack as ("SAVER" && the time)
send "backSave" to this stack in 120
end backSave
bit, instead is saving backups inside my Macintosh app-folder (i.e. inside the LC 8.1.10 app).
Re: Refactoring
Does it work if you provide the complete pathname?
Works here for me, I NEVER EVER rely on "the defaultfolder".
Code: Select all
on openStack
backSave
end openStack
on backSave
save this stack as ("/Volumes/X1/DWP autosaves"/SAVER" && the time)
send "backSave" to this stack in 120
end backSave
-
- VIP Livecode Opensource Backer
- Posts: 7233
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Refactoring
Klaus beat me to it but here's what I was writing when he posted:
Use the full file path in the backsave handler instead of setting the defaultfolder earlier. Or alternately, set the defaultfolder inside the backsave handler itself. The defaultfolder may be changing between openstack and the time your save handler executes.
Also, are you sure you want to save every 2 seconds? Seems like that would interfere a lot with everything else.
Use the full file path in the backsave handler instead of setting the defaultfolder earlier. Or alternately, set the defaultfolder inside the backsave handler itself. The defaultfolder may be changing between openstack and the time your save handler executes.
Also, are you sure you want to save every 2 seconds? Seems like that would interfere a lot with everything else.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Refactoring
And be prepared to find your stack named: SAVER 6/23 PM on your HD!
The : (colon) is not a valid character for filenames on Mac, it will get replaced by / (backslash)
However if you select htis file with:
answer file "yadda";put it
You will get: SAVER 6:23 PM again.
The : (colon) is not a valid character for filenames on Mac, it will get replaced by / (backslash)
However if you select htis file with:
answer file "yadda";put it
You will get: SAVER 6:23 PM again.
Re: Refactoring
Yes sure, but it is hard to understand why this should happen in this tiny nanosecond before calling the "backsave" routine . So the first saving SHOULD go into the right place! Not?
Code: Select all
on openStack
set the defaultFolder to "/Volumes/X1/DWP autosaves"
## No place/time for changing the defaultfolder again right here:
backSave
end openStack
on backSave
save this stack as ("SAVER" && the time)
send "backSave" to this stack in 120
end backSave
-
- VIP Livecode Opensource Backer
- Posts: 7233
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Refactoring
I'd think so, but there are several other open* messages and they may take precedence. I found out a while ago that the opening stack behavior isn't what I thought it was.
At any rate, handling the file path only when needed should work. Like you, I almost never use defaultfolder because it can change unexpectedly.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Refactoring
Yes, true, I forgot how busy the IDE is in the background.
-
- Livecode Opensource Backer
- Posts: 9385
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Refactoring
Well, I started off by editing one line:
HOWEVER:
does NOTHING.
Code: Select all
save this stack as ("/Volumes/X1/DWP autosaves"/SAVER" && the time)
Code: Select all
on openStack
backSave
end openStack
on backSave
save this stack as ("/Volumes/X1/DWP autosaves/SAVER" && the time)
send "backSave" to this stack in 120
end backSave