Software Development

Emulating "defer" in C, with Clang or GCC+Blocks

In the Go language (and now Apple’s Swift), there’s a new control-flow mechanism: defer.

When you tag a function call with the defer keyword, its execution is deferred until the end of the current scope. This makes it easy to construct an ad-hoc use of the RAII pattern — handy for placing resource initialization and finalization next to each other, to make it less likely that you’ll forget to finalize a resource.

I was curious whether it was possible to do something similar in C. It turns out it’s pretty straightforward.

LLVM generates code that generates code

Back from last week’s LLVM developer’s meeting, I’d like to talk about one of my favorite features of LLVM .

LLVM is the compiler infrastructure that underlies Clang, Vuo, and many other projects. It’s a set of libraries to help you build compilers (and more). Among other things, LLVM provides a C++ API for generating LLVM Intermediate Representation (LLVM IR) code. LLVM IR is an assembly language for a hypothetical computer. LLVM IR code can be either interpreted or compiled down to native code.

So LLVM provides this C++ API for generating LLVM IR code — but it doesn’t stop there. LLVM can also generate C++ code that generates LLVM IR code. In other words, LLVM can literally write part of your compiler for you!

Kosada is Developing a Next-Generation Programming and Performance Environment for Multimedia Artists

Kosada is developing Vuo, a next-generation visual programming environment. It will enable multimedia artists to create powerful real-time audiovisual projects, data visualizations, and apps — all without writing code.

With Vuo, non-programmers will be able to create their own multimedia software for interactive art and music performances, animations, visualizations, games, special effects, museum exhibits, kiosks and other artistic projects. Rather than writing code in a traditional computer language, the composer will drag and drop building blocks onto a canvas, connecting those blocks with cables to create the composition. Unlike most programming environments, artists will be able to interact with their Vuo compositions while they are running, allowing for live improvisation.

Compiling code with the Clang API

Have you tried Clang yet? Clang is an open-source compiler, under active development, that aims to replace GCC for compiling C, C++, and Objective-C. Compared to GCC, Clang is faster, while generating comparably fast code, and prints more useful error messages.

Clang is also better for developers who want to compile code programmatically. Unlike GCC, Clang is designed to be both a tool and an API. That makes Clang’s source code easier to understand and reuse. And, for those of us working on projects incompatible with GCC’s GPL license, it’s good to know that Clang is distributed under the BSD license.

Kosada is working on a cool new project that’s built on top of Clang and its underlying framework, LLVM. While using Clang for this project, I’ve been pleased to see how simple it is to write code that builds other code. Simple in retrospect, anyway! The code I wrote turned out to be simple, but it took lots of digging through the Clang source code to figure out what to write. So here’s my first contribution to the Clang community: two examples of using the Clang API to build code programmatically.

Announcing: iOS Development on 1 Page

When you’re getting started with iOS development, it’s hard to figure out those first steps. What developer tools do you need? What are some good tutorials to start with? Where to begin delving into Apple’s thousands of pages of documentation?

That’s why I created iOS Development on 1 Page — a not-overwhelming guide for iOS newbies.

Is there any essential info about iOS development that should be added to iOS Development on 1 Page? Let me know!

Are you sure you want to localize?

It’s a wonderful fact about the world that humans have thousands of living languages. And a wonderful fact about many software development environments that they provide ways to create versions of applications localized into the most common of those languages. But before localization (or should I say world-readiness) sweeps you off your feet, let me tell you about some unexpected difficulties with Kineme’s first localized application.

When did Firebug get so terrible?

Firebug is one of those vital extensions for web developers and designers who use Firefox. I have been faithfully updating it whenever it whines at me to update it, which is usually every minor version, and it pretty much just works. Firebug and I have a romance of debugging HTML, CSS, and more recently the Javascript and JQuery that I use in Select Other, Processing, and some more recent custom development for Slight High.

The honeymoon ended recently…

Example of IOSurfaceCreateMachPort and IOSurfaceLookupFromMachPort

The IOSurface framework lets you pass a reference to an IOSurface — a kind of pixel buffer — from one process to another. Here’s an example of how to pass an IOSurface through a mach port using the functions IOSurfaceCreateMachPort and IOSurfaceLookupFromMachPort.