=== 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 //) * '''/# ... #/''' for multiline comments * Line continuation is implied in method argument lists: foo.bar(arg1,[NEWLINE]arg2) * Use a trailing '''_''' for explicit line continuation * Tab or 4 Spaces to indent line (Fixed 4 space indent), Cannot mix Tabs and spaces for an indent level * No statement terminator (goodbye to ';') * Fractional numbers default to decimal type (rather than int)- can be overridden (to float/double) with a compiler commandline option * Method names and properties start with lowercase. (i.e lowerCamelCase) * Access to methods/properties in used libraries are also done via (implicitly mapped) lowerCamelCase methodnames * In resulting binaries such as .exe and .dll, the .NET standard CamelCase is used so that Cobra libraries vend out naturally to C# and VB.NET * Class names must be (upper) [http://en.wikipedia.org/wiki/CamelCase CamelCased] or at least start with an upper case letter) * instance variable optionally prefixed with _ (implicitly makes them private). If so prefixed can be accessed directly in methods * methods (and properties) on current object invoked with leading '''this.''' or more usually (shortcut) just '''.'''. * constructor/initializer method is called init, has no return value * String type accessed as '''String''' * Numeric types specified as int, uint, float and double types ( rather than Int, UInt, Float, Double) * Sized int and uint types all have the same naming form * int8, int16, int/int32, int64 instead of SByte, Int16, Int32/int, Int64 * uint8, uint16, uint/uint32, uint64 instead of Byte, UInt16,... * Type of numeric literals can be dictated using suffixes * Variable specification - typing, access modifiers, argument attributes specified by keyword '''as''' rather than C-like/Java-like syntax * e.g. x as int32, instVar as string public (vs int32 x; public String instVar; ) * typecasting by keyword '''to''' as in 'x to Type' rather than '(Type)x' * cast to and away from nilable Type. * '''is shared''' to declare a static type * '''<>''' instead of '''!=''' for 'not equals' comparisons * Condition negation uses keyword '''not''' ( as in {{{ not a >10}}} ) * boolean conditions use keywords '''and''' and '''or''' ( as in {{{ if a>3 and b<10 or b>55 }}}) * '''nil''' for no object (null) value * Supports +=, -=, etc. Does not support ++ or -- unary operators ( use += 1 and -= 1 instead). * boolean conditions can be tested on any type. True is any of * non false (bool Type) * numeric not 0 * non zero char * not nil * blank strings and empty collections are true (non nil) - must check .length for strings and .count for collections * Strings delimited by single or double quotes, normal range of \c expansion ( e.g \n, \t) * Substitute expressions (values) directly in strings by enclosing with []. * such expressions can have optional String.format specification * 'Raw' Strings (r"a raw string") no escape sequence expansion ( vs c# @"a raw string") * '!NoSubstitution' strings ( ns" no substitution [done] here") * !DocStrings on Programs, classes, Instance variables, methods and properties * Different syntax for characters c'x' $ since '[] used for Lists array literals are specified using ''' @[]''' - comma separated values * '''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 * ''' branch... on, on, [else]''' statement rather than c# '''case''' statement * 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 as they surface See also: * http://cobra-language.com/how-to/