Est. 2006 Intermediate

Cobra

A .NET and Mono language that fused Python-style indentation syntax with static typing, Eiffel-style contracts, and unit tests built directly into the grammar.

Created by Charles "Chuck" Esterbrook (Cobra Language LLC)

Paradigm Multi-paradigm: Object-Oriented, Imperative, Functional, Contract-based
Typing Static and dynamic, Strong, Inferred, with compile-time nil tracking
First Appeared 2006
Latest Version Cobra 0.9.6 (December 23, 2013)

Cobra is an object-oriented programming language for the .NET and Mono platforms, designed by Charles “Chuck” Esterbrook and developed from 2006 to 2013. Its premise was unusually explicit for a language project: rather than invent anything new, take productivity features that already existed in separate languages — Python’s clean indentation-based syntax, C#’s compiled performance and static typing, Eiffel’s design-by-contract, Objective-C’s dynamic binding — and put all of them in one language at the same time. Cobra was, in its author’s words, “a practical synthesis of already-proven features that are currently scattered across multiple languages.”

The synthesis worked. Cobra is a genuinely pleasant language to read, and its treatment of contracts and unit tests as first-class syntax rather than library calls remains one of the more compelling arguments for building quality control into a grammar. What it never found was users. Development stopped after version 0.9.6 in December 2013, and the language never reached a 1.0.

History & Origins

From Webware to Cobra

Before Cobra, Esterbrook was known in the Python community as the creator of Webware for Python, an open-source suite of web frameworks and components that predated the modern Python web stack. That background matters for understanding Cobra’s design: it was written by someone who had spent years being productive in a dynamically typed scripting language and who wanted to keep that experience while getting compiled performance and compile-time error checking.

According to the project’s own release-notes page, the earliest listed release is Cobra 0.0.2, dated February 10, 2006, followed by a steady drumbeat of small releases through 2006 and 2007. During this period the language was developed privately by Cobra Language LLC rather than as an open project.

Going open source

On February 29, 2008, Cobra was released as open source under the MIT license — an event picked up by Computerworld, which ran a piece headlined “Cobra language slithering to open source.” Version 0.8.0 followed in April 2008, adding built-in sets, extensions, bitwise operators, a configurable number type, and a -turbo compiler option, alongside roughly thirty bug fixes.

Through 2009 and 2010 the project reportedly moved to date-stamped releases rather than version numbers, while the community produced editor integrations, a handful of libraries, and IDE add-ins. Cobra also drew mainstream coverage in this period: MSDN Magazine ran a “Polyglot Programmer” column on it in June 2009, and Red Gate’s Simple-Talk published both a review of the language and an interview with Esterbrook on April 26, 2010.

The 0.9 series and the end

Numbered releases resumed with Cobra 0.9.0 on September 26, 2012. Further releases followed — 0.9.1 with .NET 4.5 installation support, 0.9.2 on November 26, 2012 with roughly thirty refinements, and 0.9.4 on May 24, 2013 — before Cobra 0.9.6 on December 23, 2013, which turned out to be the last. Ports to the JVM and to Apple’s Objective-C runtime were listed on the download page as “underway”; neither shipped.

The project’s own “Why Cobra?” document, describing the state of things as of Winter 2013, called the language a “late beta” offering. It never left that state.

Design Philosophy

Esterbrook laid out Cobra’s rationale as a complaint about having to choose:

Right now, if you want software contracts in your language, how can you get them? The answer is to use Eiffel or D. What if you want static and dynamic binding? Use Objective-C or Boo. What if you want expressiveness and quick coding? Use Python, Ruby or Smalltalk. What if you want runtime performance? Use C#, Java, C++, etc. What if you want first class language support for unit tests? Use D. But what if you want all of those?

The resulting four goals were:

  1. Quick, expressive coding — achieved by following Python and Ruby, “but not religiously.”
  2. Fast execution — achieved by favoring static typing and leaning on .NET/Mono for machine code generation.
  3. Static and dynamic binding — using the .NET type system at compile time and the .NET runtime for dynamic dispatch.
  4. Language-level support for quality — contracts and assertions from Eiffel, doc strings and unit tests inline, plus Cobra’s own compile-time nil tracking.

The last point is the one Cobra pushed hardest. Quality control mechanisms that most languages relegate to libraries, attributes, or separate test files were built into the syntax, on the theory that a test you can write two lines below the method it tests is a test you will actually write.

Key Features

Contracts and inline unit tests

A Cobra method can carry require and ensure clauses and a test block alongside its body. This is the sample that greeted visitors on the language’s home page:

class SmallSample

    var _random = Random()

    def randomString(length as int, alphabet as String) as String
        require
            length > 0
            alphabet <> ''
        ensure
            result.length == length
        test
            utils = SmallSample()
            assert utils.randomString(5, 'ab').length == 5
            s = utils.randomString(1000, 'a')
            for c in s, assert c == 'a'
        body
            sb = StringBuilder()
            for i in length
                c = alphabet[_random.next(alphabet.length)]
                sb.append(c)
            return sb.toString

    def main
        alphabet = 'abcdefghijklmnopqrstuvwxyz'
        for i in 10, print .randomString(10, alphabet)

Note result in the ensure clause, referring to the method’s return value — straight from Eiffel — and the built-in test runner that could execute those test blocks without any external framework.

Compile-time nil tracking

Cobra types are non-nilable by default; a type that may be nil is written with a trailing ? (s as String?). The compiler tracks nilability through the program and rejects code that could dereference nil. Cobra had this well before non-nullable reference types became standard equipment in mainstream languages — C# did not get nullable reference types until C# 8.0, released with .NET Core 3.0 in September 2019.

Static and dynamic binding together

A variable declared as dynamic defers member lookup to runtime, in the manner of Objective-C, while everything else is checked statically. Type inference means i = 5 declares an int without ceremony, so static typing costs very little syntax.

Python-shaped syntax, .NET semantics

Indentation defines blocks, there are literals for lists, dictionaries and sets, string interpolation, slicing, for and if expressions, lambdas and closures, and an implies operator. Underneath, it is ordinary .NET: classes, interfaces, structs, properties, indexers, generics, attributes, mixins, and extension methods, all interoperating with C# and VB.NET assemblies.

Postmortem exception reports

Introduced in Cobra 0.6.0, an uncaught exception generates an HTML report containing environment details, a level-by-level breakdown of the expression that failed in a failed assert/require/ensure, and navigable object tables showing property values. With the optional detailed stack trace enabled (cobra -dst), the report also captures the original and final values of every argument and local in each stack frame. The release notes were candid that this instrumentation is expensive — they state a program may run about 4× slower with detailed stack traces turned on, which is why the option is off by default. That figure is the project’s own characterization rather than a published benchmark, and no measurement methodology was given.

Other touches

Cobra defaults numeric literals with decimal points to .NET’s decimal type rather than binary floating point, on the grounds that accurate decimal math is what most programs actually want. It supports #! shebang lines and one-step run (cobra program.cobra compiles and executes), so a Cobra file can be used like a script despite being compiled.

Implementation

Cobra’s compiler is self-hosted — written in Cobra — and takes the pragmatic route of generating C# source code, which it then feeds to the platform’s C# compiler, rather than emitting CIL bytecode directly. This is why the Simple-Talk review described Cobra as functioning much like a preprocessor for C#: the output is ordinary .NET assemblies, fully usable from C# and VB.NET projects.

The two officially supported runtimes were Microsoft .NET on Windows and Mono elsewhere; according to the project’s download page, the final releases required approximately .NET 4.0 or later, or Mono 2.10 or later. The same page reportedly named Mac OS X, Linux, BSD, and Solaris among the Mono-hosted targets, though the project published no per-platform support matrix and those claims cannot be independently verified today. Windows builds shipped as .zip, Unix-like builds as .tar.gz.

Beyond the compiler, the distribution included a unit test runner, a documentation generator, a syntax highlighter, and a shared/static data lister.

Current Relevance

Cobra is dormant. There has been no release since December 2013, the language never reached 1.0, and the announced JVM and Objective-C backends were never completed. The original site at cobra-language.com is still reachable as an archive of the documentation, release notes, samples, and forums — though only over plain HTTP, and its long-term availability is uncertain — and mirrors of the source exist on GitHub. There is no active maintenance.

