Cobra (programming language)

From Infogalactic: the planetary knowledge core
Jump to: navigation, search
Cobra
Paradigm Multi-paradigm: object-oriented
Designed by Charles Esterbrook
Developer Cobra Language LLC
First appeared 2006; 18 years ago (2006)
Stable release 0.9.6 / December 23, 2013; 10 years ago (2013-12-23)
Typing discipline strong, static, dynamic, inferred
OS Microsoft .NET, Mono
License MIT
Filename extensions .cobra
Website cobra-language.com
Influenced by
Python, Eiffel, C#, Objective-C

Cobra is a general-purpose, object-oriented programming language.[1] Cobra is designed by Charles Esterbrook, and runs on the Microsoft .NET and Mono platforms.[2] It is strongly influenced by Python, C#, Eiffel, Objective-C, and other programming languages.[3] It supports both static and dynamic typing.[4][5] It has support for unit tests and contracts.[4] It has lambda expressions, closures, list comprehensions, and generators.[6]

Cobra is an open-source project; it was released under the MIT License on February 29, 2008.[7][8]

Updates are posted to the Cobra news forum with progress on features, fixes, documentation and related projects since the last update.[9]

Features

Object-oriented
Quality control
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
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'

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] and I am [_age] years old'

References

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found.
  4. 4.0 4.1 Lua error in package.lua at line 80: module 'strict' not found.
  5. Lua error in package.lua at line 80: module 'strict' not found.
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Cobra News Forum

External links