Programming

2023-11-15

This note describes how I use OS X as a programmer's tool, for

Every developer uses different tools and has different preferences. Other programmers may need other tools and processes; most of them are supported on OS X. (These notes are based on my current use of OS X 13, Ventura.)

What makes a Mac good for programming?

Many of these programming tools run in a Terminal shell window, which allows you to type Unix commands.

Installing Programming Tools

You have to install tools in the right order, because some tools depend on others. See the installation section for the latest operating system for a step by step cookbook.

Free Tools That I Use

These notes apply to Snow Leopard through Ventura.

System Tools

Apple provides a complete free set of system development tools free with OS X. Install them from the Internet. In a Terminal window, type xcode-select --install. (In Ventura, this queues a request to install the tools using  ► App Store..., which you then invoke.)

The tools include C and C++ compilers, all the Unix tools like Perl, rsync, make, etc.

You can also install Apple's programming development environment including Xcode, header files, documentation, and auxiliary tools. (A free subscription to Apple Developer lets you download additional tools and information for developing Mac and iPhone applications.)

You can type man ssh in a Terminal window to get standard Unix help, useful to Unix programmers.

Shell Environment and /bin

One of the first things I do is to create a directory called /bin in my home directory, and then tell the system to search $HOME/bin for commands, as well as the standard places that Unix-derived systems look. This allows tools I add to my /bin to be used in scripts. To set this up, type the following in a Terminal window:

cd $HOME mkdir bin echo "export PATH=$HOME/bin:$PATH" >> .bash_profile . .bash_profile

Personal library in $HOME/bin

I keep personal shell scripts, Perl programs and modules, and utilities in a subdirectory ~/bin of my home directory. There are over 300 files there. Some of these tools have been incrementally tweaked and developed over more than 30 years, on whatever system I was using at the time. (Probably half are obsolete.) When I need to write a new tool, I often start from an old one and modify it. (This can be a time saver, but risks the propagation of programming errors.) Remember what I always say: "If it's worth doing, it's worth writing a tool that does it."

As described in my CPAN page, I ensure that Perl programs in ~/bin have a first ("shebang") line #!/usr/local/bin/perl, and then create a symlink from /usr/local/bin/perl to /opt/local/bin/perl.

For shell scripts in ~/bin, I make the ("shebang") line #!/bin/sh. This tries to make sure that my personal scripts are executed by a shell that works the same way on all operating systems. (In 2008, some of my shell scripts were broken by Ubuntu 6.10 when they changed /bin/sh to dash... see https://wiki.ubuntu.com/DashAsBinSh. So things can still go wrong.)

Personal SSH keys in $HOME/.ssh

See Setting Up SSH Keys for the steps to generate your ssh keys to enable access to other computers without giving a password every time, and advice on using rsync.

Terminal Shell Customizations

I set my Terminal shell to bash. This is standard on most Linuxes. When bash starts, it invokes $HOME/.bash_profile.

My .bash_profile invokes ssh-add for keys, adds/opt to the PATH for MacPorts, then calls ...

.bashrc which sets up PATH to contain $HOME/bin, then calls ...

MYUSERID.bashrc which defines my personal bash macros, then invokes ...

MYUSERID.bvars which defines variables local to the computer, like server names.

I also create $HOME/.inputrc which sets terminal behavior for the Bash shell. My preferences are:

  set bell-style none
  set completion-ignore-case On
  set mark-symlinked-directories on

I saved default Terminal settings so that when I launch Terminal I get three shell windows with different colored backgrounds. These help me remember what I am doing when I multi-task.

zsh

As of Big Sur, the default Terminal shell was changed to zsh, but I have been lazy and not reworked my environment yet. bash still works as of Ventura. Converting bash configuration to zsh is complex.

Finder and Terminal Settings

In Terminal Settings, I set the Window profile tab settings to show the command key, working directory path, and active process name in the window headeer. I set scrollback to "limit to available memory."

In the Finder, I set View Options to open in list view, and make that the default. In Finder Settings, I customize the sidebar and show all filename extensions.

Java

Java is a powerful modern programming language.

Java is safe for programming and development when used sensibly. Apple provides an optional complete Java runtime environment and compiler. Updates now come from (Oracle) Javasoft. Apple has disabled Java applets in web browsers by default in OS X, because of security attacks by malicious websites. (See https://support.apple.com/kb/DL1572.)

Oracle now packages Java 8 with a control panel viewed in  ► System Settings... ► Java.

Go and Rust

I am learning Go and Rust, using the environments provided by the languages.

Emacs

Emacs is my text editor of choice and has been for over 30 years. I use Aquamacs Emacs, derived from Emacs 24 and adapted to the Mac by David Reitter, and customize its settings to be like Emacs on other platforms.

Homebrew

Homebrew provides hundreds of Open Source Unix tools compiled for OS X, free. It can be used to install the latest versions of important programmer's tools, such as rsync.

I use Homebrew to install uni2ascii, ImageMagick, subversion, psutils, Perl, Go, Ruby, rsync and other Terminal commands. (Some of these tools come with the Mac, but Homebrew may install a newer version.)

Homebrew is an alternative to Macports.

ImageMagick

ImageMagick is a free package of image processing programs. I install it with Homebrew. One thing I use it for is automatically generating thumbnails for picture galleries. Another task is generating packed sprite files: see CSS Sprites.

MySQL

MySQL is a free relational database, now owned by Oracle. I install it with Homebrew (see above). It is straightforward to download and install on the Mac. Among other uses, I create web pages such as the indexes for this website by loading a database with tabular information and then generating HTML from a MySQL query.

Perl

Perl is a wonderful quirky text processing language. Perl is free and included with Mac OS X system tools (though Apple gives you an old version; get a better one from Homebrew). I have written many personal tools in Perl and used them on multiple platforms. Perl is also useful for writing server-side web applications.

CPAN

CPAN, the Comprehensive Perl Archive Network, is a free community-provided library of Perl programs. To install Perl modules, open a Terminal window and do sudo -H cpan and then issue CPAN install commands.

Some CPAN bundles I use are Bundle::CPAN, DBI, DBD::mysql, Crypt::CBC, Crypt::Twofish, Net::DNS, Net::Subnet, News::NNTPClient, Geo::IP::PurePerl, Digest::SHA, Compress::Raw::Zlib, Compress::Raw::Bzip2, LWP::Simple, XML::Simple

(Install Homebrew before CPAN, and update your environment, before installing CPAN modules. If you are installing DBD::mysql, install MySQL first.)

Apache

Apache is a widely used and powerful web server, included in OS X. It is useful for testing web applications before deploying them on a server. You can add features to it by editing its configuration files in /etc/apache2. Apache is shipped with OS X but not enabled in Lion and later versions. See the instructions for each macOS release to see how to turn it on.

PHP, Ruby, Python

PHP, Python, and Ruby are scripting languages, no longer supported by OS X. Installing them from Homebrew if you need them. You can enable their use in Apache by editing the Apache configuration files.

Other

I install HTML Tidy 5.8.0 from Homebrew; it supports HTML5.

Commercial Developer Tools That I Use

OmniGraffle

A drawing tool oriented toward diagrams and charts is very useful. OmniGraffle Pro is slick (I like it better than Microsoft Visio on Windows, or trying to draw in PowerPoint).

Affinity Photo

If you are doing web development with graphics, you may be able to avoid spending the $120/yr that Photoshop costs from Adobe. You can get a free version of GIMP for OS X, or buy Adobe Elements or Affinity Photo.

Home | FAQ © 2010-2023, Tom Van Vleck updated 2023-11-15 10:03