Jun 97 - Tips

Volume Number: 13 (1997)
Issue Number: 6
Column Tag: Tips & Tidbits

# Jun 97 - Tips & Tidbits

by Steve Sisak

## Prettyprinting Complex Expressions

The main problem with trying to read a complex expression in a program is trying to discern its structure. When you are writing such an expression, think of it as a tree, with the operators located where the branches join, and the operands attached to them. If you arrange your code to reflect something of this tree structure in two dimensions, the result becomes much easier to understand.

```IF (NewState > OfState^.NrStates) OR (NewState = 0) AND
(OfState^.NrStates > 1) THEN
```

with

```IF
(NewState > OfState^.NrStates)
OR
(NewState = 0) AND (OfState^.NrStates > 1)
THEN
```

Note that the AND-expression and its subexpressions were not broken out onto separate lines, because they are simple enough that their clarity would not be helped by this.

See how gracefully this technique copes with increasing numbers of subexpressions:

```RETURN
(ThePoint.x >= TheRect.left)
AND
(ThePoint.x < TheRect.right)
AND
(ThePoint.y >= TheRect.top)
AND
(ThePoint.y < TheRect.bottom)
```

Imagine what a mess this would look like all run together:

```IF
NOT EqualFixedRect
(
OldEntry^.DeviceIntersect,
NewEntry.DeviceIntersect
)
OR
NOT BlockEqual
(
(*Count :=*) SIZE(gxMapping)
)
OR
(
OldEntry^.DeviceBitmap.width
<>
NewEntry.DeviceBitmap.width
)
OR
(
OldEntry^.DeviceBitmap.height
<>
NewEntry.DeviceBitmap.height
)
OR
NOT EqualColorSet
(
OldEntry^.DeviceBitmap.set,
NewEntry.DeviceBitmap.set
)
OR
NOT EqualColorProfile
(
OldEntry^.DeviceBitmap.profile,
NewEntry.DeviceBitmap.profile
)
THEN
```

or this one:

```IF
(
ThisDevice^^.gdPMap^^.pixelSize
=
OtherDevice^^.gdPMap^^.pixelSize
)
AND
(
(QuickDraw.gdDevType IN ThisDevice^^.gdFlags)
=
(QuickDraw.gdDevType IN OtherDevice^^.gdFlags)
)
AND
(
(
QuickDraw.dontMatchSeeds
IN
flags
)
OR
(
ThisDevice^^.gdPMap^^.pmTable^^.ctSeed
=
OtherDevice^^.gdPMap^^.pmTable^^.ctSeed
)
)
THEN
```

Such an arrangement also makes it easier to attach comments explaining what the subexpressions are for:

```IF
(Windows.FrontWindow() = NIL)
(* no other windows active *)
AND
(LastPalette() <> Windows.WindowInFront)
(* I have palettes *)
THEN
```

By the way, these are not made-up examples, they are all from actual working code. This isn't about exercises for kiddies in classrooms. It's about real-world programming!

Lawrence D'Oliveiro
LDO@waikato.ac.nz

Community Search:
MacTech Search:

