Release Notes

Summary

Cobra 0.6 adds a new Exception Report for faster postmortem diagnosis, adds yield statements, improves error checking, makes other improvements to the language and runtime, and fixes over 50 bugs and more.

Exception Report

When a Cobra program throws an uncaught exception, an informative report will be generated that includes:

The report is HTML formatted for easy reading and object navigation. Its purpose is to help you diagnose your program's bug by providing easy-to-read details on the state of the program at the point of the exception.

The exception details include:

The value of this and any objects encountered in the expression breakdown are displayed as HTML links which jump to an "object table" further down in the report. Each object table displays the class name of the object, its .toString value and all its property values in alphabetical order. The object table may itself have links to other objects. After navigating through one or more object references, you can use your browser's back button to revisit previous locations in the report.

Detailed Stack Trace

The exception report can provide details of each stack frame including the usual items (class name, method name, filename, line number) as well as the original values of arguments and the last values of all arguments and locals. As you might expect, any objects are displayed as links which when clicked lead to the table detailing that object.

Capturing these values can be extremely useful for troubleshooting, but also expensive. A program may slow down by 4 X when doing so. For that reason, the detailed stack trace is turned off by default. You can turn it on via a command line option:

cobra -dst MyProgram.cobra
# or the full option name:
cobra -detailed-stack-frame MyProgram.cobra

Clicking Back to Source Code

The assert statement will produce a clickable link for the source location (filename and line number) if the environment variable COBRA_EDIT_LINK is set. Likewise for ensure and require conditions that fail. Below are two examples in Bourne shell. The first invokes a local web server containing a CGI script that will invoke the local editor to open the file at the given line number. The second performs the same task but more directly due to the TextMate editor's direct support of such URLs. The use of "FILE" and "LINE" is literal and case sensitive: The Cobra run-time will substitute the correct values when generating the exception report.

export COBRA_EDIT_LINK='http://localhost:8888/cgi-bin/edit.cgi?file=FILE&line=LINE'
export COBRA_EDIT_LINK='txmt://open/?url=file://FILE&line=LINE'

Example

Here is an example of an exception report (5MB) with a detailed stack trace. Note that reports for your own programs will be easier to understand as the classes, methods and objects will be familiar to you.

Additional Details of the Exception Report

CobraCore.maxDumpObjectCount = 500
class MyClass def extendObjectTable(view as IObjectView) view.addEntry('label text', someValue)

Yield Statements

Cobra now has yield and yield break statements which are equivalent to their C# versions. You can conveniently use these in a normal looking method or property as opposed to explicitly implementing an IEnumerator class that manages state.

Using these, you can have the implementation of IEnumerator or IEnumerator<of T> generated for you.

For an example, see How to Iterate Through Recursive Data With Yield.

Because Cobra is a CLI language and adopts some C# features, you can leverage existing articles. The following may be helpful when trying to understand the yield statement:

New potential errors relating to yield and return include:

Other Language Improvements

# instead of: .foo(name to String) # you can write: .foo(name to !) # where "!" indicates non-nil # instead of: bars = foo.bars to List<of Bar>? # you can write: bars = foo.bars to ? # where "?" indicates a nilable type # now you can assign nil to bars later on: bars = nil

The short forms are strongly preferred as the long forms may imply that the given expression being cast is not already the casted type (such as String or List<of Bar>). Consequently, there are warnings when using the long forms over the short forms such as:

The given expression is already a "String", but nilable. You can just use "to !".
The given expression is already a "String", but not nilable. You can just use "to ?".
if (not name.length) # Cobra is not C return(nil) # Even in C, return is not a function

The idea is to encourage a "normal form" for Cobra syntax so that Cobra code you see in examples, blogs, wikis, books and various projects looks similar. The benefit is the same as that for the conventions of writing English: youspendlesstimedIsCeRnInGSYntax::and::immediately get into semantics.

if (value = .currentValue) inherits String value = value.trim

Previously that had to be written as:

value = .currentValue if value inherits String value = value.trim

or:

value = .currentValue to? String if value value = value.trim

or:

if .currentValue inherits String value = (.currentValue to String).trim # redundant invocation and redundant String reference
class Stuff<of T> inherits List<of T> ... class Stuff<of T, U> inherits Dictionary<of T, U> ...

Library and Runtime Improvements

Command Line Improvements

Compilation failed - 8 errors, 1 warning
Compilation succeeded - 1 warning
Compilation succeeded

No message is printed if Cobra is going to run the program and there are no errors or warnings.

How To's

There are three new How To's:

Improved Error Checking

Cannot find a definition for "nwLine" in "." whose type is "System.IO.TextWriter".

to:

Cannot find a definition for "nwLine" in "Console.out" whose type is "System.IO.TextWriter".

Bug Fixes

Language Bug Fixes

Generic Bug Fixes

for pair in someDict print pair.key, pair.value

Library Bug Fixes

Other Bug Fixes

Tech Notes

This section contains fairly obscure technical notes that the average Cobra user won't need. These notes are for completeness and to aid implementors of the Cobra compiler.

Future Work

The following doesn't cover everything on the TO DO list, but some of the major areas left to tackle include: