Search This Blog

Wednesday, June 3, 2020

Comment code

Answer to Do software engineers comment code after they finish coding or whilst they are coding? by Garry Taylor https://www.quora.com/Do-software-engineers-comment-code-after-they-finish-coding-or-whilst-they-are-coding/answer/Garry-Taylor-5?ch=8&share=c9b5940f&srid=zx8E 

We comment whilst programming, but these days it's actually becoming more common to have fewer and fewer comments. I remember when I was first learning, the standard was to have *lots* of comments, but these days the emphasis tends to be more on "self documenting" code, i.e. it should be clear enough to understand without comments.

That is you don't write something in a convoluted way to make it run 0.001% faster, you write it in a clear way which any programmer can understand without comments.

You still have comments to explain non-obvious stuff, and perhaps to explain *why* you are doing something, not *what* you are doing. *what* you are doing should be clear from the code.

Certainly don't feel you need stuff like this:

    • //Get database connection
    • var db = getDatabaseConnection();
    • //Get users.
    • var allUsers = db.getUsers();
    • //Iterate over users.
    • for (var user in allUsers) {
    • //blah
    • }

Really none of those comments should be there, because it's plainly obvious what is happening

No comments:

Post a Comment

Phật giáo vs cúng sao

Nhiều người nói Phật giáo bây giờ biến tướng, cúng sao giải hạng mê tín dị đoan... Nhưng mất đi cái đó rồi, nhóm những con người có ít họ...