Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
This chapter is from the book

Goodbye “Hello, World”

For many people, their first program was something along the lines of the well-known Hello World program shown in Listing 1.1. It is from the classic The C Programming Language by Brian Kernighan and Dennis Ritchie (1978).

Listing 1.1 Hello, World

main( ) {
    printf("hello, world");
}

Many people still think of this as a model of what programming is all about: You start with a blank piece of paper or a blank screen, you type in your code, you run it, you make revisions, and you continue on to the next program on its own blank piece of paper or blank screen.

Today’s programming is based on several commonly used paradigms. Two of the most important have to do with how programs function—declarative and imperative paradigms. A third, object-oriented programming, has to do with the structure of programs.

Working with Imperative and Declarative Programming Paradigms

Today’s apps are much more complex than just printing or displaying a line of text. How do you get from Hello, World to an app such as iTunes? Even an app that appears to be text-based such as Pages in the iWork suite is a far cry from Hello, World. And when you consider that Mac OS X and iOS are basically just very large apps, it is hard to see how they evolved from Hello, World.

When Hello, World first was written, the programming world was already moving away from this linear do this/do that paradigm (called imperative or procedural programming) to a new paradigm called declarative programming, in which the mechanics of how something is done are less important than what is done.

Procedural programming is used in the code you write; most of that is Objective-C when you are writing for Mac OS X and iOS. For most people, writing procedural code “feels” like programming. (In addition to its procedural programming concepts, Objective-C uses object-oriented programming, hence its name.)

Languages that are declarative (that is, focusing on what is done) are particularly common on the Web. Most people consider Cascading Style Sheets (CSS), regular expressions, and the basics of SQL (SELECT statements, for example) to be examples of declarative languages. Markup languages in general—including HTML itself—are declarative rather than procedural because they describe what the end result should look like. For many people, designing databases and web pages doesn’t “feel” like programming (and many people do not think that it is).

The distinction between these two programming paradigms is not a matter of good versus bad or old versus new: It is simply a contrast between two ways of developing software. As you approach Xcode, Mac OS X, and iOS, you do not have to make a choice because both paradigms are supported in Xcode. Most of the time, a specific editing function is implemented only in procedural or declarative styles because one or the other is the natural way of editing that particular set of instructions.

If you are starting building apps for Mac OS X or iOS that use Core Data, you will use descriptive editors for the Core Data side of things just as you do with many SQL-based development environments, and you will use procedural editors for the text-based code that you write to manipulate the interface and the database.

Working with Object-Oriented Programming

Object-oriented programming is now so pervasive that for many people, it is the only kind of programming they do. Instead of the simple and relatively unstructured code shown in Listing 1.1, objects are created that encapsulate data and functionality. These objects interact with one another to get the work of the program done.

When people first started using object-oriented programming techniques, some critics pointed out that it took much more code and programming time to use object-oriented techniques and languages than to use traditional techniques and languages. The idea of writing a program with the three lines shown in Listing 1.1 is unthinkable in the object-oriented programming world.

However, the arguments made by proponents of object-oriented programming and borne out by decades of experience are that

  • Object-oriented programming is easier to maintain and modify over time in part because of its inherent structures.
  • It might take many more lines to write a very simple program using object-oriented programming techniques, but as the complexity of the program increases, the incremental effort to build each new feature can be significantly less than with traditional techniques.

When you put these points together, you can see that there is a significant difference between simple and complex programs no matter whether you are using object-oriented programming or traditional programming. The benefits of object-oriented programming really only appear in complex programs, whereas the limitations of traditional programming methods do not appear in short programs.

In practical terms, this means that to learn how to use the tools of Mac OS X and iOS along with Xcode, you have to work with hefty examples. And if you try to use a simplified example, you might wind up thinking that these tools are overly complex. That is true in one sense: Using these tools to write something very simple is overkill. But not using tools like this to write complex software is frequently self-defeating.

As you begin to work with Xcode, Core Data, Mac OS X, and iOS, you will find yourself at the helm of a sophisticated and powerful development environment. In this book, you will see how to start small and build up to very complex apps. In the initial hours, because the examples are small, you may be tempted to worry about the complexity, but just remember that the complexity will pay off as the examples become more complex.

  • With that overview, you might be interested in the Tutorial “Using Xcode to Write ‘Hello, World’” in Hour 1 of Apple’s Xcode Quick Start Guide. It is 20 pages long and demonstrates precisely these points.
  • + Share This
  • 🔖 Save To Your Account