How popular is REALbasic?

· 16 days ago

According to the TIOBE Programming Community Index, REALbasic may now be as popular as Oberon and Algol.

Comment [3]

---

Pretty-Printing XML: A 'Hello World' Example

· 27 days ago

REALbasic has no built-in method to pretty-print XML. What it does have is support for XSLT, and that will allow you to generate nicely-formatted XML with no effort on your part other than to learn some XSLT.

XSLT is a language for describing transformations of XML documents. Since I don’t understand it yet, I won’t explain the transform itself, except to say that it simply copies the input, and indents the output. Here it is, printed prettily.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes" />
	<xsl:template match="/">
		<xsl:copy-of select="/" />
	</xsl:template>
</xsl:transform>

Let’s suppose that you have this available in your REALbasic project as a String called IndentXML. Then you can format an XML document as follows.

Function PrettyPrint(extends xml as XMLDocument) as String
  return xml.Transform(IndentXML)
End Function

Comment

---

Marking Code For Later Attention

· 39 days ago

When engaged in the Big Refactor, it is often the case that you want to mark code for later attention. Perhaps one refactoring has broken some other code, and you’d rather not deal with it now. The immediate solution is to comment it out, and perhaps add a comment to remind you what needs to be fixed. And then you forget about it, and only remember in the course of figuring out why things don’t work later.

Here is a simple trick that enlists the compiler to help you remember. Add a module to your code, and to it a constant like

const ToBeResolved = false

Now instead of commenting out code, wrap it along with your notes into a pragma block.

#if ToBeResolved
  this code needs to be reworked to use the new
  Foo class interface
  blah
  blah
  blah
#endif

Now, the compiler will ignore everything inside the block, allowing you to stay on task with the refactoring. Later, you can change the value of ToBeResolved to true, and the compiler will tell you about compile-time errors in the code whose reworking was deferred. You can check the code for a single class, or the entire project.

Comment

---

Matching a Quoted String With a Regular Expression

· 42 days ago

I needed to match quoted strings in text, so I set out to write a regular expression to find them. I am, of course, not the first person to require such a thing, and a quick web search turned up a very nice analysis of the problem. I leave you to read it, and provide here some REALbasic code. The function that follows contains a version of the regular expression adapted for the REALbasic IDE.

Function QuotedStringBody(s as String) As String
  dim r as new RegEx
  const quotedString = "\x22([^\x22\\]*((\\.)*[^\x22\\]*)*)\x22"
  r.SearchPattern = quotedString
  dim match as RegExMatch = r.Search(EditField1.Text)
  if match <> nil and match.SubExpressionCount >= 2 then
    return match.SubExpressionString(1)
  else
    return ""
  end if
End Function

The regular expression language allows you to represent any literal by its ASCII code as hex (\xdd) or octal (\ndd). Here I use \x22 in the regular expression so that I do not need to escape every use of the double-quote in the IDE.

The string returned by this function still contains escaped characters. We can replace them with another regular expression.

Function QuotedStringContents(body as String) As String
  dim r as new RegEx
  r.Options.ReplaceAllMatches = true
  const escape = "\\(.)"
  r.SearchPattern = escape
  r.ReplacementPattern = "$1"
  return r.Replace(body)
End Function

It would be nicer to have a regular expression that returned the quoted string body as subexpression 0. With the use of some fancier features of regular expressions, we can do just that.

First, the original regular expression contains quite a few subexpressions. Let’s begin by removing the parentheses used to group the quoted string body.

const quotedString = "\x22([^\x22\\]*((\\.)*[^\x22\\]*)*)\x22"

We can use the operator ?: to tell the RegEx object that some parentheses are for grouping only, so that no subexpression need be kept.

const quotedString = "\x22[^\x22\\]*(?:(?:\\.)*[^\x22\\]*)*\x22"

Next, we want the regular expression to look for a pattern that follows a ", without including the " in the match . This is accomplished with the operator ?<=.

const quotedString = "(?<=\x22)[^\x22\\]*(?:(?:\\.)*[^\x22\\]*)*\x22"

And then we want the same thing for the terminal quote; that is, we want to match a certain pattern followed by a ", without including the " in the match. For this we use the operator ?=.

"(?<=\x22)[^\x22\\]*(?:(?:\\.)*[^\x22\\]*)*(?=\x22)"

This does the trick; we can now simplify the function QuotedStringBody.

Function QuotedStringBody(s as String) As String
  dim r as new RegEx
  const quotedString = "(?&lt;=\x22)[^\x22\\]*(?:(?:\\.)*[^\x22\\]*)*(?=\x22)"
  r.SearchPattern = quotedString
  dim match as RegExMatch = r.Search(EditField1.Text)
  if match <> nil then
    return match.SubExpressionString(0)
  else
    return ""
  end if
End Function

Comment [3]

---

Trivial Client-Server Example

· 52 days ago

The trivial client and server projects written for my Real World 2008 talk on designing client-server applications are now available for download.

Download

Comment [2]

---

Real Artists Ship

· 63 days ago

“Real artists ship” is famously attributed to Steve Jobs. Apparently, many of them ship it using some version of BASIC.

Slumming with BASIC Programmers

Comment

---

otrGraphics on SourceForge

· 71 days ago

The source code for the graphics engine from On-Target Reports ia now available at SourceForge.

---

FolderItem Annoyances

· 78 days ago

Suppose you have a FolderItem parent representing a directory, and the directory contains a file named foo.

What would you think is the result of parent.Child(“Foo”) when the user executing some code lacks execute permission for the directory?

More...

Comment [2]

---

Comparing Array References to Nil

· 78 days ago

The inability to compare an array reference to Nil is a longstanding REALbasic annoyance. It is now possible to do so in REALbasic 2008r1, albeit obliquely.

More...

Comment [2]

---

Sparkle For REALbasic Update

· 78 days ago

A new version of Sparkle for REALbasic is available. This fixes a bug in the code that looks for Sparkle.framework.

Download

Comment [1]

---

Older