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?
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?
Could you be any more self-absorbed?
I just program in write only languages like Perl so I never have to worry about this problem.
Does the submitter also move his or her mouth while mentally sounding out code?
Does it help to really nail phonemes before moving from reading Python to Perl?
Does familiarity with Latin help appreciate the true meaning of "=="?
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.
My initial response is, "who wrote this shit?!" And then I recognize it as my own code.
holy fuck what is this article and how the fuck did it make it to the front page.
Even when the identifiers were in a foreign language... I worked for Siemens US research lab back in the '80s, and saw a fair amount of code that looked like
for Untzelgerflekenzet in 1 .. Ausplotzenfargang loop
Geinengemacht (Zealer => Untzelgerflekenzet, Zugemacht => Sptizelgang);
end loop;
(mostly made up German-sounding words there... I knew a bit of German, but the words you learn in high school German rarely made it into computer code.)
It's sometimes odd to hear others pronounce code, because it may not align with your own mental map of how things should be pronounced. I remember getting mildly distracted when watching one of Stephen Lavavej's videos because he would call shared_ptr "shared putter" (with the u pronounced similar to 'put'). Why would you abbreviate the sound when it's not any shorter than "pointer"?
When reading code by myself, though, I think the translation to a phonetic translation happens quite subconsciously, because I'm typically not aware of it at all. It obviously happens to some extent, or I wouldn't have been bothered by STL's reading. So, trying to think it through (which I haven't done before, really), I can assure you that == would never be "equal equal". It would be "is equal to". "cout" is not "kowt", but "see-out". And I use > so infrequently, I think I don't even bother with a mental pronunciation.
Irony: Agile development has too much intertia to be abandoned now.
I execute it in a mental virtual machine.
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?
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.
"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)
I teach introductory C++ programming courses at a large, urban community college. Getting students to be able to read and write the syntax reliably is itself a major challenge (e.g., poor initial reading/writing skills, never encountered programming before, about half not native English readers, etc.). So at numerous points during the course I ask for the class as a whole to direct my coding at the lectern for some simple problem. "What should I type here?" And of course, we need some recognized way to verbalize that.
The OP touches on the toughest nut I've found in that regard -- that there's no agreed-upon way to pronounce the symbols for C++ stream insertion/extraction operators (e.g., the OP mentions that he just leaves those uniquely silent). Notice that I'm talking about the typographical symbols here, not the name of the C++ operator. E.g.: For the C++ "and" operator, you type the symbol "double-ampersand". But if a student were to say, "insertion operator", and I said, "and how do we type that on the keyboard?", there is surprisingly no agreement in what that symbol is.
Asked this on Stack Overflow a few months ago, to no good resolution: How do you read the... and... symbols out loud?
We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
WHEN YOU READ THIS THE LITTLE VOICE IN YOUR HEAD SCREAMS
however, the lameness filter complains, so this useless text has been added
*/
Life isn't like a box of chocolates. It's more like a jar of jalapenos. What you do today, might burn your ass tomorrow.
Sorry, I can't. My code is in Perl.
Slashdot, fix the reply notifications... You won't get away with it...
when I am reading javascript in code review I always say "Threequals" for the === operator. It hasn't caught on... People in code review still groan when I do it.
That said code should be written in small snippets and as much as possible idiomatically. One recent troubling innovation I have seen are developers trying to do several things in one line of code, like they are trying to win the c obfuscation contest. It makes little sense as we are not using teletypes, and the compiler will optimize code as needed. What we know is that gates and memory is much cheaper than people, and we only need to optimize the code that is run often and is in fact slow.
So, to answer the question, how we read code depends on how code it written, just like we read anything. For the most part code should be written as easily accessible poetry, not literature, not a physics textbook. The skill in reading code, again just like any reading, is not the decoding or sounding out of the text, but the comprehension of the meaning.
"She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
Maybe this is why the majority of people who can read cannot code. Programmers think analytically, not linguistically.
And it's c (see)-out, because the c is for console, out for output.
So you're a drug dealer.
You say "The majority of humans read silently by rendering a simulation of the printed words as if they were being spoken".
That may be how you read, but it's far from being a true statement about the "majority of humans". With a little training, it's possible to read at speeds far higher than a human could speak.
If I recall correctly, "speaking the words" internally was recommended as a technique to [b]slow down[/b] your reading. Maybe you need some speed-reading classes?
I only write it. Reading code is for the little people.
I don't care if it's 90,000 hectares. That lake was not my doing.
OK, I tried
(first '(A B C))
and it came out:
"Car Quote A B C Damn kids get off of my lawn."
I hate getting old.
Your post made me realize I do not read the source, I look at them it like I would do with a map or a geometric shape. And when someone reads me code, I have to do the mental work of representing it differently as when spoken.
I got the fuck out of coding ... Silicon Valley is ... overcompensated
Wait, what? I should get out of a field where I am overcompensated???
it's only a matter of time...
I'll wait.
I typically only read code aloud in two cases. The first is is there's a really stubborn logical bug and it's just not popping out at me. The translation into english often helps point out where I've gone wrong. The second is when coding with someone, it's nice to say code aloud just for communication.
I tend to read code in a way that sticks to the ordering of the code, but makes its meaning more clear with the insertion and substitution of words.
"char* example;" becomes "define a character array called example"
"for (size_t i = 0; i itemList.size(); ++i)" becomes: for i equals zero, while i is less than the size of item list, pre-increment i.
&& is just 'and', || is just 'or'. & and | are "bitwise ___".
"cout str endl" becomes "send to see out, 'str', followed by an endline.
I try to keep the order of the code mostly in tact, and keep the keywords without changing them, but I like to make sure everything turns into an english sentence that kinda makes sense even if you're not super familiar with the language. Obviously, if I have to get into gritty syntax, I'll character by character recite, using words when possible, but that's rarely necessary.
Saying stuff like "char star example semicolon" is just kinda incompatible with the way my brain works. It would like if you had spoken to me by spelling out each word in the sentence you wanted to say. I'll get it but it'll take me a second.
Cwm, fjord-bank glyphs vext quiz
I don't make any mental "sounds" when I read code because I parse through it way too fast but when I'm writing it I do, translating it into something for my brain to type out. I make a lot of beeps and grunts in my head because of that. Parens are a "hernk" noise which get louder the deeper they're nested and semi-colons and periods generally become a 'boop' or "donk." Curly braces are we weird "hurrah"-ish sound on opening and on closing a sad-ish "hurrah."
Despite doing this stuff for the last 25 years I'd never thought about it until today.
My brain natively handles code as programming constructs, more akin to how one understands the whole of the moving parts of a mechanical machine or the schematic of an electrical machine than to how one understands words and sentences of sequential words. It's an alternative mental dimension of sorts.
It takes me some time to descend into "the zone", but once I'm there, magical things happen.
If I'm interrupted by somebody when I'm in this state, I have difficulty parsing their speech and forming my own; it takes me significant time to swap between these mental modes, and my mental buffers are discarded during the switch.
FWIW, I spent lots of time playing with Legos as a kid and started programming around age 13.
I always thought -- since Fortran -- that using "=" as attribution is braindamaged. I loved when ":=" came with Algol.
C only added to the problem by using idiocies like "==" and "!=". These things look like a redundant use of superfluous chars (just to illustrate how redundancy is annoying).
Maybe someone (or I) one day make an IDE where symbols like those can be redefined -- for a saner experience.
Or just self righteous and pretentious snobs who think they are superior because how dare you think they read like the masses.
I'm not sure how it happened, but I found that during the course of my career as a coder, I also became a speed reader. Like, I'm an absurdly fast speed reader now, and it's fucking odd. I don't really have a voice in my head when I read anymore, unless I'm doing it intentionally. Slows things down, and it's unnecessary. Pretty sure the two are related, but I couldn't tell you when it happened. If I had to guess, I would say it probably has something to do with spot reading thousands of manuals over a 20 year period.
This signature has Super Cow Powers
For what it's worth, I read the same way... I too have been told it is unusual, particularly considering the fact that when I first learned to read, I was taught to use phonics principles, and sound a word out based on how it was spelled.
File under 'M' for 'Manic ranting'
for(size_t i = 0; i
Wtf? Of course you mean
for(auto const & i : itemList )
If I am reading code out loud, I read == as "double equals", -> from C as "arrow", ++ and -- as plusplus and minusminus, respectively, and when reading javascript, === as "triple equals". I read the period when used as a separator from an object and its members as "dot", but when it is in a decimal number, I read it as "point". I read "&&" and "||" as "logical and" and "logical or", respectively, the boolean "&" and "|" as simply "and" and "or", and the & operator for taking the address of a variable as "ampersand".
When reading code silently, I don't think I associate real words to anything I am reading.. The smallest unit that I generally internally think of in code is a whole line at once, and often I think in terms of entire functions, as long they are small enough to fit on single screen without scrolling (a practice I try to adhere to, personally... as I find it results in more readable and comprehensible code).
File under 'M' for 'Manic ranting'
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.
That (essentially correct) observation led to the creation of the "Look-Say" method of teaching English and its replacement of "Phonics" in the public schools.
Look-Say attempted to skip the "learn new words by sounding them out" step and teach students immediately to use the faster words-as-a-chunk technique of good readers.
But that ended up crippling them, because it left them with no way to acquire new words. They knew the handfull they'd encountered in class as a set of pictograms but didn't have the "secret code" to parse somethig they hadn't seen before. Result: Mostly illiterate graduates whose reading was so painful to them that they did little, getting farther and farther behind.
Turns out that good readers of substantially phonetic languages start with sounding-out (Phonics-style). Then as they gain skill and experience they start recognizing progressively more words at-a-glance, falling back to sounding-out when they hit words for which they hadn't yet built a neural-net recognizer. Eventually the "speed-bump" words become so rare that they blaze along familiar vocabulary without appearing to sound-out at all. But new or rare words bring out the old toolset, rather than bringing them to a full stop.
There are a corresponding pair of methods for learning a "second (i.e. additional) language: The "Grammatical Method" (learn and practice the lnguage rules) and the "Audiolingual Method" (repeat the samples). The latter came from an attempt to emulate the rapid language acquisition of children by modeling their environent
Tested right after a series of courses, college students taught by either method score about the same. Tested a year or so later (if they haven't been re-exposed to the second language meanwhile) those taught by the Grammatical Method had a significant skill loss, while those taught by the Audiolingual Method were unable to emit any sentence they hadn't encountered in class. Oops!
Turns out that (unless you learn two or more languages as a child) the neural structures that make kids little language acquisition machines literally die off, in several stages (at the ends of age ranges called "critical periods") as the neurons that weren't used by the language learned are "pruned". Once this has happened, learning a new language isn't impossible. But it's more like recovering from a stroke.
Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
I try to give each function a different characteristic voice. I use a high pitched voice for smaller functions.
“Common sense is not so common.” — Voltaire
I like attributes and logic (expressions) in a tubular form to both more easily identify visual patterns, and to re-project (query) the tables to emphasize different things for different needs: one is not stuck with the original coder's layout and positioning. Early on even with textual code I'd line up similar function calls so that parameters lined up into columns.
When I tried to promote the idea of "Table Oriented Programming"*, debates ensued about grokking, and I eventually realized how differently people think about programming and code (or want to think).
In general there seem to be visual thinkers (me), symbolic thinkers ("mathy"), and verbal thinkers, like the question submitter. That's probably an over-simplification, but covers the gist of my observations.
There are many ways to solve a given problem, and I don't believe any one is inherently better, at least not under all circumstances. The computer doesn't "care" what form logic is in as long the processing rules are "known" to it: it can process BrainFuck or Java or Lisp of the same algorithm just fine. Thus, the code style is largely an issue of human grokking.
* I didn't invent TOP; I once saw a book written around the early 1970's that discussed much of the idea, but haven't been able to google it.
Table-ized A.I.
Yawn, When I am reading lines and lines of code it sure is not aloud ;) Just saying.
"As a programmer (and a reader of fanfiction), plenty of things I read are not valid English syntax."
As a long-time Slashdotter, plenty of things I read here are not valid English syntax.
#DeleteChrome
int i = 0; --> "there is a machine size int named i for a while, probably used as an LCV or index"
if(i == 0) --> "enter this area of code when i is 0"
for(size_t i = 0; i "start at 0 and go as many times as there are items in itemList...unless something messes with i in the loop. Also, how sure are you that itemList.size() is a compatible type to compare with a signed int?"
cout "How bad do I want to use this software?"
Someone had to do it.
Turns out that (unless you learn two or more languages as a child) the neural structures that make kids little language acquisition machines literally die off, in several stages (at the ends of age ranges called "critical periods") as the neurons that weren't used by the language learned are "pruned". Once this has happened, learning a new language isn't impossible. But it's more like recovering from a stroke.
This is total bullshit.
http://citeseerx.ist.psu.edu/v...
vi ~/.emacs # I'm probably going to Hell for this.
For example, take the following MIPS Assembly:
...
andi $a3, $t1, 41399
Which translates to: 001100 010010 011110 100001 101101 110011
Can easily be read as zero zero one one zero zero
and as a result will initiates a paradox-correcting timesphere.
... the program. You get used to it, though. Your brian does the translating. I don't even read the code. All I see is blonde, brunette, probable deadlock. Hey, I think I need a drink.
The main advantage of the audiolingual method is not actually whether you learn more material in class or retain more material when tested after ignoring the subject for a year. The real advantage is you have practice with useful coherent sentences and can sub out words to easily create new sentences that you are capable of saying out loud to another human being. Yes, the grammar is sometimes crap, but the meaning is sufficiently clear that the locals in that foreign country you are visiting understand. Thus the audiolingual method is a launchpad for you to teach yourself the language in situ, not necessarily a superior means to score high on a test. This is much like how a child learns language, and it works, providing you actually dive in.
As for the analogy between phonics and coding, I would expect experts to simply look inside "the loop", and then check the initialization, update, and exit conditions for the loop carefully if they sense there is need to parse it out carefully. Of course, they are capable of "phonetically sounding it out" and checking these things in the first place, much like I am capable of phonetically sounding out most any word. Rarely do I do so, though.
You need to understand it, if you can.
Sent as ripples into the electromagnetic field. No single photon has been harmed in the process.
i usually read it out directly in compiled MMIXAL.
Same as with math. When I work with math I think in "math" when I work in code I think in code. Only time I think in words is when I am writing comments in human language. I doubt anyone could write good code if they were setting there trying to formulate it in spoken language.
The only time I passed judgement was when someone pronounced "API" as "App-Ee" (please don't make me upload an audio file of that). Of course, I politely asked them to get off my lawn.
that sounds like a thread on 4chan's /g/
Next on Ask Slashdot: Who's your waifu?!
If I am just skimming code to find the relevant part, I use visual cues from the formatting. When I need to write or understand actual code, I form a mental image as I work with it. Only when struggling to understand some logic do I fall back to verbalization, since this by far is the least effective way of reading code.
I don't even see the code anymore. All I see is blond, brunette, redhead....
Thanks for sharing the article. It is an interesting read.
-- The Genesis project? What's that?
In my computer science course the lecturer taught us "a gets b" for a=b (assignment operator in c++ among other languages), or := (Pascal/pseudocode).
A handy convention for your inner dialogue and for communicating. You really shouldn't be saying "equals" for assignment.
If you've only learned from a book and self-study, you might never come across this kind of terminology, but I thought it was pretty useful.
He was talking about his penis not paycheck.
All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
Should be known as an assignment of a variable named i of type int(eger) with the value 0. The important bit is it being an _assignment_ and not a declaration of i being equal to zero.
That is a very important detail and not some kind of nit picking. Some other languages don't do assignment rather than binding a name to a value and for those reading it as equals is fine. Imperative languages assigns (guess there could be imperative languages with binding semantics but can't remember any).
A programmer expecting to use any other language outside the C/C++ family should never read "if (a==b)" as anything else as if a equals b. Many languages have "is" as a conditional with differences compared to "equals" opening up to difficulties when switching languages. The symbol "==" _is_ the equal symbol in C type languages, nothing else.
The first language with pointers and structures that I learned was Pascal, back in 1984. To dereference a pointer and access a structure it's:
My teacher pronounced that as "pointer up dot member".
To this day when reading C/C++ code I (internally) say that for
I don't know what I'd say out loud today if I had to talk about it. I don't work in C/C++ much.
Was a contractor who asked us to open "a-duck". We are all like, open what? Finally he says, open Active Directory Users and Computers or ADUC.
I only look human.
My mother is a halfling and my dad is an ogre, so that makes me an Ogreling
how do you handle the halting problem?
By punting and saying "Out of memory".
A physical computer resembles a linear bounded automaton (LBA), or a Turing machine with tape length proportional to input length, more than it does a general Turing machine. Though halting is not provable for a Turing machine, it is provable for an LBA.
God, you're one of those people who uses single letter variable names and think it saves time, aren't you?
The MOS 6502 processor has single-letter register names (A, X, Y, P, and S), and the most commonly used C compiler distributed as free software isn't nearly as good at optimizing as even an average assembly language programmer. Thus coding directly in assembly language can save a lot of CPU time. And if a variable fits in the X or Y register, I might add a comment to the effect:
Any variable that spills out to the local variable area on zero page gets a more descriptive name, such as ceiling_ht or mapsrc.
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.
I think many people upload videos to YouTube instead of posting text articles on their own websites because YouTube has a right column listing recommended related videos, and they anticipate that their videos might appear in the right column of popular videos by other uploaders. What's the counterpart to YouTube for text articles, including an automatically generated list of recommended articles from multiple authors?
Turns out that good readers of substantially phonetic languages start with sounding-out (Phonics-style).
This works for languages that are at least roughly morphophonemic, such as English. But how do readers start out in a language that doesn't write short vowels (like Hebrew or Arabic) or writes morpheme symbols descended from abstracted hieroglyphs (like Chinese)?
Tested a year or so later (if they haven't been re-exposed to the second language meanwhile) those taught by the Grammatical Method had a significant skill loss, while those taught by the Audiolingual Method were unable to emit any sentence they hadn't encountered in class.
What happens when students do grammatical method for a semester and audiolingual for the other semester?
I usually read code something like this: "Who wrote this shit!" "What the f_ck is this" "You gotta be kidding me" etc...
Sorry, that is all bollocks.
Learning languages, reading and writing: is EASY.
Teaching it is what is hard, e.g. teaching correct spelling, grammar etc.
If you would not force people to learn and would not grade them, but had an environment where they had fun and time and intention to learn, they would learn basically automatically.
There are no special neurons required to learn a language ... it is hard wired in the brain to do so.
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
I don't translate code into English when I read or write it. I don't need to nor would I want to.
for(size_t i = 0; i
The above I read it as: For i between 0 and itemList max counter, incrementing by 1.....
...of this issue:
For several years in the '80s, I volunteered for an organization called Recording for the Blind, doing just what it said: recording the equivalent of audiobooks for blind "readers." Most books, at least then, didn't come in Braille editions, so RFB aimed to plug the gap. Although I'd imagined reading novels and poetry, because I had developer experience they put me to work recording textbooks and such on how to code.
NO ambiguity was acceptable; if I tried to fudge something, a staff member monitoring the process would stop me, and I'd have to go back and record it again, for later editing into the final product.
Some of the examples above would definitely have qualified as "fudging." For instance, I couldn't read shared_ptr as either "shared putter" or "shared pointer"; it would have to be something like "shared underscore pee tee arr." And if the text (and/or the language itself) made an issue of case-sensitivity, then Shared_Ptr would NOT be pronounced the same way as shared_ptr -- I'd have to distinguish the pronunciations by pointing out the upper/lowercase differences. Over time, we came up with conventions to simplify this -- like recording an intro explaining the conventions used by the particular text, so every single instance didn't need to be spelled out. But it was never "easy" or "unimportant"; on the other hand, while I derived satisfaction from my volunteer work, thanks to the RFB experience I can't say that I regretted eventually moving away from that geographic area.
Aside: I once took a course in developing queries for PeopleSoft, back before Oracle acquired them. One of the standard table names was "DEPT_TBL"; the instructor always pronounced this "department tibble" -- it drove me CRAZY until I figured out what the hell he was talking about.
REEEEEEEEEEEE
I don't really read code unless I've run into a snarl of conditional logic. Then it feels like I'm kind of sounding out the logic expressions while cursing under my breath about some asshat that doesn't know what state-machines are for.
What I am doing is watching for declarations, assignments, usages, language structures and flow that eventually lead me to see what a chunk of code is doing. This happens most often when I'm trying to understand what a low-level function is doing. Higher-level stuff is usually named well enough that it is easy to see flow like reading dialog in a screen play or novel. Poor formatting slows this down to an annoying degree.
If I had to give it a concise description... It is like contemplating a painting, or a photograph, until all of it's elements make sense.
One exception is when reading assembly language. I'm keeping a running tally in my head of the key variables and operations as I scan down the list of operations in a function. I'm watching for common idioms and macros, etc. Again this eventually results in abstracting all of it away and thinking of the function. This feels to me kind of like sounding out a new word.
[I was programming in BASIC at 11, and transitioned into 6502 and Z-80 assembly pretty quickly. BASIC was just too slow for what I was interested in.
I guess I was in my mid 20's before I did anything professionally with C/C++, or anything other than assembler languages, for that matter.]
"The majority of humans read silently by rendering a simulation of the printed words as if they were being spoken."
Wait? Seriously? That sounds awful! How do you get through a whole book that way?
He said he got out of programming.