Bean 3.3.1 - Fast and uncluttered word p...
Bean is no longer being actively developed, but will be updated as necessary to patch bugs and maintain OS X compatibility Bean is lean, fast, and uncluttered. If you get depressed at the thought... Read more
RetroArch 1.9.0 - Game emulator.
RetroArch is most popularly known for being a program with which you can play many emulators and games, which have all been customized and tailor-ported to the libretro API. It is designed to be fast... Read more
NetNewsWire 5.0.4 - RSS and Atom news re...
NetNewsWire is the best way to keep up with the sites and authors you read most regularly. Let NetNewsWire pull down the latest articles, and read them in a distraction-free and Mac-like way. Native... Read more
EarthDesk 7.4.5 - \$24.99
EarthDesk replaces your static desktop picture with a rendered image of Earth showing correct sun, moon, and city illumination. With an Internet connection, EarthDesk displays near-real-time global... Read more
BetterTouchTool 3.401 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom)... Read more
Vienna 3.5.6 :e12c952d: - RSS and Atom n...
Vienna is a freeware and Open-Source RSS/Atom newsreader with article storage and management via a SQLite database, written in Objective-C and Cocoa, for the OS X operating system. It provides... Read more
WhatsApp 2.2031.5 - Desktop client for W...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Day One 4.16 - Maintain a daily journal.
Day One is an easy, great-looking way to use a journal / diary / text-logging application. Day One is well designed and extremely focused to encourage you to write more through quick Menu Bar entry,... Read more
VMware Fusion 11.5.6 - Run Windows apps...
VMware Fusion and Fusion Pro - virtualization software for running Windows, Linux, and other systems on a Mac without rebooting. The latest version includes full support for Windows 10, macOS Mojave... Read more
Alfred 4.1 - Quick launcher for apps and...
Alfred is an award-winning productivity application for OS X. Alfred saves you time when you search for files online or on your Mac. Be more productive with hotkeys, keywords, and file actions at... Read more

## Latest Forum Discussions

Motorball is a car football game from No...
A few years back Noodlecake Studios announced that they would be dipping in the multiplayer gaming realm with two different games. The first of those, Golf Blitz, released a while back and has proven to be very popular. Now, the second has arrived... | Read more »
SINoALICE's latest update introduce...
SINoALICE's latest update has now arrived, adding several fan-favourite characters from popular RPG series NieR. Young Nier, Kaine, and Young Emil are available in-game as part of a limited-time crossover event set to run until August 20th. [Read... | Read more »
Rocat Jumpurr is an intense roguelite pl...
Rocat Jumpurr is a roguelite platformer from developer Mousetrap Games. You might already be familiar with it if you follow the Big Indie Pitch, where it won first place during this year's Pocket Gamer Connects London competition. Following its... | Read more »
PUBG Mobile's Play As One campaign...
Back in mid-July, we reported that PUGB Mobile had teamed up with Direct Relief to help raise money for the charity's COVID-19 response project. It focused on an in-game running challenge for players, which lead to the PUBG Mobile donating \$2... | Read more »
Marvel Contest of Champions' latest...
Marvel Contest of Champions' latest motion comic has arrived, and it shows off new fighters Air-Walker and Dragon Man. Both characters are set to arrive in-game this month. [Read more] | Read more »
Clash Royale: The Road to Legendary Aren...
Supercell recently celebrated its 10th anniversary and their best title, Clash Royale, is as good as it's ever been. Even for lapsed players, returning to the game is as easy as can be. If you want to join us in picking the game back up, we've put... | Read more »
Global Spy is an intriguing 2D spy sim f...
Developer Yuyosoft Innovations' Global Spy launched last month for iOS and Android, though if you missed it at the time, we're here to tell you why it's well worth a go. This one's all about international espionage, tracking down elusive spies,... | Read more »
Distract Yourself With These Great Mobil...
There’s a lot going on right now, and I don’t really feel like trying to write some kind of pithy intro for it. All I’ll say is lots of people have been coming together and helping each other in small ways, and I’m choosing to focus on that as I... | Read more »
Hyena Squad is sci-fi turn-based strateg...
Wave Light Games has just revealed its latest release, Hyena Squad, a turn-based RPG set in a space station infested by gross aliens and the living dead. The announcement was first reported on by Touch Arcade. [Read more] | Read more »
Idle Guardians: Never Die is a pixel art...
SuperPlanet has been fairly prolific with game releases so far this year with both Evil Hunter Tycoon and Lucid Adventure releasing earlier this year. Now, they've released another idle RPG called Idle Guardians: Never Die, which you can download... | Read more »

## Price Scanner via MacPrices.net

