684
AL1L
6y

How programmers comment their code

Comments
  • 27
    So good. Great naming renders comments unnecessary in most cases.
  • 6
    this reminds me of comments on geeksforgeeks articles. 😂
  • 17
    Well, to be fair, those are really fucking obvious controls.
  • 11
    In the best case code is self expanatory...
  • 11
    @Root for you, yes. On the other hand I dare you to show it to your grandparents...
  • 4
    @bigus-dickus pool water can get hot, so in context that image makes sense
  • 26
    They don't let me write Javascript anymore 😢
  • 13
    @bittersweet what torture is this...my eyes burn...it is beautiful.
  • 10
    @RememberMe

    Don't worry, I don't subject others to it, but I do love to write Javascript as if it were Haskell using recursion, currying and function composition, just as kata-exercises.
  • 7
    @bittersweet wow your code is self-obfuscating.
  • 13
    @duckWit It depends which corner of the dev world you come from. To me,
    "const f = (x, a = 1) => x ? f(x-1, x*a) : a"
    seems like a very readable factorial function because I usually think in terms of recursion. Most OOP devs would prefer a function with a "while" or "for" loop.

    One is not necessarily better or worse, just different approaches — although it's usually wise to adjust to language and team conventions.
  • 3
    @bittersweet haha great. Thats how HaskelScript was born. 😂
  • 6
    /** Returns the value */
    int getValue() {
  • 7
    @bittersweet although I like haskell, I'd still prefere a loop, just for the simple fact, that a recursive call needs some space on the stack for each itteration, while a loop doesn't
  • 6
    @Wack Yeah Javascript isn't optimal for recursion if the interpreter lacks TCO support.
  • 3
    @bittersweet haha, nah, I love it! The torture bit was from seeing such ideas being sullied by JS's syntax and awkward constructions. ML family syntax ftw.

    Though I really shouldn't complain, I do similar things in C++ and the syntactic torture is even worse there, heh.
  • 6
    @RememberMe I really like doing things you're not supposed to do. I've been working on a pure bash MVC with netcat webserver and awk templating engine, including middleware layers and a half finished database abstraction layer.
  • 4
    @bittersweet oh wow, that's extreme. Seriously though, you learn a lot from doing that kind of stuff.

    I have a home networking setup (i.e. the stuff that connects two laptops and a desktop together at my place) using a self made Arduino based "router", my own protocol, and (a very shitty and slow) userland sockets implementation. It actually works, to my great surprise.
  • 5
    Rule of thumb to have comments in code

    Instead of what you are doing, write why you are doing!

    Anyone can go through code figure out what you are doing, but no one can figure out why you are doing it.
  • 1
    Lol true
  • 1
    @duckWit In cases where it is not it simply means that the names chosen are not good enough. Comments should sometimes be on interfaces and classes which other people might use like libraries. Making a comment on a function should mean that you failed to convey meaning through normal code. :)
  • 1
    @arekxv I agree on all counts.
  • 3
    // Import stuff
    import stuff from 'stuff';
  • 0
    @bittersweet I still can't get full understanding of your code example. 😅
  • 0
    You are not the only programmer who writes weird comments. “40 Ridiculous Comments in Source Code that People Actually Wrote” is published by Brunette girl ...
  • 0
    I believe that with the information you share, it will bring a lot of value to the readers and I hope that they will absorb the good and useful things.
  • 0
Add Comment