Washington Apple Pi

A Community of Apple iPad, iPhone and Mac Users
Book Review: Programming 4th Dimension
by Paul Chernoff
1998, Paul J. Chernoff

Washington Apple Pi Journal, July/August 1998, pp. 63-65, reprint information

Programming 4th Dimension: The Ultimate Guide by David Adams and Dan Beckett. 1998, Fort Worth, Texas: Foresight Technology, Inc. $139. http://www.foresight.com/

Introduction

I'm pleased to say that there is a new 4th Dimension (4D) book on the market, Programming 4th Dimension: The Ultimate Guide . While expensive and not available in book stores, it is a goldmine for beginning and advanced 4D programmers. It is a complement, not a replacement, to the 4th Dimension manuals. It covers programming both versions 3.5 and 6 of 4D. A CD-ROM with database code and examples is included with the book.

What Is 4th Dimension?

4D is a database development system for the Macintosh, Windows95, and WindowsNT.1 It is intended for people who write database systems, as opposed to FileMaker Pro, which is targeted at database users. While it is possible to create a 4D database without programming, you must use its programming language to take advantage of most of its abilities. 4D is harder to learn than FileMaker Pro but offers a much more sophisticated development environment.

Much Macintosh lore surrounds 4D. Apple originally planned to publish 4D in 1985, then known by its code name Silver Suffer . The original version wowed people and was seen as the first programmable relational database that followed the Macintosh style. But Ashton-Tate--at the time, its dBase III database software dominated the PC market--complained to Apple and insisted that 4D be sold to Ashton-Tate. Fortunately 4D's developer, ACI, kept it for itself and made Guy Kawasaki president of ACI's American subsidiary, ACIUS. While ACI has not thrived, it has certainly done better than Ashton-Tate, whose dBase for Mac flopped and whose assets where purchased by Borland International.

I have used 4D to create databases since 1986. My previous database experience was with dBase III , various versions of R:Base , with its SQL-based language, and FoxBase for Mac , a worthwhile port of dBase III to the Macintosh. I prefer 4D over these and other database programs. While other people have complained about 4D's complexity, I have found its learning curve to be reasonable.

4D is cross-platform and runs under Windows95, WindowsNT, and the Macintosh. It is currently at version 6.05, though many users still depend on its previous version, 3.5. It is available in two flavors, stand alone and client/server. The client/server version is called 4D Server and is required for a 4D -based multi-user database. ACI sells other 4D -related tools including 4D Compiler, 4D Insider, and 4D Write .

This Is a Programming Book

First and foremost, this book is for database programmers. It does not provide examples of data-entry forms. Nor does it rehash the 4D manuals. While its intended audience does include beginners, it assumes that readers have read the manuals and worked through the tutorial.

The authors have a solid writing style that does not talk down to the reader and is easy enough to read while commuting on the metro. The layout is easy on the eyes and the chapters are well organized. The icons used to signify important notes, cross references, and other important information are useful and do not detract from the text. While 4D is cross platform and the book covers Windows and Mac equally well, all screen grabs were done on the Macintosh. In a world where many publishers provide Windows manuals with their Macintosh software, the latter is a little touch that I appreciate.

Programming 4th Dimension taught me not just about 4D but also about good database design. I immediately started integrating ideas from the book into my databases. I was not bored when it covered basics such as data normalization or one-to-many relationships. It was actually refreshing to have this stuff re-explained to me. I wish I had a similar book when I started 4D development a decade ago.

Who Should Read It

I think that most 4D developers would benefit from this book. There are four groups who benefit the most:

What Is Covered

Programming 4th Dimension is a great way to discover 4D gems, especially if you recently upgraded to version 6. For example, I discovered the SET QUERY DESTINATION command, which allows you to send the results of a query to an integer variable, a set, or a named selection. This allows me to get the results of a query without changing the currently selected records. I missed this command when reading the 4D manual. The authors showed me how to use this new command to speed up operations and to do new functions. Knowing commands is not enough; you need to know the implications of commands and the techniques they make possible.

Adams and Beckett do a good job explaining how 4D works. A deeper understanding of 4D's underpinnings ensures better programming. For example, a chapter covers address tables and how data is stored on the hard disk so you can better understand why certain search-and-sort commands are faster than others. I might not work on my car, but I maintain it better by understanding how it works.

Many of the subjects concern principles of database design and are not 4D specific. The book starts with a summary of normalization theory, the foundation of database design. The authors explain it in English and explain why most books discuss database design in the languages of set theory and predicate calculus. The authors cover the basics of normalization and why you would want to violate normalization rules in order to achieve better performance. The book covers the basics and then recommends Michael J. Hernandez's Database Design for Mere Mortals and C. J. Date's classic An Introduction to Database Systems, Vol I. These writers do not live in 4D nor Macintosh ghettos.