The .NET ecosystem also moved: several things Cobra offered as differentiators arrived in C# itself over the following decade — type inference, lambdas and closures, dynamic binding (dynamic in C# 4.0, 2010), and non-nullable reference types (C# 8.0, 2019). F# covered the functional and concise-syntax territory with Microsoft’s backing. A single-maintainer language competing on a platform whose first-party language absorbs its features is in a difficult position, and Cobra’s small ecosystem never reached the size that would have sustained it independently.

Why It Matters

Cobra is worth studying less for what it achieved than for the argument it makes. Its central claim — that contracts, unit tests, and nil-safety belong in the grammar rather than in libraries, conventions, or a separate test directory — has aged well. The industry arrived at the same conclusion by different routes: Rust and Kotlin and Swift made nil-safety a type-system concern, Zig and D put tests in source files, and static analysis tooling grew to do by inspection what Cobra tried to do by syntax.

It is also a clear case study in the economics of language adoption. Cobra was well designed, well documented, MIT-licensed, self-hosted, integrated with a range of editors, and reviewed favourably in outlets like MSDN Magazine and Simple-Talk. None of that was sufficient. What it lacked was an organization behind it, a killer application, and a community large enough to survive its author moving on — the three things that reliably separate the languages people use from the languages people admire.

Sources

Timeline

2006
Charles Esterbrook, previously the creator of the Webware for Python web framework suite, begins releasing Cobra; according to the project's release-notes page, the earliest listed release is Cobra 0.0.2 on February 10, 2006
2006
Cobra 0.1.0 reportedly released in May, followed by a series of 0.1.x builds and Cobra 0.2.0 later in the year
2007
Cobra 0.4.0 and 0.5.0 released during the first half of the year; Cobra 0.6.0 follows on December 31, adding yield statements and the HTML-formatted postmortem exception report
2008
Cobra is released as open source under the MIT license on February 29, after two years of closed development
2008
Cobra 0.8.0 released in April, adding built-in sets, extensions, bitwise operators, a configurable number type, a -turbo compiler option, and roughly thirty bug fixes
2010
Visual Cobra, a Visual Studio 2010 extension by Matthew Strawbridge providing Cobra syntax colouring, is released on November 13; Red Gate's Simple-Talk publishes an article on Cobra and an interview with Esterbrook, both dated April 26 of the same year
2012
Cobra 0.9.0 released on September 26, the first release in the 0.9 series; the Cobra Koans learning project and a MonoDevelop add-in were reportedly announced around the same period
2012
Cobra 0.9.1 reportedly adds support for installing on .NET 4.5; Cobra 0.9.2 follows on November 26 with roughly thirty refinements and fixes
2013
Cobra 0.9.4 released on May 24; the project's own documentation describes the language at this point as a "late beta" offering
2013
Cobra 0.9.6 released on December 23 — the final release. Announced ports to the JVM and to Apple/Objective-C were still listed as "underway" and never shipped

Notable Uses & Legacy

The Cobra compiler itself

Cobra's compiler is self-hosted: after bootstrapping, the tokenizer, parser, AST, analysis passes, and code generator were all written in Cobra. The compiler emits C# source and hands it to the C# compiler rather than generating CIL directly, which made the backend far simpler to maintain for a one-person project.

Sonny (JSON encoder/decoder)

Announced on the Cobra site in 2009, Sonny is a JSON encoder and decoder written in pure Cobra — one of the earliest third-party libraries demonstrating the language outside its own toolchain.

Overlap (SCGI server adapter)

Also announced in 2009, Overlap provides SCGI support so that Cobra programs can act as an SCGI backend for any web server that speaks the protocol; the project's wiki names Apache, Lighttpd, and Nginx. It was the project's answer to "can I write a web application in this?"

Banter (IRC library)

A library for working with IRC written in Cobra, announced in 2009. Together with Sonny and Overlap it represents the small ecosystem of community libraries the language accumulated during its most active period.

Editor and IDE integrations

Community contributors built Cobra support for a notably wide range of editors for such a small language. Visual Cobra for Visual Studio 2010 is the best documented; the project's wiki additionally lists integrations for MonoDevelop, SharpDevelop, CodeLite, Vim, Notepad++, GtkSourceView (gedit, scribes), and the Pygments syntax highlighter.

Language Influence

Running Today

Run examples using the official Docker image:

docker pull
Last updated: