User:SimonReznick/Programming Any Mac/Introduction
Programming the Mac from Scratch
[edit | edit source]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
[edit | edit source]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
- 68000 (68020, 68030, 68040, 680LC40)
- PowerPC (601, 603e, 604, 750 or G3)
- Intel x86/Core/Core2
II. The operating system
- Classic System 6/7
- Classic Mac OS 7.6 - 9.2
- Mac OS X (Cheetah, Jaguar, Panther, Tiger, Leopard)
- Linux
III. The language
- Assembly language
- Pascal
- C
- C++
- AppleScript
- Objective-C
- Java
- RealBasic
- JavaScript
- Perl
- Python
- PHP
- Ruby
- Fortran
- Scheme/Haskell/Lisp/Ocaml
IV. The tools
- Nothing
- Text editor
- Resource editor
- Compilers (commercial)
- Compilers (from scratch)
- Integrated Development Environments (IDEs)
- Macintosh Programmer's Workshop (MPW)
- Think Pascal/Think C
- Symantec C++
- HyperCard
- NeXT tools (Project Builder, Interface Builder)
- XCode
- AppleScript Studio
- Eclipse/other Java
V. Program design, goals and options
- Calculation
- Input and output
- Peripherals
- Memory management
- Loading and running programs
- Shared libraries/dynamic code
- Scripting
- Applications
- Word processing/publishing
- Spreadsheets/analysis
- Graphics
- Music
- Games
- Networking
VI. The method
- Spaghetti
- Structured programming
- Object-oriented programming
- Functional programming
- Libraries and frameworks
- Toolbox
- THINK Class Library
- MacApp
- PowerPlant
- OpenDoc
- Carbon
- Cocoa
- AWT/Swing
- X11/GTK/Qt
VII. The product
- Simple programs
- GUI programs
- The development process
- Distribution models
- Freeware/shareware
- Free/Open-Source software
- Commercial sales (boxed/download)
- 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.
- 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!)
- 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.
- 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:
- Intel Macs
- C programming
- Free tools
or
- Pascal programming
- Classic Macs
- Tools
or
- Games
- Video and graphics
- Assembly language
- 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