DEV Community

Discussion on: Daily Coding Puzzles - Nov 11th - Nov 16th

Collapse
 
jay profile image
Jay

I try to use the func keyword when defining methods, that way the compiler can guarantee that I have pure function with no side effects.
func is just sugar for proc {.noSideEffect.}.

func rental_car_cost(days: int): int =
  result = days * 40
  if days > 7:
    result -= 50
  elif days >= 3:
    result -= 20
Thread Thread
 
kungtotte profile image
Thomas Landin

I haven't gotten into the habit of doing that yet. I know I should and I think it's a great idea in general, but years of habits are hard to break and the func keyword is still a fairly recent addition to the language :)