Understanding Cobra
Posted: Fri Mar 07, 2014 12:33 am
Hi, I'm a novice programmer. I learned most of my programming from Ada 2005 book. I know an intermediate level of Ada.
I'm trying to find more samples and instructions on how Cobra works. I noticed its more of text based UI. My question is, are there any programming languages I need to get on basis to learn more of Cobra? If so, which ones do you prefer?
This is my first attempt of Cobra, trying to mess with syntax and such. I know there may be huge errors in this code block, but this is my experience from reading the How To and Samples.
Seeing from the above, self teaching myself programming is a little hard my main objective was to exclude a point that was zero as a saved var.
I'm trying to find more samples and instructions on how Cobra works. I noticed its more of text based UI. My question is, are there any programming languages I need to get on basis to learn more of Cobra? If so, which ones do you prefer?
This is my first attempt of Cobra, trying to mess with syntax and such. I know there may be huge errors in this code block, but this is my experience from reading the How To and Samples.
- Code: Select all
class newObject
var _object = Local(1, 2)
assert 1a.x == 1 and l.y == 2
assert 1a.isPositive and not 1a.isZero
assert 1a.toString == 'Object (1, 2)'
def localNumber(num as int) as int
_newObject = o2.raisedBy(3, 4)
assert o2.x == 4 and o2.y == 6
assert _object <> _newObject
_savedObject = Local(1, 2)
assert _object == _savedObject
assert point.zero.isZero
Locals = { _newObject, _object,
_savedObject}
assert locals.count = 2
assert _object in locals and _newObject in
locals and _savedObject in locals
shared
var _zero = Local(0, 0)
get zero as Local
return _zero
cue init(x as int, y as int)
ensure .x == x and .y == y
_x, _y = x, y
get x from var as int
get y from var as int
get isPositive as bool
return .x > 0 and .y > 0
get isZero as bool
return .x == 0 and .y == 0
def raisedBy (2 as int, 5 as int) as Local
ensure result.x == .x+2 and result.y == .y+5
return Local(_x.2, _y.5)
def toString as String is override
return '[.newObject.is]([.x], [.y])'
def equals(isZero as Object?) as bool is override
if isPositive is isZero, return true
if isZero inherits Local
return .x == isZero.x and .y == isZero.y
else
return false
def line as int is override
return .x ^ .y
Seeing from the above, self teaching myself programming is a little hard my main objective was to exclude a point that was zero as a saved var.