Somewhere in the beginning of learning Nim, I noticed I could use semicolons instead of commas to separate parameters while defining procs, macros, etc.
# Semicolons
proc repeat(message: string; times: int): float
# Commas
proc repeat(message: string, times: int): float
I don't know if I read something or made it up myself, but I started writing my parameter lists with semicolons thinking it was "better" somehow. I realize now it is not a matter of "which is correct" and Nim seems to lack a formal style guide, unless the default rules of nimpretty could be defined as the standard.
Does anyone else default to semicolons or was I alone in adopting this style choice?
Is not about style, they do different things https://play.nim-lang.org/#ix=3mwZ
The style guide is at https://nim-lang.github.io/Nim/nep1.html
Commas are there so you could omit repeating types for similarly-typed arguments: proc foo(x, y, z: int)
I suggest using semicolons in all other cases.
why not stick to semicolons
not sure what bugs they can help catch, but semicolons can't be used when calling the function later which is one more detail to remember - we use , throughout for simplicity and I can't think of any bug that has resulted.
I use semicolons to act as boundary where I change types in the proc argument list.
In 99.99% cases, commas would have worked too. But if you are using the `using` keyword to auto-set the types based on proc parameter names, you need the semicolon to break the type propagation happening from right to left.
See static[T] in the Special Types section
https://nim-lang.github.io/Nim/manual.html#special-types-static-t
Nim always has more wonderful surprises
surprises - yes, and overloading works -yes
It's amazing that such a sophisticated inner core is so well presented with a simple and easy to use outer shell
Yes, but you have to reveal it for yourself. E.g. type resolution is pretty much close to a functional PL.
Syntactic sugar causes cancer of the semicolon. Alan Perlis
:-)