Programmer245 / IS24-AM32

Software Engineering Project - Bachelor of Computer Engineering (PoliMi)
0 stars 0 forks source link

not a real issue.. coding style #6

Closed ingconti closed 7 months ago

ingconti commented 7 months ago

You write:

public boolean addPlayer(String nickname) { return false; if (players.contains(nickname)) { // Nickname already in use return false; // FIXME What happens if String = null? } else { // Nickname not in use // TODO Need to initialize player return true; } }

in old style origramming you use if else AND you return the result. (structured programming) in modern style (early return.. in swift... or rurst..) so you code would be: if (players.contains(nickname)) return false;

  // NO NEED  else 
  return true;

}

cleaner annd avoiding another lever of {} on "impliciti " else

OR... use ternary: "https://en.wikipedia.org/wiki/Ternary_conditional_operator"

return (a=b) ? x; y

I repeat: only a matte of style, but yours is a mix. ;)

Programmer245 commented 7 months ago

Duly noted. Thanks for the advice, I'll keep it in mind moving forwards from now on.

ingconti commented 7 months ago

of course.