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 [1]:
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:
foreach(bill) paywith(skill)
Have any to share?
What would you call these if you gave them a name?
Always deserves a mention:
2 * b || ! (2 * b)
0x2b
= 43, but 0x2b | ~0x2b
= -1 - hasen j
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;
};
byte me;
. - Georg Fritzsche
Code to display the name of everyone's favorite web site ... eventually:
void x(void) { x(); }
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);
}
puts()
- bobobobo
SELECT * FROM businesses WHERE business LIKE 'show_business%';
0 ROWS RETURNED
while(whatWeNeed != education())
{
wall->add(bricks++);
}
wall->add(brick);
- DisgruntledGoat
bikini.ToString();
ahem.
void CreateLimerick() {
#define poemKind terriblySlick
if (lines == 5
&& rhymesWith("live") {
DoLaugh(); Perform(new Trick()); }}
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();
}
}
public double penetration;
pornoverflow.com
's classes. - Starx
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 {};
This one was in Futurama
10 HOME
20 SWEET
30 GOTO 10
public class Egg
{
int hashCode()
{
...
}
}
From a t-shirt
i > u
Here's a bible one:
class the_earth
{
...
};
class the_meek : public the_earth
{
...
};
Oldie:
while ( !(succeed = try()) );
while (!succeed) { try(); }
? - Shaharyar
FORTH LOVE? IF HONK THEN
10 LATHER
20 RINSE
30 GOTO 10
if(youreHappyAndYouKnowIt) {
clapYourHands();
}
while (looks($girl) < "hot"){
beer.next();
}
cd pub
more beer
A bit more cryptic:
mkfifo('dream')
def Life()
while heartbeats
wakeup
breakfast
if weekday
work
lunch
work
else
play
lunch
play
supper
bath
while (!sex)
sleep
exit
pthread_mutex_lock(&coop_mutex);
pthread_cond_wait(&hatched_cv, &coop_mutex);
ct = count_chickens();
pthread_mutex_unlock(&coop_mutex);
FK UNICODE
Oh, pseudocode phrases? No...
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
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;
}
The only constant in our world is change:
public class OurWorld {
public const int change;
}
Short but sweet:
grep needle haystack
Another from Futurama:
10 SIN
20 GOTO HELL
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"
Perl Poetry [1]
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";
[1] http://www.perlmonks.org/?node=Suessified%20Perl%20Poem#!/bin/bash
# Apologies to John, Paul, George, and Ringo.
while true; do
echo "Strawberry Fields"
done
Or:
yes "*****" "=====" # Where's my sousaphone?
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!
Bible reference:
first = last;
last = first;
probably lame .. but
class Person
{
//....
boolean exists()
{
return this.thinks();
}
boolean thinks()
{
return this.brain != null;
}
}
reaction = screwed? flight() : fight();
Or:
function respond(situation) {
if (situation == screwed)
flight();
else
fight();
}
if ($eggs->haveHatched) {
$chickens = count($eggs->get());
}
select * from users where clue > 0 0 rows returned
sudo find / -name "*egg*" > basket
HermanD what about
if what.goes_around == what.comes_around
do.good
end
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();
}
}
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 [1]
[1] http://gen-e-sis.com/2009/03/elvis-presley-heartbreak-hotel-java-snippets/public class Person
{
public DateTime LearningCurve { get; set; }
public DateTime LifeExpectancy { get; set; }
public bool Stoopid
{
get
{
return this.LearningCurve > this.LifeExpectancy;
}
}
}
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".
class Vader
{
// ...
};
class Luke : public Vader
{
// ...
};
It was when Lucas accidentally enabled RTTI that it happened...
Yoda found one of the legitimate uses of goto
in C
if(fear)
goto Anger;
Anger:
goto Hate;
Hate:
goto Suffering;
Suffering:
; // Dark side.
In C you could do:
float Titanic = FALSE;
from VBA (this was on a website a but can't remember which one)
Dim Everything as Object
If Everything Is Nothing Then
MsgBox "This is a paradox of the universe."
End If
Sub and Function Names
Sub MachineGun ()
Sub Stitute ()
Sub Marine ()
Sub Human ()
Function Ality ()
Declaration Statements
Dim Lotus(1 To 3)
Dim Wit, TheLights
Public Exposure
Dim Julian As Boolean, King As String, Kong As Long
Dim BaseballCards As New Collection
Dim Mouthful as Byte
Dim Dewey As Decimal
Dim DatingService As Single
Public Nudity As Graphic
Dim Trouble As Double
Static Cling, Electricity
Dim Rope as String
Dim Bones, Bones, DryBones
ReDim HisRights
VBA Statements
On Error GoTo Hell
If IsMissing(InAction) Then GoTo MilkCarton
If IsNull(Warranty) And Void Then BuyaNew1
Cocktail = Abs(Vodka)
SendKeys "Because I'm locked out"
Synergy = Whole > Application.Sum(ItsParts)
Brightness = Array("of", "light")
Yield = Right(OfWay, 2)
Perfect10 = DateValue(Tiffany)
If(IsEmpty(Head)) Then GoTo School
WoodenHouse = Log(Cabin)
Kill("SomeTime")Heart = Val(Entine)
RaiseEvent Hell
Brittney = Space(Cadet)
Seek(AndYeShallFind)
Lonely = Left(Out, 1)
OnWithThe.ShowDeadActor = Dir("WoodKirby")
Call MeACab(Hansom)
Application.Run "Away"
GoodIdea.Copy
Wallpaper.Paste
Range("HomeOnThe").Activate
Lubricant = Shell("\Oil")
Mismatch = Round(Sqr(Peg), 0)
Actor = Val(Kilmer)
Map = Rand(McNally)
GoTo Jail
Do Walk Backwards
Loop Until Christmas
From the Fifth Element:
if (!kills(you)) {
you.stronger();
}
Try this:
float or_sink = 0xB000;
int eresting_value = 1;
volatile bool sheet = TRUE;
My definition of everything: SELECT * FROM *
$TheQuestion = (ToBe() || !ToBe());
Just saw this is based on the same quote as the highest rated pseudo-code example in this thread...
In commenting on an answer to this question [1], which asks about converting strings of hex digits to decimal, I ended by suggesting:
[1] http://stackoverflow.com/questions/788026/hex-to-decimal-conversion-kr-exerciseIt's a matter of taste: 6 of one,
C>>1
of another.
SELECT * FROM tblMeals WHERE type = 'lunch' AND cost = 0;
0 ROWS RETURNED
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
{
...
}
void test(char *str, int max) throw(...)
{
if (_stricmp(str, "Bathwater")
{
strcat_s(str, max, " Baby");
throw(str);
}
}
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;
}
}
C#:
while((bouncing = paycheck())) new Action(() => {})();
JavaScript:
while((bouncing = paycheck())) (function() {})();
oh->shit(pointer);
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();
}
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;
Jack = null
:) - alex
if what.goes_around?
what.comes_around
end
Whenever using a static variable in a function in PHP, I can never get past the temptation just to write:
static $x;
[explanation] [1]
It makes the code really hard to understand, but it's totally worth it.
[1] http://en.wikipedia.org/wiki/Static%5FXMight be something music relative.
function dance($year) {
if($year == 1990) {
$this->stop();
$this->hammer_time();
}
}
[england.sell(p) for p in pounds]
or:
map(england.sell, pounds)
I saw this on a coffee cup once
Cup<T>
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
!Y
... :) - Øystein