Hello Fun-A-Day 7!

For this year’s Philadelphia Fun-A-Day project I decided to write “Hello World” programs. “Hello World” is a traditional programming tradition where a programmer encountering a new language writes a trivial program which displays the phrase “Hello World”.

This introduces the programmer to the basic syntax of the language and demonstrates that their development environment is set up properly to work with that language.

Much of our current environment runs on software, which is generally invisible to us, except when a failure impacts our lives. However, software generally starts as human-readable written text, albeit in a highly defined form using specific vocabulary.

This project attempts to make software visible, in at least a trivial way. The words and structure may differ between languages, but each program is a series of instructions to achieve some end – here to issue a friendly “Hello Fun-A-Day 7!”. Hopefully this can serve to demystify software to some degree, and remind us that software, at some point, has been written by a person.

The programs here demonstrate a Fun-A-Day variant on Hello World in several languages. I made an effort to explore historical and modern languages, compiled and interpreted languages, console and graphical programs, but avoided esoteric languages which are often difficult to understand by design.

The Association for Computing Machinery has a collection of Hello World programs:
http://www2.latech.edu/~acm/HelloWorld.html

(Note: I’m generally referring to high-level languages, not considering assembly or binary code. If you’ve read this far, and understand what I mean, then you’ll forgive this simplification made for clarity of purpose)


Language: C

#include <stdio.h>

int main(int argc, char* argv)
{
    printf("hello fun-a-day 7! \n");
    return 0;
}

Language: JavaScript

// Use Rhino intrepreter to run in a shell
// http://www.mozilla.org/rhino/download.html

function sayHello() {
    print('Hello Fun-A-Day 7!');
};

sayHello();

Language: Arduino / Wiring (C++)


#include "WProgram.h"

// prototypes
void blink(int n, int d);

#define unit 100
void dot(int n);
void dash(int n);
void gap();
void pause();
void space();

// variables
int ledPin = 13;                      // LED connected to digital pin 13

void setup(){
    Serial.begin(9600);               // opens serial port, sets data rate to 9600 bps

    pinMode(ledPin, OUTPUT);          // sets the digital pin as output
    
    // print a friendly message to the serial console:
    Serial.println("-------------------");
    Serial.println(" Hello Fun-A-Day 7");
    Serial.println("-------------------");
}

void loop(){
    // display "Hello Fun A Day 7" in morse code:
    dot(4); pause();                  // H
    dot(1); pause();                  // E
    dot(1); dash(1); dot(2); pause(); // L
    dot(1); dash(1); dot(2); pause(); // L
    dash(3);                          // O
    space();
    dot(2); dash(1); dot(1); pause(); // F
    dot(2); dash(1); pause();         // U
    dash(1); dot(1);                  // N
    space();
    dot(1); dash(1);                  // A
    space();
    dash(1); dot(2); pause();         // D
    dot(1); dash(1); pause();         // A
    dash(1); dot(1); dash(2);         // Y
    space();
    dash(2); dot(3);                  // 7
    space();
    dot(3); dash(1); dot(1); dash(1); // end-of-message
    space();space();space();
    space();space();space();
}

void blink(int n, int d){
  for (int i=0;i<n;i++)
  {
    digitalWrite(ledPin, HIGH);
    delay(d);
    digitalWrite(ledPin, LOW);
    delay(unit);
  }
}

// timing as specified by International Morse Code
void dot(int n) {
    blink(n, unit);
}

void dash(int n) {
    blink(n,3*unit);
}

void gap() {
    delay(unit);
}

void pause() {
    delay(3*unit);
}

void space() {
    delay(7*unit);
}

int main(void)
{
    init();
    setup();
    for (;;)
        loop();
    return 0;
}

Language: Perl

# Fun-A-Day 7
# Perl
#

sub sayHello {
    printf("Hello Fun-A-Day 7!\n");
}

sayHello;

Language: Cobol

 IDENTIFICATION DIVISION.
      PROGRAM-ID. HELLO-WORLD.
      PROCEDURE DIVISION.
          DISPLAY 'Hello Fun-A-Day 7!'.
          STOP RUN.

Language: BASIC

10 print "Hello Fun-A-Day 7!"
20 goto 10

Language: C++

