- C# and .NET Core Test Driven Development
- Ayobami Adewole
- 181字
- 2021-06-25 22:00:27
Source code readability
A good code base can be easily distinguished from a bad one by how quickly a new team member or even the programmer can easily understand it after leaving it for a few years. Quite often, because of tight schedules and approaching deadlines, software development teams tend to compromise and sacrifice professionalism to meet deadlines, by not following the recommended best practices and standards. This often leads them to produce code that is not readable.
The following code snippet will perform what it is intended to do, although it contains elements written using terrible naming conventions and this affects the code's readability:
public void updatetableloginentries()
{
com.Connection = conn;
SqlParameter par1 = new SqlParameter();
par1.ParameterName = "@username";
par1.Value = main.username;
com.Parameters.Add(par1);
SqlParameter par2 = new SqlParameter();
par2.ParameterName = "@date";
par2.Value = main.date;
com.Parameters.Add(par2);
SqlParameter par3 = new SqlParameter();
par3.ParameterName = "@logintime";
par3.Value = main.logintime;
com.Parameters.Add(par3);
SqlParameter par4 = new SqlParameter();
par4.ParameterName = "@logouttime";
par4.Value = DateTime.Now.ToShortTimeString(); ;
com.Parameters.Add(par4);
com.CommandType = CommandType.Text;
com.CommandText = "update loginentries set logouttime=@logouttime where username=@username and date=@date and logintime=@logintime";
openconn();
com.ExecuteNonQuery();
closeconn();
}