Settings

Theme

What coding mnemonics do you use?

27 points by vickytnz 12 years ago · 87 comments · 1 min read


What weird coding things do you have to use statements for or other weird tricks to remember? I can never remember < or >, and only remember that < is less than from years of typing (i=0; i<30; i++).

MichaelAza 12 years ago

Not a mnemonic per se but I have melodies for common code snippets.

"public static void Main(string[] args)", which is the default method signature for the main method in C#, is a hip-hop beat. SQL statements are always metal tunes. Javascript is usually indie pop.

  • suhailpatel 12 years ago

    I also have a melody for the default method signature in Java which is the same except a slight difference in case "public static void main(String [] args)"

    • JonnieCache 12 years ago

      Please tell me you guys are actually singing the signature to a particular tune in your head like people sing the ABC song when they recite the alphabet. Because that is adorable.

      Rapping arbitrary chunks of code could be a fun after-hours conference game.

  • zqfm 12 years ago

    Just out of curiosity, do you say "array of string" or "strings" or something else?

    • MichaelAza 12 years ago

      Actually, I say "string" and then drop the bass for the square brackets.

      • shousper 12 years ago

        Normally, this would honestly be a moment when I'd question if you were trolling, maybe post the fry meme image.. but. Given the topic, I actually believe you O_O

Terretta 12 years ago

