|
|
|
|
|
by girvo
1446 days ago
|
|
> I'm particularly keen on Nim's UFCS One of my favourite parts about UFCS is how it can turn C libraries that I've had to bind into nice clean looking interfaces! esp_err_t sw_enableRx(SwSerial *self, bool State)
Becomes proc sw_enableRx*(self: ptr SwSerial, State: bool): esp_err_t {.importc: "$1", header: "<SwSerial.h>".}
Which when called is super lovely! var port = sw_open(params, etc)
port.enableRx(true)
|
|
Nim almost feels like I'm writing a dynamic scripting language, except that I've worked with a typed python code base and it sucked because typing always felt taped on. With generics in Nim I feel like I'm duck typing, but my ducks are compile time checked!
I'm keen on experimenting with protocol oriented programming and as far as I understand, UFCS provides this really neatly to the language. I really like the idea of being able to define my own types and have them seamlessly work with functionality of other libs (and vice-versa) without needing to resort to a language feature like traits.