Polyglot programmer: Playgrounds and generators

Code playgrounds, in which you can interactively test and develop code fragments and chunks, and code generators are hardly new. But improved interpreters and compilers, and the formal overhead required by most modern languages, has brought them to the fore. They are now important tools for many developers.

Playgrounds

pggenxcode

Xcode’s playgrounds are very sophisticated, and an ideal way to explore and learn Swift, or for getting to grips with OS X or iOS development. As with any other Xcode project, you can add source code files and other resources, building your playground into a project uncannily resembling a full-blown app.

Comments can be created using its own Markup Format and then rendered with styled rich text and more. They also provide access to a surprising range of frameworks, including graphics, and your own custom frameworks. However these have various limitations which can trip you up too: you will need to read the documentation carefully for details.

Autocompletion and automatic running make it very easy to write code and to see what it does almost immediately. QuickView allows you to see a floating pane depicting an appropriate graphical representation of many results, without your having to create your own output window.

sdkshaskell

The Haskell app’s playgrounds inevitably run Haskell, and are almost as sophisticated, in that they support graphical output which is displayed in the same window. Even if you intend compiling your Haskell code using the conventional compiler controlled from the command line, you should find them a valuable aid to development, particularly when you are not a complete expert in Haskell.

sdksasobjcexp

All AppleScript development environments are also in effect playgrounds, in that code being edited can be compiled and run whenever you wish. There are no limits imposed on access to alerts, dialogs, and other features. If you are working in an AppleScript-Objective-C environment, then Shane Stanley’s tools provide appropriate playground features for that.

Several code editors now offer the ability to run code in a playground-like environment, including Nikolai Krill’s CodeRunner 2 (App Store, £10.99) and Foobar (App Store, free) from Websecurify.

pggencoderunner

CodeRunner 2 supports 17 proper programming languages, from AppleScript to Swift, and you can install additional language support provided that it can access the interpreter or other means of code execution from the command line. Support provided to these languages is more basic than that in Xcode, but sufficient to check through code routines which can then be incorporated in more substantial source. AppleScript, for example, is able to access its basic human interface calls, together with those supported by installed scripting additions. As an editor, it has excellent autocompletion, and a highly customisable interface.

pggenfoobarpro

Foobar is a bit more basic, but still provides good support for at least a dozen scripting languages; AppleScript retains access to its intrinsic interface and calls to scripting additions. Because of the restrictions imposed by sandboxing on the App Store version, you will probably be better off using FoobarPlus. One slight quirk of these is that they do not (yet) recognise .swift files as Swift source code, and only seem able to open them when plain text.

Code generators

Paw, with the HTTP ready to send a tweet. Note this is shown as Python source in the lower centre pane.
Paw, with the HTTP code ready to send a tweet, showing the required Python source in the lower centre pane.

Paw (App Store, £22.99) is an excellent development environment and code generator for client interfaces for RESTful servers. I have detailed its use here. It can generate code in Python for Requests, Swift for Alamofire and NSURLSession, or in straight HTTP. Additional code generators are available for Ruby, PHP, Objective-C, Java, JavaScript, and more.

pggenpaintcode

PaintCode 2 (App Store, £79.99) generates programmatic human interface elements in four languages (Objective-C, Swift, C#, and SVG) on any of three different platforms, OS X (Objective-C or Swift), iOS (Objective-C, Swift or C# Xamarin), and the Web (SVG). These are centred on StyleKits containing sets of colours, gradients, shadows, images, and variables. A good range of drawing tools and features are provided to help you construct icons, tabs, and other interface elements. Set the language and OS for which you want source code, and that is generated ready to build into your Xcode project.

pggencoreanim

Core Animator (App Store, £79.99) provides tools to develop animations using QuartzCore, which it will then export in two languages (Objective-C, Swift versions 1.2 or 2.0) for OS X or iOS, as complete Xcode projects. The current version has occasionally quit unexpectedly when trying to export under El Capitan, but normally succeeds on a second try.

pggendialogmaker

Dialog Maker (App Store, £4.99) is a simple but time-saving tool for creating the full range of normal AppleScript dialogs, those which do not rely on Objective-C calls or scripting additions. It offers three different types of dialog: set the appropriate one up, and it will copy the requisite AppleScript code ready for you to paste into your script editor.

If you know of more playgrounds or code generators which are useful for OS X development, please let me know.