Probably the best place to start learning a programming language is to find the features common to most languages. All human languages, for example, use nouns to describe objects and verbs to describe actions. Programming languages have similar common elements.
Let’s begin with one of the first tasks to learn in any new programming language: how to say, “Hello world!” We’ll use a website, repl.it, for these articles. Sign up for an account on repl.it and then create templates for each language to try out these examples, using the top left dropdown list.
To say “Hello world!” in any programming language requires learning how to send text to the computer screen. For example, here’s the line of code in Python:
and here’s how the Lua language says “Hello world!”:
print “Hello world”
Notice the difference between these two statements? Python uses parentheses to specify what to print on the computer screen while Lua uses a single space.
Having looked at these two similar examples above, can you begin to understand how this PHP code works?
<?php echo ‘<p>Hello World</p>’; ?>
PHP is a language typically used to create web pages and, as a result, it can include HTML-like paragraph (P) tags.
The word echo does the same thing as print. The <?php and ?> bits tell the web server the PHP code in between needs to be processed. And Hello World is to be displayed with HTML paragraph p tags before and after the phrase. Notice the PHP code uses single quotes instead of double quotes like Python and Lua.
When learning a new language, look to see how it prints text to discover both what is common among languages and what is unique to each language.