Hacker News new | past | comments | ask | show | jobs | submit login

When you are using a particular method that is required by the context of your work rather than code you have control over. Perhaps the method name in the framework you are using is non obvious, or there is a bug in the way it works.

Sometimes comments are just to save future you some time or help other developers find context.

Suffice to say any project of significant complexity will probably require comments at some point. That complexity can come from the code, the task, the stakeholders or the dependencies.

Unless you are happy with a method name like getSimpleProductInstanceThroughCoreFactoryBecause ModuleRewriteWillBreakCompatibilityWithSecurity PatchSUPEE5523 ()

In that case I guess you're right.

Edited to stop the method name stretching HN layout.




Break the long method up into multiple methods, each implementing a different fix. Bundle these methods up into a gateway class.


That introduces unnecessary complexity in the code for something that could just be explained in a comment.

There were no fixes performed in the method, the method just gets a product instance from a factory. The comment gives reasons for why it was using a core factory directly instead of using the automatic object resolution mechamisms.

The real method name was getProductInstanceFromCoreFactory. Still long, still clear as to what it is doing. But making the context clear would be more code than it is worth.

Avoiding comments by writing clearer code isn't a bad habit, but my point is that they are very useful to provide context for something that getting context for would otherwise be erroneous or cumbersome to implement.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: