Let's consider how well Java meets this requirement by looking at the traditional first program: one that prints "Hello, World!" on the console. If we were dogmatic about exploiting Java's object-oriented nature, then such a program would have to look something like this:
public class Greeting { public void display() { System.out.println("Hello, World!"); } public static void main(String[] args) { greeting = new Greeting(); greeting.display(); } }A complete novice who is already nervous about the challenge of learning programming will probably regard this code with dismay and wonder just how much more difficult writing a non-trivial program is likely to be.
One way of minimising the complexity is to develop and execute code within an environment that hides much of the 'scaffolding' - BlueJ, for example. Alternatively, we could simplify things by adopting a largely procedural style:
public class Greeting { public static void main(String[] args) { System.out.println("Hello, World!"); } }But even this simpler code is replete with potentially confusing details. The novice will no doubt be able to identify the single line of code that causes a message to be printed on the console, but will wonder
- Why the line appears inside something called main
- What purpose is served by String[] args
- What the words public, static and void signify
- What a class is, and why the code has to be enclosed within it
Python suffers from no such problems, offering us what is surely the simplest version possible of the traditional first program:
print 'Hello, World!'(The Python 3 version includes parentheses, of course, because print is a built-in function rather than a statement in Python 3.)
A quibble: You say python's hello world is "surely the simplest version possible of the traditional first program". A simpler version is found in languages that allow you to do away with the quotes, such as bash:
ReplyDeleteecho Hello, World!
In some languages (php) you could even do:
Hello World!
and have that print itself out.
I guess so, cbr - although I would argue that omitting the quotes reduces the clarity. A pathological example would be:
ReplyDeleteecho echo beach is a song by martha & the muffins