Standard.Licensing icon indicating copy to clipboard operation
Standard.Licensing copied to clipboard

Improvement

Open ammarheidari opened this issue 1 year ago • 6 comments

Syntax improvement and code cleanup

ammarheidari avatar Nov 10 '24 09:11 ammarheidari

Changing var lines to explicit type declarations in C# can be beneficial for several reasons. Let's explore why:

  1. Readability: Explicit type declarations make it clear what type a variable is, which can make the code easier to read and understand, especially for new developers or those not familiar with the codebase.
  2. Clarity: In complex codebases, knowing the exact type of a variable without having to infer it can reduce confusion and errors.
  3. IntelliSense and IDE Support: Explicit types can improve the accuracy and usefulness of IntelliSense in Visual Studio or other IDEs, making development smoother and more efficient.
  4. Type Safety: Explicitly declaring types helps catch type-related errors at compile-time, which can be crucial for avoiding runtime errors.
  5. Code Maintenance: Explicit type declarations can make the code easier to maintain and refactor, as the types are clearly stated, reducing the likelihood of introducing bugs during changes.
  6. Documentation: Having explicit types can serve as a form of documentation, making it clear to others (and your future self) what kind of data structures and types are being used.

ammarheidari avatar Nov 17 '24 12:11 ammarheidari

To be honest, the var not var argument borders on being a religious argument amongst developers. I personally lean much more towards the use of var everywhere, as the underlying type should be clear from the naming and usage. I also make extensive use of auto in my C++ code for the same reason. At the same time, I can also agree with the Dotnet teams coding guidelines, which say to use var when the type is explicitly named on the right-hand side. To me, that feels like a decent compromise.

My bigger point here is that there is already an established coding style in the project and this PR is mainly about changing that style. There are advantages and disadvantages to both styles, and both sides have their adherents. So the point of my comments was not that "this style is wrong", but rather that the existing code (and the project that it is based upon) follow the style of "use var when possible".

If you would like to raise it as an issue and have the community discuss it, that would be great, and if others in the project feel like the change would be welcome, then the style could be changed, but it is something that the community should decide.

jshergal avatar Nov 17 '24 14:11 jshergal

Thanks for the follow-up and response. This was a suggestion for improvement. And whatever decision the community makes will be the same.

ammarheidari avatar Nov 18 '24 08:11 ammarheidari

@ammarheidari It is great that you want to contribute and help the project. Please file an issue under the issues tab to suggest (along with your arguments as mentioned here) why it might be good to change the coding style of the project. That is the place that discussions will occur and decisions will be made.

jshergal avatar Nov 18 '24 17:11 jshergal

@jshergal Any update on merge ?

ammarheidari avatar Dec 15 '24 05:12 ammarheidari

@ammarheidari - I am not a maintainer of the project and thus have no rights to merge PRs. I was simply providing some feedback.

jshergal avatar Dec 15 '24 06:12 jshergal