tags:

views:

5893

answers:

63

Do you have any clever pseudo-code phrases? Maybe a common phrase that has analogous pseudo-code? What's your best one?

For example, one I've seen, from bash.org:

A programmer started to cuss
Because getting to sleep was a fuss
As he lay there in bed
Looping 'round in his head
was: while(!asleep()) sheep++

One I thought of/use:

  • "Skills to pay the bills": foreach(bill) paywith(skill)

Have any to share?

What would you call these if you gave them a name?

+89  A: 
    2 * b || ! (2 * b)

always deserves a mention

cobbal
Awesome, love it!
Chris
If that's the question, the answer is always TRUE!
Adam Liss
It's a syntax error in C#. ;P
strager
valid in C99, assuming b is defined
cobbal
0x2b || !0x2b :)
char question = 0xFF;if (question == 0x2B | ~0x2B)suffer(outrageous_fortune[slings elsetake_against(arms, troubles.c)
cobbal
question = (2 * b || ! (2 * b ))
hasen j
@Adam Liss — Not so! What if b is "#define b (++a)" and a is equal to -1 when that line is executed? ;-)
Ben Blank
I was going to upvote this, but want it to stay at 42. Sorry. :)
BenMaddox
Same here. It stays at 42. :)
Vulcan Eager
but "to be or not to be" is the question, not the answer :)
cobbal
alex
-1, has to stay at 42!
Treb
perl -e 'print 0x2b|!0x2b, "\n"' => 43. Off by one, sorry.
d0k
d0k, `0x2b` = 43, but `0x2b | ~0x2b` = -1
hasen j
so (0x2b | ~0x2b) + (0x2b | !0x2b) = 42
cobbal
0x2B | ~0x2B == 0xFF <- that is the answer.
Zifre
ThinkGeek sells a t-shirt: /bb|[^b]{2}/
Samir Talwar
+39  A: 
void CreateLimerick() {
#define poemKind terriblySlick
  if (lines == 5
  && rhymesWith("live") {
DoLaugh(); Perform(new Trick()); }}
John Feminella
http://mail.python.org/pipermail/python-list/2005-March/313900.html
Miles
http://xkcd.com/554/
cobbal
+16  A: 

FORTH LOVE? IF HONK THEN

gbarry
Okay, I feel stupid. Someone explain this one.
Chris
FORTH is a stack-based language (like an RPN/postfix calculator). You push data on the stack and then compute by pushing an operator than pops its arguments. This expresses the logic "Honk if you love FORTH" in FORTH syntax (assuming that "LOVE?" is a unary operator)
Tyler McHenry
sounds like reverse polish notation or something
Joe Philllips
@d03boy: That's because RPN was created for use in stack based systems ;-)
Treb
+30  A: 

Can't remember the original off the top of my head (feel free to edit this if you can) but something like this. For Star Wars fans

do || !do;
// try {};
alex
I'm no Star Wars buff. My guess is it's a Yoda quote ending with "to try is nothing."
Chris
"No. Try not. Do... or do not. There is no try. "
Chris Lutz
Thanks! I am humbled by Yoda's wisdom. :)
Chris
Hope my attempt is good enough people can figure it out. Trailing semi colons are just ingrained in me from PHP and JavaScript (optional I know, but I prefer them)
alex
do || !do;//try { }
Joe Philllips
hehehe gooooood good
thomasrutter
I always thought it was:do || !do;#define try
DK
@DK, I think they all work to some degree...
alex
+20  A: 

Oldie:

while ( !(succeed = try()) );
Adam Liss
I love this one.
Josh
Wouldn't this one be: `while (!succeed) { try(); }` ?
Shaharyar
@Shaharyar: how does "succeed" get updated?
Adam Liss
I assumed that try() is a method inside the class and it would update the value as soon as the function succeeds?
Shaharyar
+18  A: 

From a t-shirt

i > u
JaredPar
I have that shirt. While I can't argue with the math, the grammar drives me crazy. :-)
Tim Sullivan
@Tim, same to both :)
JaredPar
thats 1 number away from something
It looks like "i <3 u"
furtelwart
+10  A: 
pthread_mutex_lock(&coop_mutex);
pthread_cond_wait(&hatched_cv, &coop_mutex); 
ct = count_chickens();
pthread_mutex_unlock(&coop_mutex);
Uri
+1 for cleverness -- is that original?
Adam Liss
Yea, I was reading the frigging pthread manual earlier today, so it was in my head when I saw this. Java threads are so much more convenient :)
Uri
+5  A: 

Bible reference:

