Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 3.1

FEATURE

Postmortem: CodeCleaner

Writing an Integrated IDE Extra

Issue: 3.1 (September/October 2004)
Author: Owen Yamauchi
Author Bio: Owen Yamauchi is a freelance programmer who has been programming REALbasic since version F4. He is the Lead Programmer for Domain Softworx, a company that produces developer tools like CodeCleaner for REALbasic.
Article Description: No description available.
Article Length (in bytes): 11,054
Starting Page Number: 11
Article Number: 3108
Related Web Link(s):

http://www.domainsoftworx.com/

Excerpt of article text...

I never learned good code-formatting habits when I started programming. Specifically, I never spaced out my code so that it was more readable. As soon as I discovered the feature, I developed the habit of putting all my DIM statements on a single line. Finding the variable I wanted in a mile-long line of them got tiresome very quickly, but the habits were ingrained in my brain by then. I thought that maybe I could write a program that could space out code for me. That was the origin of CodeCleaner.

CodeCleaner's first incarnation was named CodeSpacer. It was a single window with a big EditField and a button. The button had a load of ugly code behind it, not just because it was not spaced out, but because I had not bothered to plan how it was going to work before I started writing it. The full code of the very first build was as follows:

EditField1.text = ReplaceAll(EditField1.text,"="," = ")

(In the actual program, the first equals sign was not spaced, but it is here, per RB Developer guidelines.) When I ran this code on itself, I was appalled. CodeSpacer had spaced out the equals signs inside the quotation marks. Then I realized something else: when I ran CodeSpacer again, all the equals signs would be doubly spaced out. Clearly I had to re-think what I was doing.

That's when the code started getting ugly. I had another method that would check whether a certain character was inside quotation marks. Each equals sign had to be checked, and for a long code snippet, this got very slow. I had to have two ReplaceAll commands: one that un-spaced doubly spaced equals signs, and another one to space them out. I had to repeat all of that for plus signs, minus signs, "greater than" and "less than" and all the other operators. Then I ran into trouble when the code found "less than or equal to" signs: "<=". Both operators got spaced, so the end result was: " < = ". RB still interpreted it correctly in code, but it was even uglier than before. What I ended up doing to solve that was to replace "<=" with a low-ASCII character before running any of the spacing-out code, then changing it back again at the end.

...End of Excerpt. Please purchase the magazine to read the full article.