Most people do not associate poetry with computer programming. Yet on a fundamental level, poetry and programming actually have many similarities...
- Brevity. The best poems and computer codes are concise and use the fewest words or symbols. The best poems are those that have many interpretations contained within a short arrangement of words. Similarly, the best programs are the efficient ones that can complete a task with the fewest lines possible.
- Word choice. Every symbol and word has a purpose in both poems and computer code. Every word in a poem has a meaning, and the author chose every single word for an important reason. In the same way, every symbol in a computer program has a reason for being there. No programmer leaves extra words or characters cluttering up the code.
- Hard to understand by skimming. The meaning of both a poem and a computer code is not clear after just a quick glance. You cannot understand the full meaning and all the nuances of a poem by just skimming it in a few minutes. You have to sit down, analyze it, and think about each line's purpose. The same is true of a computer code. If one programmer tries reading someone else’s uncommented code, they would find it almost impossible to make sense of without careful reading and analysis.
- Repetition. In many poems, repetition is key. Whether it is repeating the same first line in a verse, repeating a word or phrase two or three times for emphasis, or just repeating the same theme throughout the poem. In computer programming, the fundamental basis of almost every code is loops, which allow programmers to repeat a section of the code as many times as the programmer wants. Both poems and code would lose meaning without constant repetition.
Below are some simple programs that can be read in haiku form. The first represents the basic syntax of a for loop in Java. The second is a basic program in c++ that outputs the text “Hello world.” The third is a similar basic text-output program in Java.
for( int x = 10; x > 2; x--)
For int x is 10
x strictly greater than 2
x decrease by 1
-------------------------------------------------------------------------------------------
#include <iostream>
int main()
{
cout << "Hello World!";
}
Include iostream
Int main no parameters
C-out hello world
-------------------------------------------------------------------------------------------
public class program
{
public static void main(String[] args)
{
public static void main(String[] args)
{
System.out.print(“Hi!”)
}
}
Public class program
public static void main args
System out print Hi!