I think the very general approach Nim takes on OOP-style of procedure calling is pretty amazing. To make clear what I'm taking about: When i use the standard function substr I can either write
substr("hallo",1,1)
or
"hallo".substr(1,1)
The latter I call "OOP-style of procedure calling". I know that it is not really object oriented, but that's exactly the cool thing about it! (I can for example "add" a method to a type without touching the type or the need to create a new child type.)
Anyway, my big question as a Nim starter is: When is it best to use which way of procedure calling? With substr it feels natural to use the OOP style, but should I use this style on all procedures with at least one argument?
Well, I'm totally with you. - I have a vague image what it means to use C-style "where they make the most sense" and respectively for OOP-style calls.
But is there any more specific way to say when which makes more sense?...
init("myOrg", "Linerino")
createWindow("Linerino", 128, 128, 4, false)
run(gameInit, gameUpdate, gameDraw)
These functions from the Nico framework dont make much sense to call with member functions, since the function name does not sound like it'd be a member function. My view is if the proc sounds like it's attached to an object use the OOP style, else use the C style.OOP style also looks nicer when you have a set of functions for manipulating a specific type/object
player.move(Left)
player.accelerate(North)
player.isHit(bullet)
Same can be true for the whole strutils module https://nim-lang.org/docs/strutils.html:
s.add "a"
s.replace("a", "b")
s.splitLines
It looks even cooler with with:
with s:
add "a"
replace("a", "b")
splitLines
moigagoo didn't mention that but you need to import std/with to use it. https://nim-lang.org/docs/with.html
Currently it's a bit underdeveloped though, with some simple examples not being parsed correctly (eg. you can't do [1] = "a" to use x[1] = "a" syntax), but it's certainly nice to have.