Changes between Version 2 and Version 3 of NilableTypes
- Timestamp:
- 05/04/08 07:04:46 (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NilableTypes
v2 v3 1 1 = Nilable Types = 2 2 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 3 Cobra does 'nil tracking' which forces specification of variables that may be allowed to contain '''nil'''.[[BR]] 4 This 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 5 10 6 11 e.g. … … 12 17 }}} 13 18 14 nilable Typing can be applied to anything that can be Typed ( variables, Args, parameters,returnTypes)19 nilable Typing can be applied to anything that can be Typed ( local variables, class variables Args and returnTypes) 15 20 16 21 {{{ … … 42 47 == nil and not nil detection == 43 48 44 You can explicitly test for nil or not nil values using normal conditionals ( 49 You can explicitly test for nil or not nil values using normal conditionals (true is non-nil) 45 50 {{{ 46 51 s as String = 'sss' … … 55 60 56 61 == nil and non-nil coalesce == 57 Shortcuts for Nil test and assign(coalesce) or non nil test and process [[BR]]62 There are shortcuts for Nil test and assign default (coalesce) or non nil test and process [[BR]] 58 63 59 64 '''a ? b''' coalesce to b if (a) nil.[[BR]] … … 84 89 # i = if(input, .parse(input), input) 85 90 86 # or alternatively91 # an alternative would also be: 87 92 # input = input ? '0' 88 93 # i as int = .parse(input)