I know some languages (C comes to mind) its best to declare as few variables as possible. In a language with memory management like C# is it better practice to continue with this philosophy or should I be declaring unnecessary variables if it improvese readability?
Ex: Declaring unnecessary database and server variables
public static DataTable CreateMonthlyPerformanceSummaryTable(int perfSumId, DateTime date, bool startDate) { DataTable monthlyPerformanceTable = new DataTable(); string dataBase = PerformanceDBDataObject.DBName; string server = PerformanceDBDataObject.Server; using (SqlConnection conn = SQL.ConnectToDB(dataBase, server, 30)) { if (startDate == true) { SelectPerformanceSummaryUsingStartDate(date, monthlyPerformanceTable, conn); } else { SelectPerformanceSummaryUsingEndDate(date, monthlyPerformanceTable, conn); } } return monthlyPerformanceTable; }
Or: Simply plugging in Values into ConnectToDB
public static DataTable CreateMonthlyPerformanceSummaryTable(int perfSumId, DateTime date, bool startDate) { DataTable monthlyPerformanceTable = new DataTable(); using (SqlConnection conn = SQL.ConnectToDB(PerformanceDBDataObject.DBName, PerformanceDBDataObject.Server, 30)) { if (startDate == true) { SelectPerformanceSummaryUsingStartDate(date, monthlyPerformanceTable, conn); } else { SelectPerformanceSummaryUsingEndDate(date, monthlyPerformanceTable, conn); } } return monthlyPerformanceTable; }
Personally I think the first option is better because the shorter line length allows for improved readability, but I am wondering if this is bad practice.
The post Declaring Unnecessary Variables for Readability appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.