Well it was harder then I thought but I figured out how to encapsulate my code using a namespace
I already know how to do it with a class
(I’m coming from C# world)
And for the question, I had a small class
that just needed an initiation and then it start working (without exporting any function or property) to do its infinite internal job.
I was told that in my case it’s not a good practice to use a class
, because I’ll always have only one instance that not exporting anything so I need to use internal module
instead...
Now all my code is working great inside of a namespace
, is it a good practice to encapsulate it in a class
too?
namespace X { class Y { } }
Or should I leave it without a class?
My module code is bunch of functions that works together using a shared internal state.
A great answer will explain with details the reasons when to use a namespace
, when to use a class
, when to use both, and when to use nothing.
Until now I didn’t find a page that explain the best practice for each, and I believe that a great answer to my question will receive a lot of great feedback (or upvotes ;) ) from confused new comers like me.