Cobra is an object-oriented
programming languageA programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
produced by Cobra Language LLC. Cobra is designed by Chuck Esterbrook, and runs on the Microsoft .NET and
MonoMono, pronounced , is a free and open source project led by Xamarin to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime....
platforms. It is strongly influenced by
PythonPython is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
, C#,
EiffelEiffel is an ISO-standardized, object-oriented programming language designed by Bertrand Meyer and Eiffel Software. The design of the language is closely connected with the Eiffel programming method...
,
Objective-CObjective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
, and other programming languages. It supports both static and dynamic typing. It has first class support for unit tests and contracts. It has lambda expressions, closures, list comprehensions and generators. Cobra provides both rapid development and performance in the same language.
Cobra is an open-source project; it was released under the
MIT LicenseThe MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...
on February 29, 2008.
Updates are posted to the Cobra news forum with progress on features, fixes, documentation and related projects since the last update.
Features
- Object-oriented:
- Namespaces
- Class
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
es, interfaces, structstruct is a computer science term for a record that is used to store more than one value.struct is used in the following programming languages:* struct * struct vs. C++ classes...
s, extensions, enumerations
- Method
In object-oriented programming, a method is a subroutine associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time...
s, propertiesA property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field and a method. Properties are read and written like fields, but property reads and writes are translated to get and set method calls...
, indexers
- Mixins
In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited or just reused by a subclass, while not meant for instantiation , Mixins are synonymous functionally with abstract base classes...
, extension methods
- Generics
In a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...
, attributes
- Quality control:
- Contracts
Design by contract , also known as programming by contract and design-by-contract programming, is an approach to designing computer software...
, assertionIn computer programming, an assertion is a predicate placed in a program to indicate that the developer thinks that the predicate is always true at that place.For example, the following code contains two assertions:...
s
- Unit tests, 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 Javadoc documentation, docstrings are not stripped from the source...
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 deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....
- Lambdas and closures
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
- General productivity:
- Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
- Postmortem exception report
- Garbage collection
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
- Scripting
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...
conveniences:
- Clean syntax
- Dynamic binding
- One-step run
- Shebang
In computing, a shebang is the character sequence consisting of the characters number sign and exclamation point , when it occurs as the first two characters on the first line of a text file...
line (#!)
- Miscellaneous:
- Doc tool (cobra -doc)
- Syntax highlighting tool (cobra -highlight)
Examples
The following examples can be entered into a file and run using
cobra .
Classic Hello world example:
class Hello
def main
print 'Hello, World'
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] and I am [_age] years old'
External links