- tab or 4 space indentation,
block structured by indentation as python
cannot mix Tabs + spcs as indentation on same line
- Strict naming conventions (language enforced)
- Class names ( and Types) must start with capital Letter
- methods and object variables property names should be lowercase ( must start with lowcase letter)
- cobra name formats mapped to and from correct notation for enclosing system ( e.g .Net)
- Regular declaration notation
- Everything is declared using syntax 'keyword' 'name' or 'keyword clause'
namespaces: namespace NamespaceName
classes: class ClassName
(also Interfaces and structs)
class variables: var variableName
properties: pro propName
get propName - readOnly property
set propName - write only property
methods: def methodName
multiple vals comma separated
Type inference (default) - types naturally inferred from first assignment
or type declaration
- as TypeName
- late binding ( declared inferred or defaulted as type 'dynamic' )
accessmodifiers and other: is shared, private
-all method calls contain '.'
either instance.method (or Class.method )
local class method access using this.method (deprecated) or just(shortcut) '.method'
- protected and private class vars and methods (shortcut) may be declared with '_' or '__' names and called directly with same
- local variable - all lowcase, no '.'
e.g.
- Class Oriented - all code and data must be enclosed in a class.
- main method on driving class is program entry point
- no args passed, access cmdline arglist with Library method CobraCore.commandLineArgs (an array)
def main
n = 0
for args in CobraCore.commandLineArgs
print 'arg [n]: [arg]'
n += 1
- superclass and interfaces specified with 'inherits' and 'implements' clauses
class myException
inherits Exception
implements IExceptional
object constructor/initializer method called 'init'.
def init()
#or latterly
cue init
unspecified default is public noarg ctor
Can call another init of its own class or baseclass (must be first statement)
initialiser has no specified return values
not inherited
call upclass/superclass (in ctors at least) using 'base.'
base.init()
- Enums
- builtin Types
- primitives
- 8,16,32,64 bit signed and unsigned ints, 32, 64 bit floats, Decimal
- byte is unsigned 8 bit int ( uint8)
- String
- List, Dict, Set
- Generics - declare and instantiate
- Variables must be declared nilable if can take a nil/null value
- Type Literals
- numeric primitives - default types 'naturally' but can be tagged with explicit type tags
e.g. 32_u8 ( 32 as an unsigned int), 487_i16 (signed 16 bit)
- underscores allowed in numeric literals for readability
- polytype 'Number' - Type set at compile time
- " (double) and ' (single quote) delimited Strings
- Strings support escape sequences for normal control sequences
- 'raw' and 'non substitutable' strings
- characters (Unicode) - c'x' c'\0'
- Lists - values comma separated enclosed in []
- Arrays - values comma separated enclosed in @[]
- Set values comma separetd enclosed in {}
- Dict {:}, Key value pairs ':' separated, pairs comma separated, enclose in {}
Statements and expressions
- usual conditionals and loops
- case (branch) statement
- trinary expression
- nil and non-nil test, cast and coalesce
- slices on collections and multi item types
etc..
I've got a file of these that I thought I'd put on the wiki but cant find it...
I started this when I first ran into cobra and tweaked it over time so its possibly now not as high level/entry as it once was or would need to be for beginner use... Needs culling and reorg anyway....