Is it better to evaluate bool once but have more code like this
if (klient.Podmioty.PodmiotRodzaj == "Osoba") {
textImie.Enabled = true;
textNazwisko.Enabled = true;
textNazwa.Enabled = false;
} else {
textImie.Enabled = false;
textNazwisko.Enabled = false;
textNazwa.Enabled = true;
}
comparing to this
textImie.Enabled = klient.Podmioty.PodmiotRodzaj == "Osoba";
textNazwisko.Enabled = klient.Podmioty.PodmiotRodzaj == "Osoba";
textNazwa.Enabled = klient.Podmioty.PodmiotRodzaj != "Osoba";
It’s a generic question and maybe this little example is micro optimization but I would like to know whether reusing same bool over and over is not considered bad code.
Probably useful note is that klient.Podmioty.PodmiotRodzaj is actually variable from SQL brought by Entity Framework.
Evaluate once and use the results: