Brendan Tompkins [MVP]

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
What is Air Code, and What's its Purpose?

I think I first heard the term “Air Code” on DNR, although I’m not sure exactly who said it (Mark Miller maybe? Rory Blyth?)  but I think it’s a valuable and often overlooked as a tool for communicating programming concepts.  

What is Air Code?

Air Code  n. A bit of software code, written in a particular language, compiled using an imaginary compiler.

This past week, I asked Sahil a question, and he replied with the following snippet of code, to illustrate a point he was making:

partial class Program{
 static void Main(string[] args) {
 Man Brendan =
new Man();
 
Console.WriteLine(Brendan.MakeSound());
 Type t = Brendan.GetType();
 Console.WriteLine(t.BaseType.ToString());
 }
}

public class Monkey {
  public string MakeSound() {
    
return ("RRR !!! RRR!!!");
  }
}

class Man : Monkey {
 
public new string MakeSound() {
    
return ("How do I find the base class?");
  }
}

The point of Air Code isn’t to write code that you expect will actually compile – it’s useful when you want to communicate how to do something in a particular language, but don’t want to worry too much about syntax. I mean, we all use ReSharper or CodeRush anyway, right? We’re going to know if the code has errors way before we hit that compile button, so why waste time compiling code?  Actually, I think Sahil’s code will compile (that’s just in his nature), but even if it didn’t it would still be good Air Code.

How is Air Code different from pseudocode?  

Pseudocode: n. a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language.

Air Code is often actually written in a particular language and it’s intentionally not formally styled.  Its main purpose is really to say “Here’s how to do this, but hey, I only compiled this with my air compiler, so don’t hold me accountable if there are errors.”  I think it’s a useful concept, because it allows you to quickly communicate an idea without worrying about someone actually trying to compile it, correct you in comments, or then email you, saying, “My compiler is saying that it can’t find the Sytsem.XML namespace!” 

Are there any formal conventions to indicate that code is actually Air Code? 

There are now!  I’m proposing the [AirCode] attribute to indicate that you shouldn't actually do anything as silly as try to compile the code you’re seeing.  So if if you see this attribute on my blog anywhere, it means, that the code probably won’t compile.  So  go ahead and email that code!  Blog it!  Don’t compile, use Air Code! You’ll feel liberated! 

-Brendan


Posted 02-27-2005 9:14 PM by Brendan Tompkins

[Advertisement]

Comments

Geoff Appleby wrote re: What is Air Code, and What's its Purpose?
on 02-27-2005 7:44 PM
Without knowing the actual terminology, I've been using aircode for a long time :) Hell, aircode _is_ my pseudo code!

That's not a bad idea however, marking stuff with an aircode attribute. in fact, why not take it one step further - write yourself an article (what a goo dexcuse to start :) - that is, put it in the articles section - with the code listing describing the aircodeattribute class. then whenever you use the aircode attribute, hyperlink it to that page so that people can find out what the hell it means.

Hell, i'm bored, here you go *laughs* (Deliberately written in VB to confuse people, since you'll likely write C# examples :P

''' -----------------------------------------------------------------------------
''' <summary>
''' Signifies that the following code is for example purposes, and likely doesn't compile
''' </summary>
''' <remarks>
''' Copyright CodeBetter.Com via DNR
''' </remarks>
''' -----------------------------------------------------------------------------
<AttributeUsage(AttributeTargets.All, AllowMultiple:=False)> _
Public Class AirCodeAttribute
Inherits System.Attribute

Public Overrides Function ToString() As String
Dim oBuilder As New System.Text.StringBuilder
oBuilder.AppendFormat("This is the AirCodeAttribute.{0}", vbCrLf)
oBuilder.AppendFormat("Use of this attribute indicates that the code it is applied to has not been tested and likely won't compile. {0}", vbCrLf)
oBuilder.Append("It marks a section of code that is for example only.")
Return oBuilder.ToString
End Function
End Class
Geoff Appleby wrote re: What is Air Code, and What's its Purpose?
on 02-27-2005 7:46 PM
Ooh, throw a couple of code errors into it and make sure that the code listing for the aircodeattribute is itself marked with aircode attribute!!!!

Attribute recursion! W00t!
Sahil Malik wrote re: What is Air Code, and What's its Purpose?
on 02-27-2005 9:36 PM
LOL, you just had to blog about that code :).

SnippetCompiler works for .NET 2.0 now, so one neat thing about such quick write'n'forget code is - it's much easier to do now.

BTW, I find partial classes incredibly useful in writing aircode.

