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 pro ...
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 ...
. Cobra is designed by Charles Esterbrook, and runs on the
Microsoft .NET
The Microsoft .NET strategy is a marketing plan that Microsoft followed in the early 2000s. Steve Ballmer described it as the company's "most ambitious undertaking since Internet Strategy Day in 1995". In support of this strategy, between 2000 and ...
and
Mono
Mono may refer to:
Common meanings
* Infectious mononucleosis, "the kissing disease"
* Monaural, monophonic sound reproduction, often shortened to mono
* Mono-, a numerical prefix representing anything single
Music Performers
* Mono (Japanese b ...
platforms.
It is strongly influenced by
Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
,
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, M ...
,
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 NeXTS ...
, and other programming languages. It supports both
static
Static may refer to:
Places
*Static Nunatak, a nunatak in Antarctica
United States
* Static, Kentucky and Tennessee
*Static Peak, a mountain in Wyoming
**Static Peak Divide, a mountain pass near the peak
Science and technology Physics
*Static el ...
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&mda ...
s and contracts.
It has
lambda expressions, closures,
list comprehension
A list comprehension is a Syntax of programming languages, syntactic construct available in some programming languages for creating a list based on existing list (computing), lists. It follows the form of the mathematical ''set-builder notation'' ( ...
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 comp ...
on February 29, 2008.
Features
;Object-oriented:
:* Namespaces
:*
Class
Class 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 differentl ...
es, interfaces, structs, extensions, enumerations
:*
Method
Method ( grc, μέθοδος, methodos) literally means a pursuit of knowledge, investigation, mode of prosecuting such inquiry, or system. In recent centuries it more often means a prescribed process for completing a task. It may refer to:
*Scien ...
s,
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 and ...
, 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 depend ...
s, extension methods
:*
Generics
Generic or generics may refer to:
In business
* Generic term, a common name used for a range or class of similar things not protected by trademark
* Generic brand, a brand for a product that does not have an associated brand or trademark, other ...
, 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 tran ...
,
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&mda ...
s,
docstring
In programming, a docstring is a string literal specified in source code that is used, like a comment, to document a specific segment of code. Unlike conventional source code comments, or even specifically formatted comments like docblocks, docst ...
s
:* 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, an ...
:* 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 m ...
;
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 C ...
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 personal ...
and I am age
Age or AGE may refer to:
Time and its effects
* Age, the amount of time someone or something has been alive or has existed
** East Asian age reckoning, an Asian system of marking age starting at 1
* Ageing or aging, the process of becoming older ...
years 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