Slashdot Mirror


Ask Slashdot: How Do You Read Code?

New submitter Gornkleschnitzer writes: The majority of humans read silently by rendering a simulation of the printed words as if they were being spoken. By reading that sentence, chances are you're now stuck being conscious of this, too. You're welcome.

As a programmer (and a reader of fanfiction), plenty of things I read are not valid English syntax. When I find myself reviewing class definitions, for loops, and #define macros, I rely on some interesting if inconsistent mental pronunciation rules. For instance, int i = 0; comes out as "int i equals zero," but if(i == 0) sometimes comes out as either "if i is zero" or "if i equals equals zero." The loop for(size_t i = 0; i < itemList.size(); ++i) generally translates to "for size T i equals zero, i less than item list dot size, plus-plus i." I seem to drop C++ insertion/extraction operators entirely in favor of a brief comma-like pause, with cout << str << endl; sounding like "kowt, stur, endel."

What are your code-reading quirks?

9 of 337 comments (clear)

  1. FFS by nuckfuts · · Score: 5, Insightful

    Could you be any more self-absorbed?

  2. WTF Are you Serious? by CrashNBrn · · Score: 5, Insightful

    What competent programmer converts the abstraction of code to ENGLISH to grok it?

    generally translates to "for size T i equals zero, i less than item list dot size, plus-plus i.

    No it doesn't. It translates to, "Iterate 'itemlist'" , You're Welcome.

  3. I don't. by Anonymous Coward · · Score: 0, Insightful

    I got the fuck out of coding and IT, like any bright person would do.

    The handwriting is on the wall. Silicon Valley is overrated and overcompensated and it's only a matter of time...

  4. One line st a time... by __aaclcg7560 · · Score: 5, Insightful

    My initial response is, "who wrote this shit?!" And then I recognize it as my own code.

    1. Re:One line st a time... by swillden · · Score: 3, Insightful

      BTDT, more times than I could possibly remember.

      OTOH, I'm proud to say that there have been a number of times in the last few years (of a 30 year career) that I've looked at something and thought "Damn, this is really clean and elegant, and that bit is incredibly clever in its simplicity"... and then realized that was my code. And I've had co-workers compliment me on the simplicity and clarity of my code. That is an awesome feeling.

      On the gripping hand, I would *not* say that of the project I've been working on for the last three years. It started out fairly decent (not great, but good, IMO), but has gotten very crufty and at this point is pretty hard to follow. It really needs a major refactor. If I only had a quarter to spend on cleanup... but new requirements come in too fast.

      Writing working code is easy. Writing readable code is much, much harder. Worth the effort, though.

      Here's a tip: Once you have developed enough as a programmer to have a good sense of what's clear enough to be readable to another programmer (i.e. yourself in three months) and what isn't, enough that you know when you need to add explanatory comments to clarify how bits of the code do their job, then you should start treating inline comments as a code smell. If the code can't stand on its own, refactor until it can. Often this is as simple as picking some better variable or function names, or pulling apart a calculation so you can assign parts of it to well-named variables, or factoring a block of code out into a separate method so you can give it a descriptive name. Other times, after doing all of that it's still not good and you need to do a deeper refactor. But don't be satisfied until the code can stand alone, comment-free, and still be clear, concise and straightforward. There are some cases in which this is impossible, but I think they are rare.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  5. don't we have editors to block this garbage? by Anonymous Coward · · Score: 2, Insightful

    Anyone that needs such literal English translations for simply programming structures is either a beginner programmer or really struggles as a programmer. secondly what the hell is this garbage doing being posted here?

  6. I don't read text like that, and code neither by Anonymous Coward · · Score: 3, Insightful

    When I read, I perceive concepts. Only when I can't grasp something right away do I go back and read words "aloud in my mind". That's part of why I hate videos that don't make use of the advantages of the medium. If you just want to explain and not show, let me read it. It's faster.

  7. Wrong! by Chris+Mattern · · Score: 5, Insightful

    "The majority of humans read silently by rendering a simulation of the printed words as if they were being spoken".

    Actually, only people who read poorly do that. People who read well decode printed words directly into mental concepts, rather than sounding them all out, only sounding out a word when it is unfamiliar in print. (see jokes about people whose lips move when they read)

  8. Re:I do not read by Anonymous Coward · · Score: 2, Insightful

    This is why I have difficulty reading oddly formatted code. The shapes don't match up. All the correct characters are still there, but they're damn near illegible until I really slow down and read like a kindergartner.

    I've been programming long enough that I can recognize most of the usual formatting styles without too much trouble. But when people use something really off the wall, or when (I hate these people!) different developers insist on each using their own style back-to-back in the same chunk of code, I have to switch gears into an entirely different (and much slower) mental model.