MARCH 26, 2012
'Hello, world': Programming languages quizName that language: 20 'Hello, world' programs to test your polyglot programming mettleBy Neil McAllister|Print|26 Comments
You got 17 of 20 correct.
Your score: 85%
Your responsesQuestion 1:/* Program: helloWorld */#include<stdio.h>int main(void) {
printf("Hello, world!\n");
return 0;
}
Correct Answer: C
Your Answer: C
The godfather of modern imperative language syntax, you can recognize C by its header files (with the *.h extension) and its slash-and-asterisk comment delimiters.
Question 2:// Program: helloWorldfunction helloWorld() {
document.write("Hello, world!");
}
Correct Answer: JavaScript
Your Answer: JavaScript
The Web's scripting language still resembles C and its cousins, but its syntax is a little more verbose. The I/O based on the document object is a dead giveaway.
Question 3:# Program: helloWorlddefhelloWorld():
print "Hello, world!"
return
Correct Answer: Python
Your Answer: Python
Compared to the other popular scripting languages, Python does away with C-like syntax, with its braces and other punctuation marks, in favor of natural-language keywords and code blocks based on whitespace indentation.
Question 4:// Program: helloWorldclass helloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Correct Answer: Java
Your Answer: Java
Java looks a lot like C and C++, but it's more strictly object-oriented and uses a different syntax for classes, methods, and types.
Question 5:# Program: helloWorldsubhelloWorld {
print"Hello, world!\n";
}
Correct Answer: Perl
Your Answer: Perl
You can tell it's a scripting language because it uses the hash symbol (#) to denote comments. Unlike its competitors, however, the concepts of functions, methods, and subroutines are interchangeable in Perl, and all are defined using the keyword sub.
Question 6:// Program: helloWorld#include<iostream>usingnamespace std;
int main()
{
cout << "Hello, World!" << endl;
return0;
}
Correct Answer: C++
Your Answer: C++
The object-oriented successor to C looks a lot like its older sibling, but C++ is easy to spot by its simplified, single-line comments and its stream-based console I/O.
Question 7:# Program: helloWorldclass HelloWorld
defgreet
puts "Hello, world!"
endend
Correct Answer: Ruby
Your Answer: Ruby
Ruby's class and method definition syntax resembles that of Python, but unlike that language, definitions in Ruby must be closed with the end keyword.
Question 8:;; Program: helloWorld
(write-line"Hello, world!")
Correct Answer: Lisp
Your Answer: Lisp
You can always tell a Lisp program by its signature parentheses -- in real programs they are often nested many levels deep. This program's particular dialect is Common Lisp.
Question 9:' Program: helloWorld
Imports System
Public Module helloWorld
Sub Main()
Console.WriteLine ("Hello, world!")
End SubEnd Module
Correct Answer: Visual Basic
Your Answer: Visual Basic
Microsoft's often-criticized language bears little resemblance to the Basic that was popular in the 1980s, but you can still spot Visual Basic by its single-quote comment delimiters. The example uses the modern Visual Basic .Net syntax.
Question 10:// Program: helloWorldobject helloWorld {
def main(args: Array[String]) {
Console.println("Hello, world!");
}
}
Correct Answer: Scala
Your Answer: Scala
As a JVM language, Scala borrows much from Java, but its syntax is more compact and has a few twists of its own. Watch for the object and def keywords, which aren't used in Java.
Question 11:-- Program: helloWorldmodule helloWorld where
main = putStrLn "Hello, world!"
Correct Answer: Haskell
Your Answer: Cobol
As a functional language, Haskell's syntax differs from most of the languages in this quiz. It can be spotted by its unusual, compact syntax and its double-dash comment delimiter.
Question 12:{ Program: helloWorld }Program helloWorld(output);
Begin
WriteLn('Hello, world!')
End.
Correct Answer: Pascal
Your Answer: Pascal
One of the earlier structured programming languages, Pascal's syntax is verbose by today's standards, but it remains eminently readable. Unlike languages derived from C, curly brackets in Pascal indicate comments.
Question 13:// Program: helloWorld#import<Foundation/Foundation.h>int main(void) {
NSLog(@"Hello, world!\n");
return0;
}
Correct Answer: Objective-C
Your Answer: Objective-C
Because Objective-C is a superset of C, some Objective-C code looks almost identical to its older cousin. To tell which is which, watch for library classes and functions that start with "NS." That prefix is a holdover from the NeXTstep OS, which popularized Objective-C.
Question 14:; Program: helloWorldto helloWorld
print [Hello, world!]
end
Correct Answer: Logo
Your Answer: Logo
Logo is an old language with an unusual syntax. A teaching language, it is recognizable by its friendly, readable keywords. The to/end keyword pair, used to define a subroutine, should be a big hint.
Question 15: * Program: helloWorld
IDENTIFICATION DIVISION.
PROGRAM-ID. helloWorld.
PROCEDURE DIVISION.
DISPLAY'Hello, world!'.
STOPRUN.
Correct Answer: Cobol
Your Answer: Fortran
Once you've seen Cobol code, you can never forget it. The rigorous and unorthodox program structure, the mandatory indentation, and the liberal use of uppercase are all dead giveaways.
Question 16:* Program: helloWorld
PROGRAM helloWorld
PRINT'(A)', 'Hello, world!'
STOP
END
Correct Answer: Fortran
Your Answer: Basic
The granddaddy of programming languages, Fortran is the oldest language still in use today. As such, it resembles a lot of later languages, but the primitive syntax and unusual indentation make it readily identifiable.
Question 17:\ Program: helloWorld: helloWorld( -- )
." Hello, world!"cr ;
Correct Answer: Forth
Your Answer: Forth
Not only is Forth seldom used today, but its syntax remains unique in the history of programming languages. It can still be found in various embedded systems applications, including the Open Firmware found in some PowerPC, Sparc, and IBM Power systems.
Question 18:// Program: helloWorldusing System;
public class helloWorld
{
public static void Main()
{
Console.WriteLine("Hello, world!");
}
}
Correct Answer: C#
Your Answer: C#
Somewhere between C and Java lies C#. It retains much of the syntax of the former while adding many of the modern language features of the latter (and some of its own). If it looks like C but it's too slick to be C++, you just might be looking at .Net code.
Question 19:# Program: helloWorldfunction helloWorld() {
echo "Hello, world!\n";
}
Correct Answer: PHP
Your Answer: PHP
PHP uses the function keyword to begin function definitions like JavaScript, but it uses the hash character for comments and the echo keyword for text output, like a scripting language. If you can remember those things, you'll be able to recognize one of the more popular scripting languages on the Web.
Question 20:-- Program: helloWorldwith Text_IO;
use Text_IO;
procedure helloWorld is
begin
Put_Line("Hello, world!");
end helloWorld;
Correct Answer: Ada
Your Answer: Ada
Ada was designed by the U.S. Department of Defense as a reliable, efficient, and highly maintainable language for embedded systems applications. As such, it uses a strict, verbose syntax that owes a lot to Pascal and its related family of languages.√
Created
June 1, 2012 19:57
-
-
Save wilmoore/2854793 to your computer and use it in GitHub Desktop.
'Hello, world': Programming languages quiz
Score: 17/20
The languages I missed were:
- Haskell - I'm a little surprised I missed this but I'm not terribly worried about it
- Cobol - I am very surprised I missed this one. The PROGRAM-ID keyword is a dead giveaway. Even worse was the review comments at the end for this question read "Once you've seen Cobol code, you can never forget it". Well, crap...I guess I must be dense.
- Fortran - Not surprised at all. I don't recall every reviewing a Fortran program in my life.
Further observations:
- I'm surprised I got the Logo one right. I think I heard once that it was a very fluent language, so I happened to guess correctly.
- I almost messed up the PHP question because of the "#" comment. That is no longer supported but I had to think back to recall that it once was. I thought perhaps it was a trick question, but then I came to my senses and realized that this was not likely.
- Overall, I'm happy with the score given I didn't google nor did I use any notes. At the same time though I was expecting to get 18/20 --> oh well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The quiz is here: http://www.infoworld.com/d/application-development/hello-world-programming-languages-quiz-188874