Forums

Tips for beginners

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Tips for beginners

Postby Charles » Wed Jan 22, 2014 7:52 pm

I was thinking we should compile a list of tips for beginners. They would be on the shorter side since these are not a replacement for reference documentation or tutorials. Also, it would be ideal to emphasize things that may not be obvious. For example, @help isn't commonly found in other languages/compilers and it's not like it's going to jump out at you.

Obviously that would go in the wiki, but we can start the discussion here. Some that come to mind:

-- You don't have to state the type of a local variable twice:
results as List<of String> = List<of String>()

This shorter form is the same:
results = List<of String>()

Cobra infers the type from the right hand side.

-- For IDE support with completion suggestions, parameter tips, breakpoint debugging, etc., use Xamarin Studio aka MonoDevelop.

-- In Cobra code, you can put @help before a type or method call to make the compiler generate an HTML file containing information about that type and/or method.

-- The @number directive can be used to set Cobra's default number type to decimal, float64 or float32. `decimal` is the default.

-- The `extend` feature can be used to add methods to existing types including String, int, etc.

What tips can you guys think of?
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Tips for beginners

Postby hopscc » Sat Jan 25, 2014 2:12 am

- 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....
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron