Hi all, new to Nim but I have really enjoyed using it thus far! I had a
question about the benefits of using procs vs methods when defining methods (in
the general sense) for various objects where there is inheritance. See below:
type
BusinessCalendar* = ref object of RootObj
TargetCalendar* = ref object of BusinessCalendar
NullCalendar* = ref object of BusinessCalendar
proc isBusinessDay*(this: BusinessCalendar, dt: Time): bool =
not(getLocalTime(dt).weekday in [dSat, dSun])
proc isBusinessDay*(this: NullCalendar, dt: Time): bool = false
proc advance*(this: BusinessCalendar, interval: TimeInterval, dt: Time):
Time =
var
n = interval.days
newdt = dt
if n > 0:
newdt += n.days
while this.isBusinessDay(newdt) == false:
newdt += 1.days
n -= 1
else:
while n < 0:
newdt -= 1.days
while this.isBusinessDay(newdt) == false:
newdt -= 1.days
n += 1
return newdt
proc adjust*(this: BusinessCalendar, dt: Time): Time =
var newdt = dt
while this.isBusinessDay(newdt) == false:
newdt += 1.days
return newdt
Is there a benefit to defining these as methods, or is using the static
dispatch with the proc fine? Thanks in advance!