I was looking at a question on here about confessing your worst code ever written and I am not quite sure, because of my lack of knowledge on why this is bad code.
public string GetUsername (string userName)
{
User user = DbLookup.GetUser(userName);
return user.Username;
}
Is it because, it assumes username
will exist and doesn't check for null
? Or is there more to it?
https://stackoverflow.com/questions/130965/what-is-the-worst-code-youve-ever-written/191969#191969
because it returns the same thing that the user sends as input to the method... Username
It doesn't return the same string that was provided. It return the username from the database and the user may or may not exist - thus it could return null. The method name is perhaps incorrect given what it does. Someone in the original post mentioned that it should be CheckIfUsernameExistsAndReturn sorta method name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With