DEV Community

Discussion on: 5 easy wins to refactor even the ugliest code

Collapse
 
juanjoms profile image
Juan Miramontes

if I were to refactor the getName function, I would simply do:

public getName(): string {
  return this.name ? this.name : this.NAME_DEFAULT;
}
Enter fullscreen mode Exit fullscreen mode

or even:

public getName(): string {
  return this.name || this.NAME_DEFAULT;
}
Enter fullscreen mode Exit fullscreen mode

It includes points 1) and 2), and I think is simpler and more readable.