Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading content…
Loading…
Transcript

Cobra (Programming Language)

Thank You For Listening !

Sss!

History Of Cobra?

Cobra is a object-oriented programming language, which was designed by Charles Esterbrook, and runs on the Microsoft .NET and Mono platforms. It is strongly influenced by Python, C#, Eiffel, Objective-C, 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.

Sample

class Hello

def main

print 'Hello, World'

Why Cobra when Python Already Exists ?

Cobra has many advatages over Python such as:

  • Cobra has more compile-time error checking. e.g Python can throw a NameError at any point during run-time due to mispelling a variable name, but Cobra catches these errors at compile-time. Also, because Python is throwing run-time exceptions for some of these simple errors, they only get reported one at a time and each instance requires a new run of your program. Cobra saves time when it reports multiple errors at once.
  • Accurate Math - Python performs math incorrectly compared to Cobra because Python defaults to a binary floating point type even though most numbers that people input are base 10. To help address this Python offers an additional Decimal type that calculate the correct numbers. As Of Cobra does the inverse, defaulting to an accurate decimal type and offering the floating point type as an option. A simple "f" suffix on a number such as "0.1f" gives the 64-bit floating point value. The types are built in with the names "decimal", "float", "float64" and "float32". The type "float" is an alias for "float64".
  • "float" math operations are faster than "decimal" as both programming languages prefer accuracy over speed
  • Cobra's performance is close or equal to that of C# and Java, and is therefore significantly faster than Python. IronPython claims to be around 1.8 X faster than Python, but this is still far slower than Cobra. Also, some users have found that IronPython can run significantly slower than CPython and Jython.

How Do Does Cobra Work ?

Sample

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'

  • Cobra achieves point 1. like Python and Ruby.
  • It achieves point 2. by favoring static typing ("i = 5" means "i" is an integer and always will be) and leveraging .NET|Mono for machine code generation.
  • It does point 3. by using the .NET typing system at compile-time for static types, and using the .NET run-time for dynamic binding.
  • It takes language features from multiple sources including Eiffel, Python and its own compile-time nil tracking. (With accurate error , arithmatic tracking)

So What is Cobra Made Of ?

Why Cobra ?

Cobra is made up of individual elements such as, contracts, classes, etc. This is not something speacil even python has this, but putting all these elements together to design a program is what makes Cobra different. But has fewer elements compared to Python since it was a experimetal program. Cobra's program always starts with the word called Class.

There are plenty of object-oriented programming languages that exist in the world today like Python and Ruby. So why use Cobra?

The answer is simple Cobra is the combined version of Python, Ruby, C++ and Eiffel put together, with direct support for contracts, unit tests and compile-time nil tracking. It has namespaces, classes, interfaces, generics, methods, properties, indexers, variable number of args, overloading, exception handling and garbage collection. It has a high-level syntax with indented blocks, doc strings, list literals, dictionary literals, set literals, in operator, slicing, for expressions, if expressions, assert, and more.

Cobra has it's own unique characteristics:

  • Quick Expressive Coding
  • Fast Execution
  • Static & Dynamic Binding
  • Language Level Support

Windows:

> cobra -compile hello.cobra

> hello

Hello, world.

Posix:

$ cobra -compile hello.cobra

$ mono hello.exe

Hello, world.

http://cobra-language.com/docs/hello-world/

By Adithya Raj

Learn more about creating dynamic, engaging presentations with Prezi