Wiki

Changes between Version 2 and Version 3 of NilableTypes

Show
Ignore:
Timestamp:
05/04/08 07:04:46 (16 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NilableTypes

    v2 v3  
    11= Nilable Types = 
    22 
    3 Cobra forces specification of variables that may be allowed to contain '''nil'''. 
    4 This is done by typing the variable as a nilable Type which is any typeName with a '?' suffix 
     3Cobra does 'nil tracking' which forces specification of variables that may be allowed to contain '''nil'''.[[BR]] 
     4This is done to 
     5 * Help eliminate runtime exceptions about nil reference errors  
     6 * Allow reporting of multiple nil referencing errors at compile time (instead of a single failure point at runtime) 
     7 * Help document which parameters permit nil and which do not 
     8 
     9'''nil tracking''' is done by typing the variable as a nilable Type which is by typing to any typeName with a '''?''' suffix 
    510 
    611e.g. 
     
    1217}}} 
    1318 
    14 nilable Typing can be applied to anything that can be Typed ( variables, Args, parameters, returnTypes) 
     19nilable Typing can be applied to anything that can be Typed ( local variables, class variables Args and returnTypes) 
    1520 
    1621{{{ 
     
    4247== nil and not nil detection == 
    4348 
    44 You can explicitly test for nil or not nil values using normal conditionals ( true is non-nil) 
     49You can explicitly test for nil or not nil values using normal conditionals (true is non-nil) 
    4550{{{ 
    4651    s as String = 'sss' 
     
    5560 
    5661== nil and non-nil coalesce == 
    57 Shortcuts for Nil test and assign (coalesce) or non nil test and process [[BR]] 
     62There are shortcuts for Nil test and assign default (coalesce) or non nil test and process [[BR]] 
    5863 
    5964'''a ? b''' coalesce to b if (a) nil.[[BR]] 
     
    8489        #    i = if(input, .parse(input), input) 
    8590 
    86         # or alternatively 
     91        # an alternative would also be: 
    8792        # input = input ? '0' 
    8893        # i as int = .parse(input)