• 0 Posts
  • 30 Comments
Joined 1 year ago
cake
Cake day: June 12th, 2023

help-circle




  • Writing good comments is an art form, and beginner programmers often struggle with it. They know comments mostly from their text books, where the comments explain what is happening to someone who doesn’t yet know programming, and nobody has told them yet that that is not at all a useful commenting style outside of education. So that’s how they use them. It usually ends up making the code harder to read, not easier.

    Later on, programmers will need to learn a few rules about comments, like:

    • Assume that whoever reads your code knows the programming language, the platform and the problem domain at least in general terms. You are not writing a teaching aid, you are writing presumably useful software.
    • Don’t comment the obvious. (Aside from documentation comments for function/method/class signatures)
    • Don’t comment what a line is doing. Instead, write your code, especially names for variables, constants, classes, functions, methods and so on, so that they produce talking code that needs no comments. Reserve the “what” style comments for where that just isn’t possible.
    • Do comment the why. Tell the reader about your intentions and about big-picture issues. If an if-statement is hard to parse, write a corresponding if clause in plain English on top of it.
    • In some cases, comment the “why not”, to keep maintenance programmers from falling in the same trap you already found.








  • waigl@lemmy.worldtoich_iel@feddit.deich_iel
    link
    fedilink
    Deutsch
    arrow-up
    3
    ·
    edit-2
    4 months ago

    Auch bekannt als die Felgenbrechervariante.

    Auch immer schön, wenn man ein normal langes Schloss hat, und deswegen hier nur das Vorderrad anschließen kann. Dann braucht der geübte Fahrraddieb nur noch einen Schraubenschlüssel, bzw. bei Schnellspannern noch nicht mal den, und 5 Sekunden Zeit, dann ist das Rad in irgend nem Lieferwagen verschwunden. Wenn man’s souverän macht, kann man das auch auf gut besuchten öffentlichen Plätzen abziehen, so schnell reagieren die Umstehenden eh nicht.