first = last;  
last = first;
Perchik
(last,first)=(first,last) is an alternative in some dynamic languages.
Kent Fredric
Any interpretation for the religiously illiterate? :)
Chris
The first will be last and the last will be first. That's a rough approximation. I suppose I could go look it up -- it's something Jesus said.
thursdaysgeek
But here, the first will be the last and the last will be the last, too. ;)
Nikhil Chelliah
which is my version is more correct, it does an in-place swap :). With his, the second line is redundant.
Kent Fredric
It hink you might want to include a temp variable :P
Joe Philllips
possibly the oldie if (first!=last) {*first ^= *last; *last ^= *first; *first ^= *last;} //assumes C99 or better
Adriano Varoli Piazza
@Adriano - you assume it's an int (or something XOR-able, anyway).
orip
Oh, this works well in VHDL :)
netom
+18  A: 
10 LATHER
20 RINSE
30 GOTO 10
Adam Liss
I know ... downvotes for the GOTO!
Adam Liss
@Chris: Assembly?
X-Istence
@X-lstence: what else has line numbers in 10s and uses GOTOs?
Chris
Assembly would be ":start LTR; RNS; JMP :start" :)
Blorgbeard
+7  A: 

FK UNICODE

Oh, pseudocode phrases? No...

John Rasch
I prefer the more positive: "I � UNICODE": http://www.codinghorror.com/blog/archives/001084.html
Joachim Sauer
+19  A: 
public class Egg
{
    int hashCode()
    {
       ...
    }
}
Uri
A way to make sure you don't put all your eggs in one basket...
Uri
Is it meant to sound like hatchCode()?
alex
No, just that if you implement a hashcode on your eggs, they're less likely to all end up in the same basket (or bucket...)
Uri
+73  A: 

Code to display the name of everyone's favorite web site ... eventually:

void x(void) { x(); }
Adam Liss
hehehe nice one .. took me a coupla seconds to get it
hasen j
what? but stack overflow is my favorite websi.... oh
Joe Philllips
I see what you did there.
sirlancelot
Yay for SegmentationFault.org... wait... wrong language...
cobbal
xxx? That's as far as my brain went. :D
Chris
Can't get what this is.
Vijay Dev
@Vijay Dev: Run it in your head. :)
unwind
same delay here :)
dr. evil
@All: wish I could upvote your comments!
Adam Liss
Tailcall optimization would reduce this to One Infinite Loop...
Tim Lesher
@Vijay Dev: what's happening here? A method is calling itself repeatedly with no exist condition... What will happen if a method calls itself repeatedly with no end in sight? The stack will overflow at some point... StackOverflow.com!!
Shivasubramanian A
@Shiva: Only true if you're using a stack-based language implementation. Nothing about C++ (for example) says that you have to be using a stack. :)
John Feminella
I'm afraid some tail recursion optimization will thwart your plans! :)
Gracenotes
Well what do you know - several months later and I _CAN_ upvote your comments!
Adam Liss
@Tim Lesher, Nobody jokes in tailcode optimization.
Gleno
+75  A: 

I forget the original source of this; it had some other ones it it, but I also forget what they were.

class Employee
{
    long lunches;
    short hours;
    double pay;
};
Adam Rosenfield
How about: short lunches; long hours; bit pay;
Chris
What about byte juniors;
Jonathan Parker
I think that should be "class Manager"
A. Levy
@Chris, i think you are missing `byte me;`.
Georg Fritzsche
From where I live "class" also means fantastic
TWith2Sugars
From where you live "Employee" also means someone who bothers to go to the Job Center.
kjfletch
+34  A: 

Spinoff on Uri's answer...

public class Chicken {
    private Chicken() {
        ...
    }
    public Egg layEgg() {
        return new Egg();
    }
}

public class Egg {
    private Egg() {
        ...
    }
    public Chicken hatch() {
        return new Chicken();
    }
}
Nikhil Chelliah
lol... love this one :D
chakrit
Good...but you need to declare the Chicken as friend to the Egg, and vice-versa.
A. Levy
Shouldn't Egg inherit from Chicken? /me ducks
oɔɯǝɹ
A. Levy, what horrible language are you thinking of? =)
Gleno
+22  A: 

This one was in Futurama

10 HOME
20 SWEET
30 GOTO 10
alex
First one that jumped to mind. =)
gnovice
hehe i always loved that that was an infinite loop :)
thomasrutter
+1 - I'm a sucker for Futurama.
Chris Lutz
HOME SWEET HOME SWEET HOME SWEET...
rlbond
+6  A: 

From The Simpsons.

C:/dos, C:/dos/run, Run/dos/run

There's one from Futurama. A crippled (young) robot is holding this:

