Cobra is a discontinued
general-purpose,
object-oriented programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
. Cobra is designed by Charles Esterbrook, and runs on the
Microsoft .NET and
Mono platforms.
It is strongly influenced by
Python,
C#,
Eiffel,
Objective-C
Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style message passing (messaging) to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was ...
, and other programming languages. It supports both
static and
dynamic typing.
It has support for
unit tests and contracts.
It has
lambda expressions, closures,
list comprehensions, and
generators.
Cobra is an
open-source project; it was released under the
MIT License
The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility.
Unl ...
on February 29, 2008.
Features
;Object-oriented:
:* Namespaces
:*
Class
Class, Classes, or The Class may refer to:
Common uses not otherwise categorized
* Class (biology), a taxonomic rank
* Class (knowledge representation), a collection of individuals or objects
* Class (philosophy), an analytical concept used d ...
es, interfaces, structs, extensions, enumerations
:*
Methods,
properties, indexers
:*
Mixins, extension methods
:*
Generics, attributes
;Quality control:
:*
Contracts
A contract is an agreement that specifies certain legally enforceable rights and obligations pertaining to two or more parties. A contract typically involves consent to transfer of goods, services, money, or promise to transfer any of thos ...
,
assertions
:*
Unit tests,
docstrings
:* Compile-time
nil-tracking
;Expressiveness:
:* Static and dynamic binding
:* List, dictionary, and set literals
:*
in
and
implies
operator
:*
for
expressions
:* Slicing
:* Interpolated strings
:* Compile-time
type inference
:* Lambdas and
closures
;General productivity:
:*
Exception handling
:* Postmortem exception report
:*
Garbage collection
;
Scripting conveniences:
:* Clean syntax
:* Dynamic binding
:* One-step run
:*
Shebang line (
#!
)
;Miscellaneous:
:* Documentation tool (
cobra -doc
)
:*
Syntax highlighting tool (
cobra -highlight
)
Examples
The following examples can be run from a file using
cobra <filename>
.
Hello World
class Hello
def main
print 'HELLO WORLD'
A simple class
class Person
var _name as String
var _age as int
cue init(name as String, age as int)
_name, _age = name, age
def toString as String is override
return 'My name is name
A name is a term used for identification by an external observer. They can identify a class or category of things, or a single thing, either uniquely, or within a given context. The entity identified by a name is called its referent. A person ...
and I am ageyears old.'
References
External links
*
The Cobra blogby Charles Esterbrook
Cobra News Index
{{Common Language Infrastructure
.NET programming languages
Object-oriented programming languages
Programming languages created in 2006
Software using the MIT license