=== Cobra Differences From C# === See also [http://cobra-language.com/forums/viewtopic.php?f=4&t=15 Cobra Forums Differences with C#] * Dynamic Typing and Type inference (doesnt require Type or keyword to declare locals) * optional type declarations * Block structured by indentation only (like Python) no squiggly braces (brackets) * nil tracking - variables can be declared as nil assignable (or not) * Built in language support for * unit test code * assertions * Design by contract - invariants, preconditions and postconditions * Syntax support for builtin * Lists - [] - List of Dynamic * Dictionaries - {:} Dictionary of * Sets - {} * Line Oriented * # to comment line (instead of //) * No multiline comments * _ to continue line * Tab or Spaces to indent line ( Fixed 4 space indent), Cannot mix Tabs and spaces for an indent level * Methodnames and properties start with lowercase. (i.e lowerCamelCase) * Access to methods/properties in used libraries are also done via (implicitly mapped ) lowerCamelCase methodnames * Class names must be CamelCased * instance variable optionally prefixed with _ (implicitly makes them private). If so prefixed can be accessed directly in methods * methods (and properties) invoked with leading '''this.''' or more usually just '''.'''. * String type accessed as '''string''' rather than '''String''' * ditto int and uint and float and double types ( rather than Int, UInt, Float, Double) * int and uint types all the same naming * int8, int16, int/int32, int64 instead of SByte, Int16, Int32/int, Int64 * uint8, uint16, uint/uint32, uint64 instead of Byte, UInt16,... * Variable specification - typing, access modifiers, argument attributes by keyword 'as' rather than C-like syntax * e.g. x as int32, instVar as string public * typecasting by keyword 'to' as in 'x to Type' rather than (Type)x * 'as shared' to declare a static type * '''<>''' instead of '''!=''' for 'not equals' comparisons * '''nil''' for null value * Supports +=, -=, etc. It does not support ++ or -- unary operators ( use += 1 and -= 1 instead). * boolean conditions can be tested on any type. True is any of * numeric not 0 * not nil * non empty List or Dictionary * Strings delimited by single or double quotes, normal range of \c expansion ( e.g \n, \t) * Substitute expressions (values) directly in strings with []. * such expressions can have optional String.format specification * 'Raw' Strings (r"a raw string") no escape sequence expansion * '!NoSubstitution' strings ( ns" no substitution [done] here") * !DocStrings on classes and methods * Different syntax for characters c'x' * '''ref''' keyword for getting pointer to method ( reference) rather calling it ( for delegates) * '''sig''' keyword or declaring a delegate type * '''def''' keyword to declare a method/function * e.g def doCalc( start as int) as int instead of int doCalc( int start) * '''use''' keyword instead of 'using' to get access to a non default namespace * Slicing syntax for sequences (Lists and Strings) [start:stop:step] as well as normal library subsequence methods (substring, range, ...) * numeric for loop uses slice syntax. e.g. for i in 1:10:1 vs for( int i =1; i<=10; i++) * more to come