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