Ooc (language)

Ooc is a compiled programming language . It combines object-oriented programming with functional programming with a simple syntax that promotes the readability and conciseness of programs. The main implementation translates the ooc code into C sources and then uses a C compiler to produce an executable.

The ooc language and most of its ecosystem are licensed under the BSD license . It is designed to combine simple syntax with the performance of a compiled language, while remaining flexible. It is developed by individuals in their spare time. Its standard library is multiplatform ( Linux , Mac OS X , and Windows are supported), thanks to the blocks of versions built into the language.

Features

Syntax

Ooc, just like the Python , was designed to be readable, and to be easily written by a human in a simple text editor. The blocks are separated by braces, as in C .

The DRY principle is at the heart of the ooc syntax. For example, the operator : = allows to declare a variable from the expression to the right, inferring its type:

Declaration of variables in ooc Declaration of variables in Java
 Answer : = 42
 dogs : = ArrayList < Dog > new ()
 Int response = 42 ;
 List < Dog > Dogs = new ArrayList < Dog > ();

Types of bases

Ooc has the same base types as the C language, however, all types start with a capital letter, by convention.

The standard library also offers many data structures such as list tables, linked lists, hashing tables, stacks, and so on. Tables are included in the language and, unlike C-pointers, are safe (they can not be accessed outside their boundaries).

You can create types by defining a class, an interface, or by making a cover of a type defined in C.

Programming object

Simple inheritance

Ooc object-oriented model supports simple inheritance .

Animal: class {
 makeDuBruit : abstract func
}
Dog: class extends Animal {
 makeDuBruit : func {
 "Wouf!" Println ()
 }
}
Chat: class extends Animal {
 makeDuBruit : func {
 "Meow!" Println ()
 }
}
Touch: func ( animal : Animal ) {
 animal makeDuBruit ()
}
Touch ( Dog new ())
Touch ( Chat new ())

Interfaces

The interfaces allow a semblance of multiple inheritance, like the Java .

Representable: interface {
 toString : func -> String
}
Printable: interface {
 print : func
}
Document: class implements Representable , Printable {
 data : String
 init : func (= data ) {}
 ToString: func -> String { data }
 print : func { toString () println () }
}

Functional programming

Ooc supports anonymous functions and closures . One can manipulate the functions like any value, thanks to a clear and readable syntax:

Import structs / [ ArrayList , List ]
filter: func ( list : List < Int >, f : Func ( Int ) -> Bool ) -> List < Int > {
 copy : = ArrayList < Int > new ()
 for ( x in list ) if ( f ( x ) ) {
 Copy add ( x )
 }
 copy
}
list : = [ 7 , 1 , - 3 , 2 , - 12 , 3 , 42 ] as ArrayList < Int >
list2 : = filter ( list , | a | a > 0 && a < 20 )
Print ( list ); Print ( list2 )
print: func ( list : List < Int >) {
 for ( x in list ) ( x + "" ) print ()
 System.out.println ()
}

This example also uses generic types , shows a simple way to create ArrayList, browse for iterable objects, implicitly return objects, and short syntax for anonymous functions.

Modularity

Each .ooc file is a module that can be imported from anywhere. The modules can be organized in packages (the folders where they are placed). You can import a module into a namespace given, for example

// import the File module in the IO namespace.
Import io / File into IO
// one can define one's own class without worrying about conflicts
File: class {}
// we use the imported class
IO File new ( "C: \\ windows \\ iexplore.exe" ) remove ()

Unlike C, there are no separate header files from the source files. Import , rather than copying / pasting the contents of the file, defines a dependency between two modules.

The compiler thus has a clear view of the dependencies between modules, it supports the partial recompilation without need of files of projects of the Makefile type .

The .use files also allow you to specify dependencies on external libraries, options to pass to the C compiler, version information, and so on. The use directive allows it to be used in code ooc. So, for example, using SDL , OpenGL is a matter of a line of source code.

Code examples

The classic hello world:

 Println ( "Hello world!" )

View the contents of a file:

 File new ( "/ etc / hosts" ) read () print ()

Show the first 5 powers of 2

 for ( i in 0..5 ) {
 "2 ^% d =% d" size ( i , 2 pow ( i )) System.out.println ()
 }

Implementations

The main implementation of ooc is rock , entirely written in ooc and which compiles itself. It was developed in a few months and made obsolete j / ooc , the initial implementation in Java that allowed the bootstrapper language in

There is also an effort to implement an ooc compiler written in Ruby , named rooc .