a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by akkartik
akkartik  ·  4279 days ago  ·  link  ·    ·  parent  ·  post: Yes, your code does need comments.

I'm curious what people think of my commenting style: http://github.com/akkartik/wart





forwardslash  ·  4279 days ago  ·  link  ·  

You wrote a lisp? A unit tested lisp? Damn.

Your commenting style seems good, it makes the code pretty readable. At least to me.

akkartik  ·  4279 days ago  ·  link  ·  

Aw shucks :) Given my history with arc, writing lisps is kind of an occupational hazard.

briandmyers  ·  4279 days ago  ·  link  ·  

I opened 7 or 8 files at random, and saw a few (very few) one-liner comments, which meant very little to me. Then I opened main and saw you'd put an essay on Lisp at the top. So overall, and only because you asked - I'd call your commenting style "non-utilitarian" - no offense intended :-)

akkartik  ·  4279 days ago  ·  link  ·  

:) Aww, my goal is extremely utilitarian: to explain lisp to non-lispers. Many of the early files have long comments because readers need the most support early on when they're orienting themselves around a new codebase. By the end, you get a feel for how things work and the code gets more self-documenting. If the goal is to convey intent, surely intent can't be uniformly distributed throughout a codebase. It takes a lot more intent to start; once the fundamentals are in place the rest might even get built on autopilot.

Beyond comments I've also been exploring other mechanisms for keeping code readable. I thought hard about file system organization: making it apparent where newcomers should start, and keeping files easy to move around and rename. I spend a lot of time coming up with names, and minimizing the number of names I use, because the vocabulary of a codebase needs to fit in a person's head far more than lines of code. And I write tests.

Having lots of unit tests has an unexpected benefit for readability in the small. Don't understand why this line needs to be so? Try changing it or deleting it, run all tests. Something failed? Ah, it explains a design subtlety I'd forgotten about. Nothing failed? Sweet, dead code. Good names for tests are way more valuable than for functions because of this trick, but sadly most codebases don't have nearly the coverage necessary to make it tick.

In general I'm far more cavalier towards my code than towards my tests. Take away my code if you want, but leave me my tests. That's where all the reproducible value is.

A lot of my goal is to convey global intent. Often, discussion of one part includes interactions with other parts.

What else? Oh yes, I'm not just writing comments in code files, I also have random files with just prose. And I love this quote for conveying the goal of design:

    If I look at any small part of it, I can see what is going on -- I don't need to refer to other parts to understand what something is doing.

    If I look at any large part in overview, I can see what is going on -- I don't need to know all the details to get it.

    Every level of detail is as locally coherent and as well thought-out as any other level.

    -- Richard Gabriel, The Quality Without A Name (http://dreamsongs.com/Files/PatternsOfSoftware.pdf, page 42)

I actually tend to be extremely anti-comments, so it was a little eye-opening to go back and notice how much prose I've written on this project. In the end, the goal is a good design, and there are no hard and fast rules. Just do what it takes.

briandmyers  ·  4279 days ago  ·  link  ·  

Well, turnabout is fair play, so if you'd like to critique my commenting style, there's some here : http://hubski.com/pub?id=67105 (If you don't want to, I won't mind).

Although I adapted that code from a library I found online, most of the commenting in there is mine.

akkartik  ·  4279 days ago  ·  link  ·  

Ah, I saw and liked that! I'd meant to go back to it in more detail. Ok, it might be a few days, but I'll get back to you.

akkartik  ·  4277 days ago  ·  link  ·  

I'm curious: Why did you not bother with negative numbers? Were they just not relevant to the application you had in mind?

briandmyers  ·  4277 days ago  ·  link  ·  

Yes, exactly so.