Best Practice: code modularity

Hello dear community,

I have another general question regarding code modularity:
Q1: how do you organize your “Program” class?

I program C#, the structure give by CG has usualy a program class containing the main method, in which all the valiables are defined. Most of the challenge have some “reduntants” algorythms (I dont know if this is the right word. By this I mean calculations which are the same spread throught the Main() method). My idea would be to pack those in private methods of the Program class.
Q2: Which is the best way to do so? Move my variable declaration to the class level and use “easy-to-use” method without parameters or keep the original access scope and give the parameters in or out of the private method?

Q3: Why do properties and methods have to be defined as static?

Thanks in advance :slight_smile:

Q1: If i use javascript, i code every class / functions in separated files using RequireJS and Grunt to compile the final code for CodinGame. I could also use typescript by using the same method, but standard javascript is fine enougth.

If i use C++ it’s different. I don’t know any RequireJS equivalent for C++ and i’m not good enougth to make a makefile or something like that. I have multiple files in my projects containings basics functions or classes and i just copy/paste them into my code when i need it.

Q2: It all depends of your language and what you are able to code for your code. If you can code in separates files and use a tool to compile the “final code” for codingame, this is the best to do. If you can, you have to do like me in C++. Keep functions/classes in separates files and copy/paste them when you need it.

Q3: In Java and C#, the class containing the main method is never created. You are not in an instance of the class. So if members/methods are not static, you just can’t use them.

1 Like