The Cobra Programming Language Version 0.0.9 Release Notes 2006-05-07 ------------------------------------------------------------------------------ See also: Cobra\ReadMe.text Cobra\Docs\License.text Cobra\Docs\Introduction.text http://CobraLang.com/ In this release: == Additions == * Added Docs\Introduction.text * Added unit testing as a language level feature. You can now write test sections for methods, properties and classes. Because these unit tests can be specified next to what they actually test, they are more likely to be kept up to date. Also, because they are a natural part of the source code, they benefit from development environment features such as syntax highlighting and autocompletion. Finally, more programmers may be encouraged to write unit tests when it is this easy. class WordCounter test wc = WordCounter() ... def _countChars(s as String, c as char) as int test wc = WordCounter() assert wc._countChars('', c'x')==0 assert wc._countChars('x', c'x')==1 assert wc._countChars('X', c'x')==0 # case sensitive assert wc._countChars(' ! ! ', c'!')==2 code count = 0 for ch as char in s if c==ch count += 1 return count * Added indexer declarations: pro [i as int] as Stuff get return _stuff[i] set _stuff[i] = value * Added interface declarations. interface INamed get name as String interface ITalker inherits INamed def talk """ Say what you like with a `print` statement. """ * Added an even shorter form for properties for when the property name matches the variable name (which is quite often). You can use the `var` keyword instead of naming the variable explicitly. var _age as int var _length as decimal ... pro age from var get length from var * The keyword `var` can now be used in the implementation of a property to refer to the variable that matches the property's name. var _reallyLongName = 0 pro reallyLongName as int get return var set assert value>0 var = value * Added augmented assignment version of the recent nil coalesce operator (?). count ?= 0 # same as count = count ? 0 * Added ability to invoke other constructors and base constructors. See Examples\webpages.cobra for an example use. * Added new example, IndentedWriter.cobra. == Changes == * Gave == high level semantics. Essentially a==b means a.equals(b) if either expression has a compile-time type that is a reference type. By contrast, C# will return "false" for ``a==b`` when `a` and `b` are statically typed as `object` *even if they refer to strings with the same contents*. Cobra will correctly return true. In Cobra, use == for equality of object contents (as determined by the object's implementation of `equals`) and use `is` for reference identity. As needed, override the `equals` method from `Object` to define equality for your classes. * Eliminated the `cue` keyword. Use `def` instead: def construct ... * Methods and properties are now virtual by default which means any of them can be overridden in a subclass. This was done to prevent the issue of having to revisit base classes just to tweak their methods and properties so they could be overridden. This also gives the language a more "high level" feel. The keyword `nonvirtual` can now be used to explicitly make a method or property so. * In order to prevent errors, Cobra no longer allows the expression of an `if` or `while` statement to be an assignment such as ``if x=1`` or ``while x+=1``. Most instances are mistakes that lead to runtime errors. Working around this new restriction is easy (fix the comparison or move the assignment). * Extended the webpages.cobra example. * Improved several error messages. == Fixes == * Extended type inference for dictionaries: amount = amountByName[custName] * Fixed the "from" form of properties to allow doc strings. * Fixed a bug where subclasses could not access protected, inherited variables. * Fixed bug when assigning a class to a variable: t = String * Fixed a bug where Cobra would run scripts twice. * Fixed a parser bug regarding the nil-coalesce operator (and its inverse operator) and leading-dotted expressions. * Fixed a bug when passing list or dict literals as arguments. * Fixed bug where 'foo = .foo' gave a false error. ------------------------------------------------------------------------------