Branching and looping are widely used in computer programming and they may be some of the basics of coding. Have you ever reached such a high level of branching and looping that your code just became too hard to read? How about someone else taking a look at the code, how easy would it be for him or her to understand your intent? What about testing the code?
Recently, I’ve been studying some of the best practices in making understandable code and I have reached the conclusion that good code should be written in a “human language” manner.
Example. Given a set of person
- class Adress {
- public string City {
- get;
- set;
- }
- }
- class Person {
- public string Name {
- get;
- set;
- }
- public Adress Adress {
- get;
- set;
- }
- public int Age {
- get;
- set;
- }
- }
- static Adress NY = new Adress {
- City = "New York"
- };
- static Adress Delhi = new Adress {
- City = "Delhi"
- };
- static List < Person > persons = new List < Person > {
- new Person {
- Name = "John", Age = 22, Adress = NY
- },
- new Person {
- Name = "Bob", Age = 88, Adress = Delhi
- },
- new Person {
- Name = "Maria", Age = 21, Adress = null
- },
- };
maha lakshmiPosted Jul 31, 2018, 8:36 PM
Nice article