while (1){
   printf("I love mom");
}

I$ find "your_lack_of_faith_disturbing"

Tom
Only one person in a million would get that!
David Berger
+47  A: 

Classic Foxtrot comic

Factor Mystic
Gah, beat me to it! I was just about to post this, but it took me a while to find it.
Adam Rosenfield
/me thinks he'd need a try{}catch(){} on that ;)
Kent Fredric
He failed because he forgot the \n terminator.
Ferruccio
@Ferruccio: good spot. I also think it would be better if the for loop went from 0 to <500. Would save one keypress anyway.
demoncodemonkey
I actually did this in 5th grade... I asked permission to type and print my punishment phrase instead of submitting a notebook with 1000 copies.
Uri
@Uri, +1 for beating the system!
Eric
Free Image Hosting in Excess :(
KennyTM
This is totally not optimal. Also, why are blackboards in C?
Gleno
+4  A: 

probably lame .. but

class Person
{
    //....
    boolean exists()
    {
        return this.thinks();
    }
    boolean thinks()
    { 
        return this.brain != null; 
    }
}
hasen j
+8  A: 

OK So it's SQL but still it tickles my fancy...

Select * from Users
Where Clue is not null

Rows Returned: 0

Courtesy of the Think Geek Overlords

Jon P
A: 
while(DateTime.Now < DateTime.Now.Date.AddHours(17).AddMinutes(1))
{
    HttpWebRequest myRequest =
  (HttpWebRequest)WebRequest.Create("http://stackoverflow.com/users/USERID?sort=reputationhistory");
    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
}
Jonathan Parker
Won't the while condition always evaluate to true?
Piskvor
I believe that is the point
cobbal
No, it will evaluate to true between midnight and 5pm, I believe. The ".Date" bit truncates Now to midnight.
Blorgbeard
+2  A: 
public class Person
{
    public DateTime LearningCurve { get; set; }

    public DateTime LifeExpectancy { get; set; }

    public bool Stoopid
    {
        get
        {
            return this.LearningCurve > this.LifeExpectancy;
        }
    }
}
Gordon Mackie JoanMiro
i'd replace 'stoopid' by just 'looser'
GogaRieger
+9  A: 

A bit more cryptic:

mkfifo('dream')
Ali A
Just a pipe dream?
Chris Connett
+44  A: 
while(whatWeNeed != education())
{
   wall->add(bricks++);
}
Ólafur Waage
if (meat.hasBeenEaten()) {servePudding();}
James Van Huis
bool wrong = true; do {it_again();} while (wrong);
EvilTeach
pink floyd reference? awesome!
alex
+14  A: 
if(youreHappyAndYouKnowIt) {
    clapYourHands();
}
I.devries
I like the syntax error one more: http://www.ratemyeverything.net/image/9914/0/Syntax_Error.ashx
Ólafur Waage
Matthew Crumley
DisgruntledGoat
@Olafur: happy was unexpected at this time.
Mark
A: 

From the movie The Shining

All work and no play makes Jack a dull boy.

if (Work() and Not Play) then Jack = Dull

or

if (Work() && !Play) Jack = Dull;
Steve
In times like these, it is more appropriate to say : "if (work() "
ePharaoh
or even `Jack = null` :)
alex
A: 
if what.goes_around?
  what.comes_around
end
DanSingerman
+7  A: 
def Life()
   while heartbeats
       wakeup
       breakfast
       if weekday
          work
          lunch
          work
       else
          play
          lunch
          play
       supper
       bath
       while (!sex) 
          sleep
   exit
Steve
too much duplicate code, you should do something about it.
Geo
But thats life ... to much repetition ;-)
Steve
no shower or "throne" time? just picking... i like it :)
Ascalonian
I thort about the throne time but that was just a bit toooo much detail!
Steve
Between bath and sleep, I'd want to add sex.
Jonas Kölker
Don't we all Jonas, don't we all!
Gordon Mackie JoanMiro
what aboutif (!sleep) sex
Steve
Ah, likely endless loop geeks near the end. :)
BenMaddox
Yeah, I noticed that but left it in as who in their right mind would want to get out of that loop!
Steve
+2  A: 

For the Star Wars geek...

$DO || ! $DO: try  
try: command no found

OR

if(child.eatsVegetables()) {
   child.becomeBigAndStrong();
}else{
   child.remainSmallForever();
}

OR EVEN

if(self.makeFunnyFace()) {
   if(faceMakingTime > aLongTime) {
        self.face().freeze();
    }
}
Ascalonian
+2  A: 

HermanD what about

if what.goes_around == what.comes_around
   do.good
