Contrary to the popular code-golf challenges which demonstrate the genius of many regulars here, I'd like to see that genius illustrated in an antithetical fashion.
The challenge is to successfully perform "Hello World" with special focus on over-complicating matters. Not verbosity, not obscurity, just pure sloppiness/over-complication.
Think of The Daily WTF as inspiration.
function mb2($o){return (int)($o*2);}
$alphabet = str_split("abcdefghijklmnopqrstuvwxyz");
$alphabet[] = " ";
$output = "";
for ($i = 0; $i <= 10; $i++)
switch (mb2($i*.5)) {
case 0: $output = $output . $alphabet[07]; break;
case 1: $output = $output . $alphabet[04]; break;
case 2: $output = $output . $alphabet[11]; break;
case 3: $output = $output . $alphabet[11]; break;
case 4: $output = $output . $alphabet[14]; break;
case 5: $output = $output . array_pop($alphabet); break;
case 6: $output = $output . $alphabet[22]; break;
case 7: $output = $output . $alphabet[14]; break;
case 8: $output = $output . $alphabet[17]; break;
case 9: $output = $output . $alphabet[11]; break;
case 10: $output = $output . $alphabet[03]; break;
}
print $output; // hello world
You asked for it. Python:
# Copyright (c) 1999 - 2010
# Large Company, Inc. ("THE COMPANY")
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COMPANY AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
"""This program outputs an enthusiastic "Hello World" in english.
"""
# FIXME: Where are the unit tests for this? QA called and says we
# can't ship this without tests. Also, while writing documentation
# may be boring, you can't expect everyone to understand all this!
# Go ahead and write some docstrings! -- O.D. 2004/7/22
class Expression(object):
def get_value(self, **kwargs):
"""get_value returns the value of this Expression.
Any keyword arguments that the method receives should
be passed on to the get_value methods of possibly called
subexpressions, even if this method does not handle
them.
This method must be reimplemented by the subclass."""
raise NotImplementedError
class Word(Expression):
def __init__(self, value):
self.value = value
def get_value(self, **kwargs):
return self.value
class Sentence(Expression):
def __init__(self, expressions, punctuation = "."):
self.expressions = list(expressions)
self.punctuation = punctuation
def get_value(self, separator = " ", **kwargs):
mainpart = separator.join(
subexpression.get_value(separator = separator, **kwargs)
for subexpression in self.expressions
)
if len(mainpart) > 0:
capitalized = mainpart[0].upper() + mainpart[1:]
else:
capitalized = ""
# FIXME: We're hardcoding "" here. Should we be prepared for
# languages that require a separator before the punctuation mark?
# NB: A workaround for now would be adding an empty word
return "".join((capitalized, self.punctuation))
class Hello(Word):
# FIXME: We should be prepared for languages where "hello" is
# represented by more than one word.
hello_by_language = {"en": "hello", "de": "hallo"}
def __init__(self, language = "en"):
super(Hello, self).__init__(self.hello_by_language[language])
class World(Word):
# FIXME: We should be prepared for languages where "world" is
# represented by more than one word.
world_by_language = {"en": "world", "de": "Welt"}
def __init__(self, language = "en"):
super(World, self).__init__(self.world_by_language[language])
class HelloWorld(Sentence):
def __init__(self, punctuation, language):
hello = Hello(language)
world = World(language)
super(HelloWorld, self).__init__([hello, world], punctuation)
class EnthusiasticHelloWorld(HelloWorld):
def __init__(self, language):
# FIXME: We should be prepared for languages where enthusiasm
# is not expressed with an exclamation mark.
super(EnthusiasticHelloWorld, self).__init__("!", language)
def main():
english_enthusiastic_hello_world = EnthusiasticHelloWorld("en")
print english_enthusiastic_hello_world.get_value()
if __name__ == "__main__":
main()