我们作为一名程序员,职业生涯中至少完成了一个“Hello, World!“程序。当我们学习一门新的语言时,“Hello, World!“通常是我们所写的第一个程序。程序员一般也都会使用多门语言,甚至有多数人都会使用十几种语言。甚至有一个名为TTHW的指标来衡量一个程序员接触一门新的编程语言时,成功写出“Hello, World!“并运行所需要的时间。然而,如果我问你,你会用多少种编程语言写“Hello, World!“?你的答案会是多少?
为了刷新你的记忆,我会带你经历一段计算机编程领域的时空之旅。为此,我将向你展示50种不同的编程语言的 “Hello, World!“程序的写法。你也会了解计算机语言随着时间的推进发生了哪些变化。
NO.1. 汇编语言 - 1949
bdos equ 0005H ; BDOS entry point
start: mvi c,9 ; BDOS function: output string
lxi d,msg$ ; address of msg
call bdos
ret ; return to CCP
msg$: db 'Hello, world!$'
end start
NO.2. Fortran - 1957
PROGRAM Hello
WRITE (*,*) 'Hello, World!'
STOP
END
NO.3. Lisp - 1958
(write-line "Hello, World!")
NO.4. Cobol - 1959
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY "Hello, World!"
STOP RUN.
NO.5. BASIC - 1964
PRINT "Hello, World!"
END
NO.6. Logo - 1968
print [Hello World !]
NO.7. B - 1969
main(
{
putstr("Hello world!*n");
return(0);
}
NO.8. Pascal - 1970
begin
writeln('Hello, World!')
end.
NO.9. Forth - 1970
: HELLO ( -- ) ." Hello, World!" CR ;
HELLO
NO.10. C - 1972
#include <stdio.h>
int main(void) {
printf("Hello, World!
");
return 0;
}
NO.11. Smalltalk - 1972
Transcript show: 'Hello, world!'; cr.
NO.12. Prolog - 1972
:- write('Hello, World!'),nl.
NO.13. ML - 1973
print "Hello, World! ";
NO.14. Scheme - 1975
(display "Hello, World!") (newline)
NO.15. SQL - 1978
CREATE TABLE message (text char(15));
INSERT INTO message (text) VALUES ('Hello, World!');
SELECT text FROM message;
DROP TABLE message;
NO.16. C++ - 1980
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
NO.17. Ada - 1983
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line ("Hello, World!");
end Hello;
NO.18. Common Lisp - 1984
(princ "Hello, World!")
NO.19. MATLAB - 1984
disp('Hello, World!')
NO.20. Eiffel - 1985
class
HELLO_WORLD
create
make
feature
make
do
print ("Hello, world!%N")
end
end
NO.21. Objective-C - 1986
#import <Foundation/Foundation.h>
int main() {
@autoreleasepool {
NSLog(@"Hello, World!");
}
}
NO.22. Erlang - 1986
io:format("Hello world!~n").
NO.23. Perl - 1987
print "Hello, World! ";
NO.24. Caml - 1987
print_string "Hello, World! ";;
NO.25. Tcl - 1988
puts "Hello, World!"
NO.26. Haskell - 1990
main = putStrLn "Hello, World!"
NO.27. Python - 1991
print("Hello, World!")
NO.28. Visual Basic - 1991
Public Sub Main()
Debug.Print "Hello, World!"
End Sub
NO.29. Lua - 1993
print("Hello, World!")
NO.30. Ruby - 1995
puts 'Hello, World!'
NO.31. Java - 1995
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
NO.32. JavaScript - 1995
document.write('Hello, World!');
NO.33. PHP - 1995
<? echo "Hello, World!" ?>
NO.34. Rebol - 1997
print "Hello, World!"
NO.35. ActionScript — 1998
package {
public class HelloWorld {
public function HelloWorld() {
trace("Hello World !");
}
}
}
NO.36. D - 1999
import std.stdio;
void main () {
writefln("Hello, World!");
}
NO.37. C# - 2000
using System;
internal static class HelloWorld {
private static void Main() {
Console.WriteLine("Hello, World!");
}
}
NO.38. Groovy - 2003
println "Hello, World!"
NO.39. Scala - 2003
object HelloWorld extends App {
println("Hello, World!")
}
NO.40. F# - 2005
printfn "Hello, World!"
NO.41. Windows PowerShell - 2006
echo "Hello, World!"
NO.42. Clojure - 2007
(println "Hello, World!")
NO.43. Go - 2009
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
NO.44. Rust - 2010
fn main() {
println("Hello, World!");
}
NO.45. Dart - 2011
main() {
print('Hello, World!');
}
NO.46. Kotlin — 2011
fun main(args: Array<String>) {
println("Hello, World!")
}
NO.47. Ceylon - 2011
void hello() {
print("Hello, World!");
}
NO.48. TypeScript - 2012
console.log("Hello, World!");
NO.49. Julia - 2012
println("Hello, World!")
NO.50. Swift - 2014
print("Hello, World!")
总结一下,50种语言的发展来看,大多数语言的设计思想都是互相借鉴的。语言的发展也是逐渐演进的,但不是越强大的语言就越流行。一门语言想要变得流行也是需要一定的机遇的(例如Python),或者是需要有个优质的大腿(例如Java和Dart)。(如果以上代码有问题或者有错的请大家评论区帮忙纠正)