Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the good programming practices in C# to make code more self-explanatory? [closed]

I think making code self-explanatory, without need for comments all around the place, is a big advantage. But could you suggest methods and techniques how to reduce the amount of code, make it more readable and understandable.

Also what do you think are the good techniques for reducing big if statements and nested for loops and other structures which sometimes are hard to understand at the first glance.

Here are few of the things I thought would my C# application more readable and self-explanatory:

  • Converting foreach loops into LINQ statements.
  • Using anonymous function to reduce amount of event handlers.

Also suggestions about the books which covers these topics would be appreciated.

like image 592
Vitalij Avatar asked Dec 16 '22 20:12

Vitalij


2 Answers

I recommend you take a look at Clean Code by Robert C Martin. It's an entire book dedicated to writing readable code. Highly recommended if you ask me.

Resharper is also very useful as it has numerous suggestions for naming, reducing nesting and the like.

like image 137
Brian Rasmussen Avatar answered Feb 23 '23 00:02

Brian Rasmussen


Aside from syntactical/structural considerations, consistency is extremely important - code styles and formatting preferences vary, which is fine, but within a project you should standardise as much as posibble to avoid having to keep readjusting yourself as you read through the code.

like image 28
Andy Avatar answered Feb 23 '23 01:02

Andy