Markdown hyperlink syntax:

  "squared circle" aka []() aka [word](http://link)
hill79 12 years ago

I never remember that . = class and # = id in CSS, so I use "say no to drugs" to remember that "hash is not class".

Perhaps a mnemonic which only really works in the North East of the UK where 'class' is colloquial slang for 'good'. Also not very good if you smoke pot, I guess.

  • vickytnzOP 12 years ago

    I also took it to mean that it's not classy to smoke hash (i.e. 'you stay classy, San Diego' :D)

  • Toadsoup 12 years ago

    I remember the difference between class and id by thinking someone is trying to "Pound an idea into your head" or rather "# an id"

  • raverbashing 12 years ago

    Just remember that a hashtag points to something specific. A dot means nothing, so that's the least specific/most generic thing

  • nakkiel 12 years ago

    Strange one. FYI, "class" has the same meaning in French slang -- probably borrowed from you guys.

    • scrapcode 12 years ago

      I think it's the other way around. I think you guys use _class_ as slang to _classy_: "pertaining to or characteristic of a (high) class," which comes from the literal sense of class, which comes from the French word _classer_.

      I didn't know for sure, but I had that feeling knowing that most of the English language is borrowed from others, and not the other way around. (http://www.etymonline.com/index.php?allowed_in_frame=0&searc...)

ronaldx 12 years ago

The fact that programmers can't remember < and > well illustrates why children shouldn't be chastised for getting (for example) b and d wrong.

I have dealt with this by conditioning myself to always read < as 'is less than'

  • norvig 12 years ago

    When I was in grad school a friend in another department said "You guys in CS have much nicer printers; can I mail you my thesis and have you print it out? And how would I mail it?" I said "Sure; Just do 'mail me@school.edu less-than-symbol filename". Later he calls in a panic -- "my thesis file has disappeared! I did what you said ... oh, wait a minute, I might have done greater-than instead of less-than..."

    Fortunately for both of us, he had been diligent about making backups and din't lose his entire thesis.

  • afandian 12 years ago

    I find it hard to believe that a statistically normal programmer mixes up < and >. That sounds more like dyslexia.

    • yogo 12 years ago

      This is the first time I'm hearing about this too so I think there is more to it. I don't even see why a mnemonic is required since the shape of both '<' and '>' clearly demonstrate the relationship that the operator is testing.

      • vickytnzOP 12 years ago

        I probably should have chosen a better mnemonic to start from! I'd point out that if you see greater and less than more like arrows it's utterly confusing. I'm not denying I'm probably weird in that respect, it's just something I have to use tricks to remember….

      • inthewind 12 years ago

        Also a lot of people have trouble with the back and forward slashes. When teaching html, people got the closing slash mixed up, it was all over the place.

    • ronaldx 12 years ago

      I was surprised to see that as an example as well, but then I thought back to starting out as a programmer.

      I'm sure I spent many hours fixing bugs caused by getting < and > wrong.

      • karka91 12 years ago

        I find it hard to believe that someone actually mixes these unless they completely skipped all math classes in school.

        • anonymous 12 years ago

          Ah, yes the "I can't fit it to my mental model, therefore it is impossible" argument.

          When little, my brother used to mix up the words "more" and "less" while speaking. I don't doubt someone could mix up > and <.

          • Chris2048 12 years ago

            It's easy. They're alligator mouths, that always go for the larger number (greedy alligators!)...

            • ronaldx 12 years ago

              This genuinely confused me because I thought the larger number would eat the smaller number.

          • blablabla123 12 years ago

            I used to mix it up in elementary school because the school teacher explained that "<" is "less" and ">" is "more". Even worse, she suggested to memorize it like this: |<leiner = kleiner (german, meaning less)

            At some point I realized it's possible to memorize it visually, since then I never mixed it up again

          • inthewind 12 years ago

            Yeah people frequently mix up left and right also. And my brother always wrote his numbers backwards or rather left to right (units on the left).

        • taejo 12 years ago

          I remember several kids in my class having great difficulty with < and > when they were first introduced. I can well imagine many of them just decided it was impossible and gave up.

          • PeterisP 12 years ago

            Was it possible to give up? In my place, they wouldn't be let on to the next grade if they'd fail basic math - i.e., they'd spend the summer repeating it + an extra year in the same grade if that wasn't enough; so it would have to be a real exception to see a 10 year old who can't somehow manage that.

            Anyways, the classic mnemonic for that was simple - for < and > the wide part contains more 'thingies' than the narrow part. They're actually taught before numbers or together with numbers, like [pic of four strawberries] > [pic of three strawberries].

        • vickytnzOP 12 years ago

          I was taught the crocodile thing, but had real issues with it: I can think it through but it's not fast. I'm pretty much ambidexterous (i.e. write with left and catch a ball with my right) so while I can do quite a lot of things with both hands I also have problems with left and right!

    • thedudemabry 12 years ago

      I've known a few otherwise non-dyslexic programmers that have had this issue. One guy kept a sticky note on his monitor with "> Greater, < Less" written on it.

      • afandian 12 years ago

        I find that really fascinating. Was it just those things? What about which paren (or brace) opens and which one closes? (I'm not being facetious!)

  • kelvich 12 years ago

    Teacher in elementary school taught me simple rule: signs < and > has two endings on one side and one ending (corner) on another. So two bigger than one and bigger number should be on side with two endings.

    • rwbcxrz 12 years ago

      Mine taught us that it was an alligator, and it always wanted to eat the bigger number.

  • llcoolv 12 years ago

    specifically for this one, I have the mnemonic that the side containing the lower value has only one vertex, while the higher has 2 :)

    • milliams 12 years ago

      Yeah, the smaller end of the triangle is the smaller number and the wider end is the larger number.

  • chewxy 12 years ago

    Interesting. So other people too do get it mixed up. Makes me feel less silly when I find bits of my own code that looks like `x := >- receiverChannel`

    I've always thought it's because of carelessness

jentulman 12 years ago

LoVe HAte when ordering psudeo classes in css for anchors*

  ":link, :visited, :hover, :active"
*may not be particularly weird or novel
  • halisaurus 12 years ago

    Also CSS related, when doing margin/padding I use "TRouBLe" to remember:

        margin: (T R B L)
    • jentulman 12 years ago

      My one is visualising a clock face, 12, 3, 6, 9

      • Someone 12 years ago

        Thats a nice example showing that mnemonics need not be logical to have value (if you asked people to order the numbers on a clock face, I think the vast majority would have them as 3, 6, 9, 12)

    • shousper 12 years ago

      Do you have one for border-radius? Because I still can't remember the order of those..

    • Toadsoup 12 years ago

      That's the one I use as well.

      Although I can never remember the 3 parameter verision

      margin: (T R&L B)

  • brokentone 12 years ago

    I heard "Las Vegas Hells Angels" and it's stuck with me.

    • jentulman 12 years ago

      That's far more rock'n'roll, I might make the switch. Now I just need to remember...

      'Naughty Llama Holidaymakers Book Lovely Vacation Homes from AirBNB'

      = N.L.H.B.L.V.H.A = 'not Love Hate but Las Vegas Hells Angels'.

anotherhue 12 years ago

Questionably coding, but I always loved this IRC snippet:

<sdmkun> tar -xzf merc.tgz what the fuck

<sdmkun> how the fuck do you people remember this shit

<bucketmouse> just think with a german accent

<bucketmouse> XTRACT ZE FILES

billb2112 12 years ago

I was taught the alligator/crocodile thing like many others, but it never really stuck. For some reason (later in life), someone said "left hand, less than" as they held up their left hand to form a less than sign. That image sticks in my head a lot better.

Another thing that was particularly hard to get naturally was the ternary operator. It didn't sink in easily until Jon Skeet said pretend the ? is indeed a question. If the answer is 'yes', this will happen.

raverbashing 12 years ago

Not related to programming but close

The symbol for a diode is something like this: --|>|--

Now, which one is the Anode, which one is the Cathode

Very simple, the Anode has an A in the drawing (left side, turned 90 degrees), the Cathode (K) has a K, right side, upside down in the drawing

da02 12 years ago

.unshift - makes it bigger. Longer word than .shift

.shift - makes it smaller. Shorter word than .unshift

  • ronaldx 12 years ago

    I could never remember this until someone told me to imagine that an array is like a row of chairs at a cinema.

    "Shift" will shift everyone up one, bumping someone off the start of the row.

chriswaugh 12 years ago

When working with axis - "X is a-cross"

pwg 12 years ago

You might try a visual trick. Note that < and > look like "arrows" and "point" in a particular direction. There is a small end (the tip/point) and a large end (the open end). The vertical size of the point is "less than" the vertical size of open end. So if the point comes first (reading left to right) then the point is "less than" the opening (and the symbol means "less than"), but if the opening comes first (reading left to right), the opening is "greater than" the point (and the symbol means "greater than"). .

  • MerreM 12 years ago

    Imagine the arrows are crocodiles. They always try and eat more.

    1 < 2

    4 > 1

    If they're eating less, they're not happy crocodiles.

  • hill79 12 years ago

    I don't know if this is common, but I visualise numbers on a line which makes it amazingly easy to use the 'arrows' metaphor

      <  > 
    1 2 3 4 5
    • dasil003 12 years ago

      That seems ambiguous to me in several ways. There must be more semantics you are subconsciously depending on to clarify it.

      • masukomi 12 years ago

        I think he means that he visualizes the pair "< >" relative to a line of numbers. Similar to how he placed it above a line of numbers in his ASCII art. < points down (left) the row of numbers to numbers that are less than the other ones and > points up (right) to numbers that are greater than. Makes perfect sense if you are a visual thinker.

  • JonnieCache 12 years ago

    You can make it even simpler than that: just put the big number next to the big end of the glyph and vice versa.

  • RutZap 12 years ago

    I use the same visual trick (more or less, looking at < and > as arrows, or if you want, spears) but I visualise bigger numbers as more "powerful" numbers that poke the "weak", smaller numbers with the pointy bit :D That's how I imagined them when I was a small child and that's how I still "see" them :D

    Numbers are cruel and ruthless :)

  • pubby 12 years ago

    I'm not convinced programmers even need a mnemonic for < and >. After all, they'll read and write those glyphs millions of times in their lifetime.

    • JonnieCache 12 years ago

      At least for me, the metaphors that I used to learn the symbols as a child have become my enduring mental models of those constructions, even if they're not actually needed to recall them any more.

  • tome 12 years ago

    Oh, I didn't realise anyone didn't remember it that way! I remember being taught it, but just assumed everyone else was, I guess.

