Nim icon indicating copy to clipboard operation
Nim copied to clipboard

proc vs. method for OOP

Open josephernest opened this issue 3 years ago • 1 comments

Congratulations again for Nim!

I am experimenting with OOP in Nim. The article Let's Explore proc and method in Nim shows that using proc instead of method can have the following impact:

In this case, since we were using procs instead of methods, we simply called the incorrect render function in some cases. There would be no error raised, and we might not have even noticed the issue right away.

Would there be a better way to handle such situations in future versions of Nim? (error at compile time, etc.)

For the language to become more widely adopted, there might be a need for protections about such silent programming mistakes, what do you think? Are there already proposed solutions about this?

(For context: I am quite experienced in other languages, but the fact such situations can happen can be an obstacle to adoption)

josephernest avatar Jul 18 '22 10:07 josephernest

Maybe explicit dynamic dispatch with methodCall in the vein of procCall. Could error if only procs found.

metagn avatar Jul 18 '22 11:07 metagn