end
Steve
A: 

oh->shit(pointer);

Tim Post
+2  A: 

Name that tune:

if (baby.getEndDate() != null) {
  setAddress(
    new Dwelling("HeartBreak Hotel", "Lonely Street"));
}

for (int i=0; i<3; i++) {
  loneliness++;
}
mood--;

if (crowded) { // crowded always true?
  Room room = new Room();
  room.setClientelle("BROKEN_HEARTED_LOVERS")
  room.setFunction("GLOOM_AVERSION_THERAPY")
  room.getInventory().add(new Carton("Tissues"));
  room.book();
}    

if (role() == BELL_HOP && teary()) {
  global_tear_count++;
  setResidency(PERMANENT);
}  

if (role() == DESK_CLERK && getAttire.color() == Color.BLACK) {
  setResidency(PERMANENT);
}

if (recent(baby.getEndDate()) && !member()) {
  ambulate(getAddress("HeartBreak Hotel"));
}

Courtesy Gen-e-sis.com

Gavin Miller
Funny that the answer is in the URL you provided.
Cory Larson
If you couldn't figure it out by the new Dwelling command, you weren't going to anyway.
Perchik
+1  A: 

C#:

while((bouncing = paycheck())) new Action(() => {})();

JavaScript:

while((bouncing = paycheck())) (function() {})();

Chris
+8  A: 
for(int i=99; i>=0; i--)
{
    if(i!=99) cout<< i <<" bottles of beer on the wall"<<endl;

    cout<<i<<" bottles of beer on the wall, "<< i <<" bottles of beer."
        <<"Take one down, pass it around, "

     if(i==0) cout<<"no more bottles of beer on the wall. Hiccup!"<<endl<<endl;
}
Perchik
+40  A: 

Apple naming function:

function name($product){
     return 'i'.$product;
}

Google naming function:

function name($product){
     return $product.' beta';
}

Microsoft naming function:

function name($product){
     return name($product);
}
VirtuosiMedia
Excellent! +1 for turning "obvious" into "CLEVER"
Adam Liss
devio
+ anyof("", "SP1", "SP2", "SP3")
devio
I'd like to see the MS versioning system also explained. :)
Rev316
@Rev316: function name($product){ return name($product.date("y")); }
VirtuosiMedia
So nobody noticed that the last function is an infinitely recursive function.
Ólafur Waage
@Ólafur i did i did i did !!!!1
herzmeister der welten
+4  A: 

Another from Futurama:

10 SIN
20 GOTO HELL
gnovice
Why the line numbers ? You're not using them.
ldigas
It was some BASIC code on a banner in the Church of Robotology.
gnovice
+3  A: 

reaction = screwed? flight() : fight();

Or:

function respond(situation) {
 if (situation == screwed)
  flight();
 else
  fight();
}
Chris
+18  A: 

Here's a bible one:

class the_earth
{
...
};
class the_meek : public the_earth
{
...
};
gnovice
Or maybe just this :): class earth {} class meek : earth {}
Chris
That would be a bit shorter. =)
gnovice
"And thusly, said Godeth, >> THE MEEK SHALT INHERIT FROM EARTH <<." No he dadn't. :(
Gleno
+2  A: 

select * from users where clue > 0
0 rows returned

tsilb
A: 

When everybody tells you that you like every kind of woman:

class Everyone<T> where T : IDoable
{
  T woman;

   public void haveFun()
   {
       //Cool stuff goes here!
   }
}


class Blonde : IDoable
{
   ...
}

class Brunette: IDoable
{
   ...
}
MRFerocius
+4  A: 

From just before last year's election (obviously referencing the former President Bush and the Presidential candidate Barack Obama and his running mate Joe Biden, for those not in the US):

Bush^3 vs. /O(s|b)ama Bi(n La)?den/ -- YOU DECIDE!
Ken White
if(!(Bush^3)) { WorldHasHope = TRUE; }
Oliver
Agreed. <g> I just thought the use of regexes was interesting in that context.
Ken White
+4  A: 

The only constant in our world is change:

    public class OurWorld {
      public const int change;
    }
kdmurray
+1  A: 

This is what I like to call: To be married

//Singleton
public class Marriage
{
   static Marriage myMarriage = null;          // the best option!!
   public Woman myWoman {get; private set};    // why private!!

   private Marriage
   {
      myWoman = new Woman();    // smelly code... no new
   }

   public static Marriage getInstance()
   {
      if(myMarriage == null)
        myMarriage = new Marriage();

        return myMarriage;
   }
}
MRFerocius
+40  A: 
SELECT * FROM businesses WHERE business LIKE 'show_business%';

