Cobra is a discontinued
general-purpose,
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
. Cobra is designed by Charles Esterbrook, and runs on the
Microsoft .NET and
Mono platforms.
It is strongly influenced by
Python,
C#,
Eiffel
Eiffel may refer to:
Places
* Eiffel Peak, a summit in Alberta, Canada
* Champ de Mars – Tour Eiffel station, Paris, France; a transit station
Structures
* Eiffel Tower, in Paris, France, designed by Gustave Eiffel
* Eiffel Bridge, Ungheni, ...
,
Objective-C
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its N ...
, and other programming languages. It supports both
static and
dynamic typing
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
.
It has support for
unit test
In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures&m ...
s and contracts.
It has
lambda expressions, closures,
list comprehension
A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical ''set-builder notation'' (''set comprehension'') as distinct from the use of ...
s, and
generators.
Cobra is an
open-source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
project; it was released under the
MIT License
The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts only very limited restriction on reuse and has, therefore, high license co ...
on February 29, 2008.
Features
;Object-oriented:
:* Namespaces
:*
Classes, interfaces, structs, extensions, enumerations
:*
Methods,
properties
Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property.
Property may also refer to:
Mathematics
* Property (mathematics)
Philosophy and science
* Property (philosophy), in philosophy an ...
, indexers
:*
Mixin
In object-oriented programming languages, a mixin (or mix-in) is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depen ...
s, extension methods
:*
Generics, attributes
;Quality control:
:*
Contracts
A contract is a legally enforceable agreement between two or more parties that creates, defines, and governs mutual rights and obligations between them. A contract typically involves the transfer of goods, services, money, or a promise to ...
,
assertions
:*
Unit test
In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures&m ...
s,
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
Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics. ...
:* Lambdas and
closures
;General productivity:
:*
Exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, a ...
:* Postmortem exception report
:*
Garbage collection
Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclable ...
;
Scripting conveniences:
:* Clean syntax
:* Dynamic binding
:* One-step run
:*
Shebang line (
#!
)
;Miscellaneous:
:* Documentation tool (
cobra -doc
)
:*
Syntax highlighting
Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms. ...
tool (
cobra -highlight
)
Examples
The following examples can be run from a file using
cobra <filename>
.
Hello World
''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses
''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
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 nameand 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