Sale! Apple’s 16″ MacBook Pros for up to \$349...
Apple Authorized Reseller Adorama has new 2019 16″ MacBook Pros in stock on sale today for \$100-\$349 off Apple’s MSRP, each including free shipping. Their prices for 8-core models (\$349 off) are the... Read more
Save hundreds of dollars on a custom-configur...
Save up to \$920 on a custom-configured 16″ MacBook Pro with these Certified Refurbished models that Apple has restocked today. Each MacBook Pro features a new outer case, free shipping, and includes... Read more
New 2020 12.9″ iPad Pros on sale for up to \$8...
Apple reseller Expercom has new 2020 Apple 12.9″ iPad Pros on sale today for \$60-\$85 off MSRP, with prices starting at \$939. These are the same iPad Pros sold by Apple in their retail and online... Read more
Woot offers numerous 2018-2020 MacBook Pros a...
Amazon-owned Woot has many open-box return MacBook Airs and MacBook Pros available today at prices starting at \$879. Shipping is free for Prime members. Here’s what they have as of this post, and... Read more
Apple restocks refurbished 2020 13″ MacBook A...
Apple has restocked Certified Refurbished 2020 13″ MacBook Airs starting at only \$849 and up to \$200 off the cost of new Airs. Each MacBook features a new outer case, comes with a standard Apple one-... Read more
Apple restocks clearance 2019 13″ 2.4GHz MacB...
Apple has restocked Certified Refurbished 2019 13″ 2.4GHz 4-Core Touch Bar MacBook Pros starting at \$1359 and up to \$560 off original MSRP. Apple’s one-year warranty is included, shipping is free,... Read more
Apple restocks refurbished iPhone XR models s...
Apple has restocked Certified Refurbished, unlocked, iPhone XR models in the refurbished section of their online store starting at \$539. Each iPhone comes with Apple’s standard one-year warranty,... Read more
Price drops! \$100-\$200 off clearance 27″ 5K i...
B&H Photo has dropped prices on clearance, previous-generation 27″ 5K iMacs by up to \$200 off Apple’s original MSRP: – 27″ 3.0GHz 6-Core 5K iMac: \$1699 \$100 off original MSRP – 27″ 3.1GHz 6-Core... Read more
Woot offers Apple Watch and iPhone models fro...
Amazon-owned Woot has refurbished Apple Watch and iPhone models available from \$99-\$749 through August 6th. According to Woot, the items may show some wear, but they have all been fully tested and... Read more
Apple’s Phil Schiller Steps Down As SVP OF Wo...
NEWS: 08.05.20 – Former Apple senior Vice President of worldwide marketing, Phil Schiller, is stepping down from his long time role at the company in order to focus on spending more time with family... Read more

## Jobs Board

Blue *Apple* Cafe Student Worker - Fall - P...
…to enhance your work experience. Student positions are available at the Blue Apple Cafe. Employee meal discount during working hours is provided. Duties include food Read more
Cub Foods - *Apple* Valley - Now Hiring Par...
Cub Foods - Apple Valley - Now Hiring Part Time! United States of America, Minnesota, Apple Valley New Retail Post Date 4 days ago Requisition # 122305 Sign Up Read more
Cub Foods - *Apple* Valley - Now Hiring Par...
Cub Foods - Apple Valley - Now Hiring Part Time! United States of America, Minnesota, Apple Valley New Retail Post Date 3 days ago Requisition # 122305 Sign Up Read more
Executive Team Leader GM Sales (Assistant Man...
…(Assistant Manager General Merchandise and Operations) - Apple Valley, CaliforniaApply NowJob ID:R0000082364job family:Store Managementschedule:Full Read more
Cub Foods - *Apple* Valley - Now Hiring Par...
Cub Foods - Apple Valley - Now Hiring Part Time! United States of America, Minnesota, Apple Valley New Retail Post Date 2 days ago Requisition # 122305 Sign Up Read more