0 ROWS RETURNED
Adam Liss
That's a great one!
Ólafur Waage
+4  A: 
#!/bin/bash
# Apologies to John, Paul, George, and Ringo.
while true; do
   echo "Strawberry Fields"
done

Or:

yes "*****" "====="  # Where's my sousaphone?
Adam Liss
A: 
void test(char *str, int max) throw(...)
{
    if (_stricmp(str, "Bathwater")
    {
        strcat_s(str, max, " Baby");
        throw(str);
    }
}
Adam Liss
+2  A: 
 sudo find / -name "*egg*" > basket
Adam Liss
+18  A: 
public double penetration;
would that be part of the Employee class? =D
devio
Nope, only the Secretary class has that.....
Hopefully a "general protection fault" doesn't occur too. =)
gnovice
+8  A: 
cd pub
more beer
Andres
+28  A: 
bikini.ToString();

ahem.

blowdart
I prefer Bikini.hide()
Dominic Bou-Samra
This is the best answer here...
Jorn
LMAO :D Amazing!
Christian
Oh, come on now! Bikini.Remove();
Loren Pechtel
+8  A: 
while (looks($girl) < "hot"){
    beer.next();
}
Alekc
I'd have gone with "beer++";
gnovice
Ooh, good call gnovice.
Chris
A: 

I make money this way!!

if (pocket.money.saving() < money.currency.usd(500)) { 
   moneyrenter money = new moneyrenter(4000, money.currency.usd());
   pocket.money.charge(money);
}

Put it on a thread and you'll never get poor!!! :D :D

Omar Abid
Horrible, horrible coding practices expressed here. Ugh. I can't believe I even edited it.
Stu Thompson
A: 
SELECT * FROM tblMeals WHERE type = 'lunch' AND cost = 0;

0 ROWS RETURNED
Adam Liss
A: 

Whenever using a static variable in a function in PHP, I can never get past the temptation just to write:

static $x;

[explanation]

It makes the code really hard to understand, but it's totally worth it.

nickf
+1  A: 

In commenting on an answer to this question, which asks about converting strings of hex digits to decimal, I ended by suggesting:

It's a matter of taste: 6 of one, C>>1 of another.

Adam Liss
+3  A: 
if ($eggs->haveHatched) {
   $chickens = count($eggs->get());
}
alex
+4  A: 

Perl Poetry

if ("a packet hits a pocket") {
On: a;
socket(ON, A ,PORT,"")
       && the bus is interrupted as a very-last-resort
       && the address of the memory makes your 
          floppy disk, abort;

} else {

"The socket packet pocket has an";
error: to-report;
} 

if ("your cursor finds a menu item") { 
"followed by a dash"
        && "the double clicking icon";
puts: your-items-in-the-trash
        && your data is corrupted cause the 
           index("doesn't", "hash");

} else {
"Your situation is hopeless"
        && Your system's gonna crash;
} 

if ("the label on the cable") {
On-the-table, at-your-house;
Says_the; 
sub network {"is connected to the button on your mouse"};
BUT: Your-packets, want-to; 
{/tunnel to another protocol/};
thats: repeatedly-rejected; 
{/by the printer/}; "down the hall"
        && "YOUR SCREEN is all distorted";
{/by the side effects of Gauss/};
so: "your icons", in-the-window;
"are as wavy as a souse";

} else {
YOU: "may as well reboot" && "go out with a !";
CAUSE: /Sure as Im a poet/;
THIS: suckers-gonna-hang;
}

print "Seuss as a tech writer - Kevin Meltzer\n";
RegDwight
+4  A: 

Short but sweet:

grep needle haystack
DisgruntledGoat
PHP docs use this terminology in a lot of their search in functions http://php.net/manual/en/function.in-array.php
alex
A: 

From the Fifth Element:

if (!kills(you)) {
    you.stronger();
}
Jack Leow
+1  A: 

Try this:

float or_sink = 0xB000;
int eresting_value = 1;
volatile bool sheet = TRUE;
SwDevMan81
A: 

My definition of everything: SELECT * FROM *

luvieere
+1  A: 
$TheQuestion = (ToBe() || !ToBe());

Just saw this is based on the same quote as the highest rated pseudo-code example in this thread...

Douwe Maan
A: 

Might be something music relative.

function dance($year) {
    if($year == 1990) {
        $this->stop();
        $this->hammer_time();
    }
}
hellozimi
A: 
for(;$i<3;) {
     $u;
}

"I Love you forever" (although i is undefined...)

Cheesy as...but every time I see someone type "<3" regarding "love" I always say it in my head as "less than three".

Josh Stuart