Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have a simple rule about adding "magic" like that- if you can't make it immediately obvious to the readers of the code just what it is the magic is going to do, don't do it. AOP Java lead me to that rule because of too many obscure annotations that did insane things to help one developer avoid some minor nuisance.


I disagree that you shouldn't do it. The way you do it is to add a comment

// This %thing% was generated from %template% using data from %data%.

If your language is too restrictive to add sensible tools, you should write the tools yourself. As with any code, write it in a way such that other people will be able to understand it.

There is no magic, it's just code. I wish people would stop using that word.


The original comment says "they just weren't anywhere in the code that humans could see."

Where would you and the comment in a situation like that one?

I don't have anything against generated code but it should be visible and, as you said, it should be crystal clear where it come from


I think in this instance it's also a matter of tools. Visual Studio/Visual Assist would have been able to find the class definition, and that's where the comment would go. For cscope it's a matter of configuration, which should be auto-generated by the build tool.

If the class is being used, then the definition has got to be somewhere, hopefully in a header. It's simply a file that is included somewhere. And it will be human readable. There is no magic.


The class definitions were not in any file. That was the entire point. They didn't exist at all except as transient build artifacts.


I agree with that rule.

Sometimes you have to get the job done in a "less than ideal" way. But a lot of documentation/comments should be left to justify and more importantly explain how it works.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: