About comments…
96% of comments are useless. My guesswork proves this and no one should question it!
Ok, I don’t have any data to back it up, but it feels like that…
Common knowledge says that naming methods is one of the most difficult tasks, we poor developers, have to struggle with. Yet, quite often I see well-named methods with, how to call it… stupid comments.
Why is it a big deal for me? Reading code is what we mostly do, so it should be as effortless and fast as possible. Adding an extra layer of information (which does not bring anything new to the conversation) is just clutter.
Another well-known fact is, that documentation quite often diverges from implementation. Yes, we are lazy, and the documentation we write at the beginning of work gets easily forgotten in the process.
There are cases when extra comments make sense:
- A complicated piece of the algorithm,
- Extra side effects that caller has to be aware of,
- … well… Links to the tickets where we applied hotfixes?
I cannot really think about much more...
Get Łukasz Izmajłowicz’s stories in your inbox
Join Medium for free to get updates from this writer.
Solution.. just burn them all (unless your manager is forcing you to keep them. In this case there are more appropriate steps to take).
Let’s see some random code from the current codebase (There is a lot like that.. about 96% :))
/// <summary>
/// Sign up a new User
/// </summary>
public class UserController : BaseApiController
{
// ...
/// <summary>
/// Gets the Information about the User
/// </summary>
public async Task<UserDto> Get(UserId id)
{
// ...
}Explanation:
What would we expect from Get(..) method in UserController?
I don’t know you, but I expect user information. As developers working with web technologies, we all know it, we live with it daily…
Another point, did you notice the comment on the controller class? “Sing up the User”… wait, I just make a query for the User, not sign-up.. (and trust me, there are a little bit more actions there)
At some point, I will write how I see this improved. Stay tuned!
And now time for the winner (or loser, depending on how you look at it). I think we’ve all seen code like this
/// <summary>
/// Container for the Sign UP API
/// </summary>
public class SignUpData
{
/// <summary>
/// Used for the Serialization
/// </summary>
public SignUpData()
{
}
/// <summary>
/// The Email Address to register
/// </summary>
public string Email { get; set; }
/// <summary>
/// The Password to register
/// </summary>
public string Password { get; set; }
}Do I even... ehh see you next time…





