User:SimonReznick/Programming Any Mac/Introduction

Programming the Mac from Scratch
Somewhat inspired by the Linux from Scratch (LFS) project

Are you a Macintosh owner? Have you always wanted to write programs for your Mac, but weren't sure how to get started? Did you always want to know more about how your Mac works?

I first bought a Macintosh in 1995, shortly after the first major transition Apple made in the architecture of the Macintosh line - the switch from Motorola 68000-family microprocessors to PowerPC processors.

At the time, I wasn't sure exactly what this meant. I did know that Apple had done a lot of work to make sure Mac programs would keep running on pretty much any machine they sold. And at the time, that was a lot of machines! This was before the return of Steve Jobs and the scaling back of Apple's computer catalog to just a home line (iMac), a professional line (Power Macs) and portables (iBooks and PowerBooks). At one point, Apple had dozens of different models on the shelf, with names like Quadra, Performa, Centris... some of which were simply renamed versions of previous machines, or differed only by the speed of the CPU or whether or not the machine had a CD drive.

But the thing that impressed me was, almost all of these machines could run the same software. Given the computer met the minimum hardware requirements, a Mac from 1998 could run software written in 1988! That kind of backward compatibility isn't easy, considering the hardware had changed completely. The CPU changed from 68k to PowerPC. The drives changed from SCSI to ATA. The keyboard and mouse went from ADB to USB. Proprietary video systems were replaced with standard ATI or Nvidia cards. And the floppy drive was eliminated completely.

'''How did Apple do it? What magic did they use?'''

Well, if you're as interested in the guts of your Mac as I am in mine, come with me on this journey of learning and experimentation. I'm not the first to head down this path, but in doing so I hope to "Think Different" and make a tutorial that allows you to dive in at any level of expertise and go in one of several different directions without tediously wading through subjects that don't interest you.

The plan
My goal is to teach you to write programs for the Mac (any Mac) with nothing more than your hands, head, and the software that came in the box. This is harder than it sounds - partly because the classic Macs didn't come with much in the way of development tools, and partly because there are so many options in tools, languages, and documentation.

Nevertheless, here is the plan. It is not linear - you can start at the beginning and follow any of a number of different paths:

I. The CPU
 * 1) 68000 (68020, 68030, 68040, 680LC40)
 * 2) PowerPC (601, 603e, 604, 750 or G3)
 * 3) Intel x86/Core/Core2

II. The operating system
 * 1) Classic System 6/7
 * 2) Classic Mac OS 7.6 - 9.2
 * 3) Mac OS X (Cheetah, Jaguar, Panther, Tiger, Leopard)
 * 4) Linux

III. The language
 * 1) Assembly language
 * 2) Pascal
 * C
 * 1) C++
 * 2) AppleScript
 * 3) Objective-C
 * 4) Java
 * 5) RealBasic
 * 6) JavaScript
 * 7) Perl
 * 8) Python
 * 9) PHP
 * 10) Ruby
 * 11) Fortran
 * 12) Scheme/Haskell/Lisp/Ocaml

IV. The tools
 * 1) Nothing
 * 2) Text editor
 * 3) Resource editor
 * 4) Compilers (commercial)
 * 5) Compilers (from scratch)
 * 6) Integrated Development Environments (IDEs)
 * 7) Macintosh Programmer's Workshop (MPW)
 * 8) Think Pascal/Think C
 * 9) Symantec C++
 * 10) HyperCard
 * 11) NeXT tools (Project Builder, Interface Builder)
 * 12) XCode
 * 13) AppleScript Studio
 * 14) Eclipse/other Java

V. Program design, goals and options
 * 1) Calculation
 * 2) Input and output
 * 3) Peripherals
 * 4) Memory management
 * 5) Loading and running programs
 * 6) Shared libraries/dynamic code
 * 7) Scripting
 * 8) Applications
 * 9) Word processing/publishing
 * 10) Spreadsheets/analysis
 * 11) Graphics
 * 12) Music
 * 13) Games
 * 14) Networking

VI. The method
 * 1) Spaghetti
 * 2) Structured programming
 * 3) Object-oriented programming
 * 4) Functional programming
 * 5) Libraries and frameworks
 * 6) Toolbox
 * 7) THINK Class Library
 * 8) MacApp
 * 9) PowerPlant
 * 10) OpenDoc
 * 11) Carbon
 * 12) Cocoa
 * 13) AWT/Swing
 * 14) X11/GTK/Qt

VII. The product
 * 1) Simple programs
 * 2) GUI programs
 * 3) The development process
 * 4) Distribution models
 * 5) Freeware/shareware
 * 6) Free/Open-Source software
 * 7) Commercial sales (boxed/download)
 * 8) Network applications/services

This is a long journey, and covers a lot of ground. My philosophy is to take "baby steps" and cover a little bit of a topic each day, and not worry about following a rigid structure. I believe that if you get interested in a tangential topic, you should be able to ask questions without delay, and investigate without losing track of where you are in the big picture. You should always be able to return to the path once you've finished your "subroutine" covering a topic in detail. After all, isn't this what hypertext on the Web is best at? It's what makes it more flexible than just reading a book.

Speaking of which, you may wonder why this tutorial is necessary when there are so many good books out there. There are a few reasons.


 * 1) A lot of Mac programming books are very outdated. I know because I own about 300 of them. (And no, I haven't read them all - I collect them!)
 * 2) A book will take you through a limited set of topics in a specific order. It may not cover everything you want to learn, and may cover many subtopics which don't interest you.
 * 3) This is an experiment in learning strategy, and I hope to learn as I teach - which means I would either have to write my own book to throw on the pile (and likely be dissatisfied with the result) or read everything I can on the topic before regurgitating it on the Web for you. That sounds like a lot of work!

In this tutorial, you should be able to skip around as you see fit:


 * 1) Intel Macs
 * 2) C programming
 * 3) Free tools

or


 * 1) Pascal programming
 * 2) Classic Macs
 * 3) Tools

or


 * 1) Games
 * 2) Video and graphics
 * 3) Assembly language
 * 4) PowerPC

...or any number of other paths suited to what you're interested in learning!

So, to get started. Let's talk about what programs are. Next topic: Code vs. hardware