#include <iostream>
using namespace std;

class FunADay {
    public:
        FunADay () {};
        void sayHello() {
            cout << "Hello Fun-A-Day 7!" << endl;
        };
};

   
int main()
{
    FunADay *fad = new FunADay();
    fad->sayHello();
    delete fad;

    return 0;
}

Language: bash

#!/bin/bash
#
# Fun-A-Day 7
# 

echo 'Hello Fun-A-Day 7!'

Language: Processing

// Fun-A-Day 7
// Processing example

void setup()
{
  // initialize the canvas and set some paramaters
  size(100,100);
  smooth();
  noStroke();
}

void draw()
{
  // partially "erase" the previous screen
  // by drawing a semi-transparent, black rectangle on top
  fill(0,55);
  rect(0,0,width,height);

  // draw another ellipse
  fill(204);
  float x = random(width); float y = random(height);
  ellipseMode(CENTER);
  ellipse(x,y,20,20);
  
  // be friendly
  sayHello();
}

void sayHello()
{
  println("Hello Fun-A-Day 7!");
}

Language: Python

# Fun-A-Day 7
# python example
#
# be sure to mind your indentation!

def sayHello():
    print "Hello Fun-A-Day 7!"

sayHello()

Language: Ruby

class FunADay
    def sayHello()
        print "Hello Fun-A-Day 7!"
        print "\n"
    end
end

fad = FunADay.new
fad.sayHello

Language: Java

package net.robertcarlsen;

public class FunADay {
	public static void sayHello()
	{
		System.out.println("Hello Fun-A-Day 7!");
	}
	
	public static void main(String[] args) {
		sayHello();
	}

}

Language: C#

/* Fun-A-Day 7
 *
 * C#
 */

class HelloFunADay
{ 
  static void Main () {  
     System.Console.Write("Hello Fun-A-Day 7!\n");
  } 
}

Language: sed (bash)

#!/bin/bash

# This is just a simple example of using sed
# for find and replace.
# echo will just spit out the quoted text
# '|' is the pipe operator, and sends the output from
# echo to the next program, in this case sed
# sed is using the 's'earch operation
# 's/find stuff here/replace it here/'
# the parentheses match stuff that we can refer to later as \1
# .* means match any character, zero or more repeated times
# but it won't include the literal phrase " World" because that's
# specifically written in the match expression.

echo "Hello World" | sed 's/\(.*\) World/\1 Fun-A-Day 7!/'

Language: Lisp

;;; Fun-A-Day 7
;;; Robert Carlsen
;;;
;;; Lisp version

(defun sayhello ()
  "the basic hello" ; make sure to be friendly
  (format t "Hello Fun-A-Day 7!")
)

Language: php

<?php
    printf("Hello Fun-A-Day 7! \n");
?>

Language: Go

package main

import "fmt"

func main() {
	fmt.Println("Hello, Fun-A-Day 7!")
}

Language: Objective-C / Cocoa

(There is far too much boilerplate code and dependent project files to paste here, but this is the bit which drives some simple interaction – displaying an alert if you tap the badger image several times)

@interface Fun_a_Day7ViewController : UIViewController {
}

@property(nonatomic,retain)IBOutlet UILabel *badgerLabel;
- (IBAction)badger:(id)sender;
@end

@implementation Fun_a_Day7ViewController
@synthesize badgerLabel;

static int count = 0;

- (IBAction)badger:(id)sender;
{
    self.badgerLabel.hidden = !self.badgerLabel.hidden;
    
    if(++count > 4) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Badger"
                                                        message:@"No, seriously...quit badgering me!"
                                                       delegate:nil
                                              cancelButtonTitle:@"Stop it"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        count = 1;
    }
}
@end

Language: R

# Fun-a-day 7
# R language for statistical computing
#
fad_peeps <- c(43,64,72,84,74,68)
years <- seq(2010-5,2010)
data.frame(years,fad_peeps) -> fadData
fadData
#  years fad_peeps
#1  2005        43
#2  2006        64
#3  2007        72
#4  2008        84
#5  2009        74
#6  2010        68
require(ggplot2)
qplot(years,fad_peeps,fadData) + geom_smooth()


Posted

in

by

Comments

Leave a Reply