Anyone still programming in version 3.5 should not feel slighted because the book covers v3.5 and v6 equally well. Throughout the book, differences between 4D 3.5 and 6 and single-user vs. 4D Server are pointed out. This makes it easier to make the transition from 3.5 to 6. 4Dv6 has transformed much of 4D's terminology to be closer to standard database nomenclature. Files are now tables, layouts are now forms, etc. Programming 4th Dimension uses version 6 terminology but provides a table showing the changes from the previous version. It even covers how 4D terms relate to more traditional database terms, such as primary key and second normal forms.

The best method in which to write 4D code is to assume that it will be compiled and used with 4D Server. Even if you do not use 4D Server, writing code with it in mind with often result in code optimization and allow for future advancement to a multi-user database. 4D Compiler and 4D Server put certain constraints on your coding, but they result in better code. The book always points out where optimization for 4D Server is possible.

The authors are consistent in their goals of speed, proper RAM usage, and a good user experience. Not only should a database be fast, but it should appear fast to the user. This might mean optimizing the code that makes the biggest difference to the user. It also means providing user feedback whenever a long process is under way.

4D Server coverage is very good. In addition to the seven 4D Server chapters, the server is mentioned whenever relevant in the book. Some 4D Server issues, such as record locking, are very relevant to single-user 4D programming. 4D Server commands are new to v6 and are necessary for optimizing 4D Server performance. But don't be scared; client/server programming is much easier in 4D compared with other systems because client and server are tightly integrated during development and many multi-user issues are handled automatically. Compare this with other systems where you have to write totally different code for client and server and take great care that they are coordinated.

Good programming practices are reviewed. A chapter is dedicated to programming style, but the authors also cover good practices throughout the book. Not only do good practices result in easier-to-maintain code, but they can result in improved performance. For example, small methods or procedures are easier to read than large ones, but also result in better use of RAM.

The only chapter I would have benefited from more development was the one on turning 4D into a Web server. The authors cover both 4Dv6's built-in Web features and having a Web server application communicate with 4D via CGI software. I would have liked more examples of a Web site written entirely in 4Dv6.

Balance

The book points out the need to balance conflicting goals such as speed versus hard disk usage. Following a strict normalization plan will save on disk space but can hurt speed. Enough information is provided about conflicting goals to help the programmer make good decisions. The authors always aim toward making the system as good as possible for the user and recommend a user-centered approach for resolving conflicts.

Some of the most valuable sections cover the use of summary data and issues involving data accuracy. While presented in the context of 4D's development system, this information is valuable to all database programs. The emphasis is on how to build the best system for your clients.

Adams and Beckett understand that not one size fits all. A great deal of space is devoted to discussing which instructions are usually best for what circumstances. Sometimes there are tradeoffs between different approaches. They go over the pros and cons of competing techniques so the reader can make better decisions.

Warts & All

4D has its share of faults including language inconsistencies, confusing terminology, and missing features. The "4D Gotchas" provides a good view of 4D drawbacks and workarounds. It's nice to have a reference that points out that your problem might not be in your head but in your software.

Topics covered include differences between similar commands, common mistakes made by programmers, and reserved words. None of the items are major problems, but not knowing them can cause extra head scratching when your code doesn't work properly.

The CD-ROM

The included CD-ROM provides code libraries. Every time a topic has example code, the book will refer you to the CD-ROM. 75 pages are devoted to describing the libraries. Included are a batch workstation, error manager, general procedures, free join procedures, initialization manager, set manager, and transaction manager code libraries. All of these libraries have their own chapters in addition to being referenced elsewhere in the book. While the authors do not provide an overall programming shell, the libraries are provided for integration with the readers' databases.

Summary

The 4D community has been waiting a long time for a book like Programming 4th Dimension . The authors know 4D inside and out and convey this information in an easy-to-digest manner. No 4D programmer should do without this book. While the book is more expensive than your typical Microsoft Access or FileMaker Pro book, it is worth it. It pays off with improved productivity and improved products. I consider this book a "must buy" for all 4D developers.


1It also works under Windows 3.1, but the consensus is to avoid running 4D on Windows 3.1.

Paul Chernoff spends his days writing databases at The Washingtonian when not busy helping people with QuarkXPress, fixing network problems, working on the Internet, or taking care of the servers. He is lucky to be doing most of his work on a Mac. At home, he balances time between Mac and family. He can be reached at paul.chernoff@tcs.wap.org .

*


Return to electric pi

Revised Saturday, August 1, 1998 Lawrence I. Charters
Washington Apple Pi
URL: http://www.wap.org/journal/