Man, why can't the whole world move to .NET 2.0.
Raymond Lewallen wrote re: What is Air Code, and What's its Purpose?
on 02-28-2005 5:19 AM
Because some of us work for the gov't and they are slow to move, and certainly won't authorize moving platforms or frameworks until its been released for awhile. That's they way its always worked for me in various areas of the public sector.
Brendan Tompkins wrote re: What is Air Code, and What's its Purpose?
on 02-28-2005 7:09 AM
"LOL, you just had to blog about that code :). "

Sahil, you are 100% right on. And that snippet isn't even Air Code! It took me all weekend to figure out how to get it into a post!
Brendan Tompkins wrote re: What is Air Code, and What's its Purpose?
on 02-28-2005 7:10 AM
Geoff this is absolutely fantastic! I'm going to port it to C# and COBAL.
Darrell wrote re: What is Air Code, and What's its Purpose?
on 02-28-2005 7:39 AM
The problem with air code is then every cut-n-paste programmer (term used LOOSELY) will:
1. Ask why it doesn't compile, or
2. Prove you wrong by saying it doesn't compile so you don't know what you are doing.

:)
Brendan Tompkins wrote re: What is Air Code, and What's its Purpose?
on 02-28-2005 7:45 AM
Yep. But when you have the [AirCode] att at the top of your code, you can just point them there. Hey, and if you're just thinking out loud, then it's probably better that your code doesn't compile in the first place! Less chance that smelly code will get inadvertently introduced into someone's project.
Scott Isaacs wrote re: What is Air Code, and What's its Purpose?
on 03-01-2005 6:19 PM
Of course us VB developers will be using angle brackets:

<AirCode> _
Private Sub DoNothing()
Exit Sub
End Sub
Brendan Tompkins wrote re: What is Air Code, and What's its Purpose?
on 03-02-2005 7:24 AM
Scott! Yes, the AirCode attribute so far has only been coded for VB, see Geoff's reply above. Your use is exactly correct (which is to say that it's completely incorrect).
Geoff Appleby wrote re: What is Air Code, and What's its Purpose?
on 03-04-2005 2:15 AM
Yes Scott, to have used it in the correct manner you needed broken code.

This would work:
<AirCode> _
Private Sub DoNothing()
Exit Function
End Sub

So would this:
<AirCode> _
Private Sub DoNothing()
string foo = "Doh!";
Exit Sub
End Sub

And probably my favourite:
[AirCode] _
Private Sub DoNothing()
Exit Sub
End Sub

It's only broken in the simplest way, and it only if you include the attribute in the first place :)
Peter's Gekko wrote sqlInjection attack on a LIKE query
on 04-08-2005 1:57 PM
If SQL had known attributes I should have decorated my Like query with [AirCode]. Several comments questioned...
Raymond Lewallen wrote Taking responsibility for plagarism
on 07-27-2005 9:34 AM
SqlServerCentral address a recent issue they had with an author guilty of plagarism.
Raymond Lewallen wrote Taking responsibility for plagarism
on 07-27-2005 9:44 AM
SqlServerCentral addresses a recent issue they had with an author guilty of plagarism and issues an apology.
David Hayden wrote Builder Design Pattern - Part 2 of 3
on 10-26-2005 4:40 PM
As mentioned in my previous post, the DbConnectionStringBuilder Class mentioned in Pro ADO.NET 2.0 allows...
XIU’s Blog » Blog Archive » links for 2006-06-03 wrote XIU&#8217;s Blog &raquo; Blog Archive &raquo; links for 2006-06-03
on 06-02-2006 8:29 PM
gogole wrote re: What is Air Code, and What's its Purpose?
on 07-11-2006 9:33 AM
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
wordzguy: Less-pseudo pseudocode wrote wordzguy: Less-pseudo pseudocode
on 11-07-2006 1:22 AM
Less-pseudo pseudocode by wordzguy () | LjSEEK.COM wrote Less-pseudo pseudocode by wordzguy () | LjSEEK.COM
on 11-07-2006 1:22 AM
anti-keseronokan » Blog Archive » Rummage 16/03/2005 wrote anti-keseronokan &raquo; Blog Archive &raquo; Rummage 16/03/2005
on 01-02-2007 5:03 AM
Adding Action Filters to MonoRail Controllers « Random Code wrote Adding Action Filters to MonoRail Controllers &laquo; Random Code
on 03-02-2008 7:06 PM

Pingback from  Adding Action Filters to MonoRail Controllers &laquo; Random Code

Add a Comment

(required)  
(optional)
(required)  
Remember Me?