My friend disagrees with me when I say that programming can be just as creative as writing. She questions the fact that code is poetry.
After much argument, she sent the following poem, and challenged me to write a program just like it. I went one better and wrote a Java implementation of the original.
I must admit, the original poem is a lot shorter than my implementation, but the Java version has the advantage of scalability. You can add as many items as you like to my program, rather than restricting yourself to the (rather paltry) eight the poet allows. (I note, for example, he included “Magic City” but neglected to check for a normal City, or even a village or town.)
I would also add that it would take a good 10 or 15 seconds to read the poem, whereas my implementation will run in in under a second. Score one to science, I think.
The Poem
The Door Go and open the door. Maybe outside there's A tree, or a wood, A garden, Or a magic city. Go and open the door. Maybe a dog's rummaging. Maybe you'll see a face, Or an eye, Or the picture Of a picture. Go and open the door. If there's a fog It will clear. Go and open the door. even if there's only the darkness ticking, even if there's only the hollow wind, even if nothing is there, go and open the door. At least There'll be A draught. By Miroslav Holub Translated by Ian Milner and George Theiner
Java Implementation
import org.sensibility; import com.darkness; import com.wind; import com.external.door; class doorChecker { Door door = new Door(); String [] itemsVerse1 = {"tree","wood","garden","magic city"}; String [] itemsVerse2 = {"dog rummaging","face","eye","picture of picture"}; boolean isDarknessTicking = false; boolean isWindHollow = false; doorChecker() { Darkness darkness = new Darkness(); Wind wind = new Wind(); isDarknessTicking = darkness.isTicking(); isWindHollow = wind.isHollow(); for(String s:itemsVerse1) { if(openDoor(s)) { System.out.println(s + "exists outside the door"); } } for(String s:itemsVerse2) { if(openDoor(s)) { System.out.println(s + "exists outside the door"); } System.out.println("Also, the fog will clear"); } if(isDarknessTicking || isWindHollow || door.getOutside().isNull()) { System.out.println("There is a draught"); } } public boolean openDoor(String item) { boolean itemExists = false; if(item.equalsIgnoreCase(door.getOutside())) { itemExists= true; } return itemExists; } public static void main(String args[]) { new doorChecker(); } }