Preventing and detecting code smell

Programming styles and coding formats that result in code smell should be avoided. By adequately paying attention to the details, bad code pointers discussed in the Code smell section should be avoided. The replicated lines of code in the two methods of the source code mentioned in the Code smell section can be refactored to a third method. This avoids replication of code and allows for easy modifications:

[HttpGet]public ActionResult GetAllTransactions(){    var yearsAndMonths=GetYearsAndMonths();    ViewBag.Transactions= GetTransactions(yearsAndMonths.Item1,yearsAndMonths.Item2);    return View();}[HttpGet]public ActionResult SearchTransactions(){    var yearsAndMonths=GetYearsAndMonths(); ViewBag.Years = yearsAndMonths.Item1; ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.