• Print

Author Topic: Refactoring QBasic code  (Read 150 times)

TimV

  • Newbie
  • *
  • Posts: 12
Refactoring QBasic code
« on: May 25, 2013, 12:12:36 AM »
Is there an IDE / a tool which can assist in refactoring QBasic code? I'm looking for a tool that can rename variables and subs/functions and change the type (suffix or DIM). Is there anything like that for QBasic/QB64? Or am I stuck with search and replace?

OlDosLover

  • Hero Member
  • *****
  • Posts: 3953
  • OlDosLover
    • Email
Re: Refactoring QBasic code
« Reply #1 on: May 25, 2013, 12:18:13 AM »
Hi all,
    Im not clearly aware of a program of thst description. A quick search also didnt reveal anything. How big is this code? Perhaps post the code as a link and we can tackle it as a group.
OlDosLover.

Cyperium

  • Hero Member
  • *****
  • Posts: 3323
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Refactoring QBasic code
« Reply #2 on: May 25, 2013, 05:09:40 AM »
There is no tool that I'm aware of that can do that in QB64 or QB.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2269
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: Refactoring QBasic code
« Reply #3 on: May 25, 2013, 07:17:46 AM »
The QB64 IDE can be used to search and replace text, either individually or throughout the entire code in one pass.  Perhaps this can assist you.

bobtheunplayer

  • Jr. Member
  • **
  • Posts: 74
  • I'd rather be coding.
    • Email
Re: Refactoring QBasic code
« Reply #4 on: May 25, 2013, 08:26:16 PM »
If you have access to a person who can use sed ( stream editor ), they can refactor just about anything in minutes.  It's a GNU tool, and comes with every basic install of the popular distributions.  There may be a windows binary available as well.  If you want learn sed, you're in for a treat.  Like regular expressions, once you get the hang of it, you'll wonder how you ever got along without it.

~bob

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4679
  • QB Forever
    • Email
Re: Refactoring QBasic code
« Reply #5 on: May 25, 2013, 08:39:04 PM »
Grab the latest copy of QB64-GL.
Download the executable file below (a custom variant of the QB64 editor)
Create a text file called refactor.txt with 2 lines of text (in your root qb64 folder)
myoriginalvariablename
mynewvariablename
run qb64_refactor.exe instead of qb64.exe
where you define myoriginalvariable will stay the same, all references to the variable should (in theory) be renamed, but keep a backup just in case.
Hope this helps.

PS. This is a hack I put together in 10 minutes. If you want I could make it also only apply to variables called blah dim'ed on a specific line

PPS. This won't work on TYPE element names, constants and some other things.

Enjoy,
Galleon
« Last Edit: May 25, 2013, 10:07:28 PM by Galleon »
Something old... Something new... Something borrowed... Something blue...

OlDosLover

  • Hero Member
  • *****
  • Posts: 3953
  • OlDosLover
    • Email
Re: Refactoring QBasic code
« Reply #6 on: May 25, 2013, 09:39:16 PM »
Hi all,
    Using SED on Windows
http://www.thoughtasylum.com/blog/2011/9/30/using-sed-on-windows.html
OlDosLover.

TimV

  • Newbie
  • *
  • Posts: 12
Re: Refactoring QBasic code
« Reply #7 on: May 26, 2013, 01:03:47 AM »
Thank you all for your reactions. :-) I'm cleaning up the code for a utility called Liero Stuff Activator, which is a program written to patch the main executable of a game called Liero, installing add-ons. (see this website)

OlDosLover: The source is not that big. Thank you for the offer, if I really don't manage to do it I may post it here.

bobtheunplayer: I have sed on OS X. But that's basically regexp search and replace. I was looking for a program that would know the semantics of what it's doing.

Galleon: Thank you. That is already very helpful. And this sounds even better: "If you want I could make it also only apply to variables called blah dim'ed on a specific line". How would that work for variables that are not explicitly DIM'ed?

A good refactor tool would also make sure that the new variable name does not change the type, or perhaps fixes that with a postfix or a DIM. That would be ideal. :-)

Cyperium

  • Hero Member
  • *****
  • Posts: 3323
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Refactoring QBasic code
« Reply #8 on: May 26, 2013, 01:22:51 PM »
I will add refactor functionality to my custom qb64 editor but it will take some time to get done. If you have any suggestions to the interface then please let me know.



I'm also thinking of making a "loader", which means that when you press F7 it will have a Open Dialog, let you select a file and it will paste the path + filname in quotes at the current cursor location.

There are two main reasons that this would be useful, first of all you don't need to open explorer if you are unsure of the name/path of the file, second it will be less error prone as you don't need to type it yourself. I think it would be useful to have in the main IDE as well if Galleon is up to it or anyone working with the repository.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

TimV

  • Newbie
  • *
  • Posts: 12
Re: Refactoring QBasic code
« Reply #9 on: May 28, 2013, 02:06:01 PM »
Something like this would be nice:
http://wiki.netbeans.org/Refactoring#Rename
http://www.wholetomato.com/products/features/rename.asp

You could also skip the dialogue box and have the user type the new name of the variable in-place. All instances of the variable name in the text would update simultaneously while you are typing.

Cyperium

  • Hero Member
  • *****
  • Posts: 3323
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Refactoring QBasic code
« Reply #10 on: May 28, 2013, 03:46:28 PM »
I think this would be very useful, I will have a dialog box though, the user simply changing a variable in the code doesn't always want all instances to be changed, it will probably let the user specify a variable name and the new name for it, similar to search/replace but taking considerations to DIM and suffixes (let you change the type and some other things).

I have to say that I'm not too familiar with refactoring, so if there is anything special you want it to do aside for renaming/changing types then please let me know.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

TimV

  • Newbie
  • *
  • Posts: 12
Re: Refactoring QBasic code
« Reply #11 on: May 29, 2013, 12:15:15 AM »
Remember to take into account DEFINT, DEFLNG, DEGSNG etc.
« Last Edit: May 29, 2013, 12:30:49 AM by TimV »

Cyperium

  • Hero Member
  • *****
  • Posts: 3323
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Refactoring QBasic code
« Reply #12 on: May 29, 2013, 04:12:46 AM »
Yes, I will take DEF into consideration.

What will happen if the new name of the variable already exists elsewhere in the program?
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

TimV

  • Newbie
  • *
  • Posts: 12
Re: Refactoring QBasic code
« Reply #13 on: May 29, 2013, 09:21:32 AM »
In the tools that I have used, nothing special happens. The variable is renamed anyway and the two variables are effectively merged.

Cyperium

  • Hero Member
  • *****
  • Posts: 3323
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Refactoring QBasic code
« Reply #14 on: May 29, 2013, 03:26:51 PM »
Ok, I think I will have a warning and a choice to either merge them (ignore) or cancel the operation. If the variable that already exists is DEFaulted to a different type then it will be defaulted to the new type as set in the renaming dialog. As the work progresses I might come here for more questions that I can't forsee right now.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

  • Print