Fun With Programming Languages

Tonight, a Facebook thread got a little out of control after I posted a status update that I was “mentally bankrupt.” It was a long day working on client work – a project that is just about done but past due.

After some commentary by Facebook friends, we got to writing little scripts that would take a random selection from a group of adjectives and adverbs and put similar phrases together randomly.

What came of this exercise was a fun little jaunt into a variety of programming languages.

PHP
[cc lang="php"] $adverbs = array(
'mentally',
'morally',
'emotionally',
'socially',
'psychologically'
);

$adjectives = array(
'devoid',
'bankrupt',
'empty',
'hollow',
'vacant',
'sleeping with fishes',
'taking a dirt nap',
'shallow'
);

echo $adverbs[array_rand( $adverbs )] . ' '
. $adjectives[array_rand( $adjectives )];
?>[/cc]
Ruby
[cc lang="ruby"]
adj = [ "mentally", "morally",
"emotionally", "socially",
"psychologically" ]

adv = [ "devoid","bankrupt",
"empty", "hollow","vacant",
"sleeping with fishes",
"taking a dirt nap","shallow" ]

print adj[rand(adj.length)] + ” ”
+ adv[rand(adv.length)] + “\n”
[/cc]

Python
[cc lang="python"]
import random

def popchoice(seq):
return seq.pop(random.randrange(len(seq)))

adj = [ 'mentally', 'morally',
'emotionally', 'socially',
'psychologically' ]

adv = [ 'devoid','bankrupt','empty',
'hollow','vacant','sleeping with fishes',
'taking a dirt nap','shallow' ]

print popchoice(adj) + ” ”
+ popchoice(adv)
[/cc]

SQL
[cc lang="sql"]CREATE TEMPORARY TABLE adjectives (
adjective VARCHAR (30) NOT NULL
);

CREATE TEMPORARY TABLE adverbs (
adverb VARCHAR (30) NOT NULL
);

INSERT INTO adjectives (adjective)
VALUES
(‘mentally’),
(‘morally’),
(‘emotionally’),
(‘socially’),
(‘psychologically’);

INSERT INTO adverbs (adverb)
VALUES
(‘devoid’),
(‘bankrupt’),
(‘empty’),
(‘hollow’),
(‘vacant’),
(‘sleeping with fishes’),
(‘taking a dirt nap’),
(‘shallow’);

SELECT CONCAT_WS(
‘ ‘,
( SELECT adjective FROM adjectives ORDER BY RAND() LIMIT 1 ),
( SELECT adverb FROM adverbs ORDER BY RAND() LIMIT 1 ) )
as RandomStuff;
[/cc]