PaulHoule 12 years ago

< and > are pretty easy. The big side (the mouth) points to the larger number because that it what it wants to eat.

  • raverbashing 12 years ago

    I learned this in school. Still effective.

    But I never know which one is "smaller than" or "bigger than", I have to think a little bit

  • scrapcode 12 years ago

    Or you're pointing (or poking fun) at the little guy.

CJefferson 12 years ago

Most methods in C read like an assignment,

so if you are trying to remember what order the arguments to strcpy go, it's

    strcpy(x,y) is like x = y
Then remember specially that typedef is the wrong way around to the way you would like it to be :)
  • belovedeagle 12 years ago

    The trick with typedef is it is exactly the same syntax, in all cases, as declaring a variable of that type. This is essentially the only way you're going to ever remember how to do function pointer typedefs: typedef int (function_t)(int,int); // or something to that effect

ChristianMarks 12 years ago

For the right-hand rule, a vile insult: take the cross-product of the thumb and forefinger of your right hand and rotate on it.

Look, Joshua Foer says that emotional imagery is more likely to stick...

anonymous 12 years ago

I don't use mnemonics in general. For me the effort to remember the mnemonic is actually double that for remembering the thing per se. I need to once remember the symbols->mnemonic connection and then the mnemonic->meaning connection, instead of simply the direct symbols->meaning one. It feels like cluttering my brain with junk that not only doesn't make it easier to remember things, it actively makes it harder.

burgeralarm 12 years ago

When using ln to link files, I tend to recite:

ln -s "what you want," "where you want it"

3minus1 12 years ago

backslash is a man falling backwards. forwardslash is the opposite.

Joeboy 12 years ago

"dollar hat, dollar at" in Makefiles:

$(CC) -c $^ -o $@

leigh_t 12 years ago

\r\n or \n\r?

ReturN - R before N

  • informatimago 12 years ago

    Carriage Return is first because it takes much more time for the carriage to go back to the column 0 from the column 79, than for the paper to Line Feed one line. So while the carriage is flying back, the paper can feed, and hopefully we won't have to wait too much time for everything to be ready for a new line. Or we may always insert some Nul codes to wait.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection