Begin Coding Without “Hello World”

Lucas F. Lu
4 min readFeb 12, 2020

--

Why do we see examples of “Hello World”?

Almost always, the very first thing you learn from a tutorial is how to display “Hello World”.

But why?

A guide for beginners of any background to start writing codes

Like we learned previously, any line of codes within a program can be considered a line of instructions. We are instructing the computer to do what we want.

In the case of a “Hello World” example, we are simply instructing the computer to display something for us. Thus, the examples we saw from many online courses were really meant to show you this one concept, that the command “print”, “echo” or “printf” from various languages are just commands used to display something.

Note: We will be using PHP as our learning language for the remaining of the coding concept studies, since it is relatively easy to learn and still preserves the structure and delimiters. You can use an online simulator to test your program along the tutorial. One can be found at http://phptester.net/.

Great! What is this “PHP” thing?

A short description of PHP

PHP is primarily used for back-end web development. A scripting language that is easy to learn and flexible to use.

It needs an interpreter to be installed on your computer and you can find it at https://www.php.net/downloads.

When you run a PHP program, open a command line console (That black window people usually call “DOS” or “console” in windows), navigate to the folder where the target PHP file is stored and execute the program like this.

C:\Documents\Learning\php MyProgram.php

Finally, let’s build a program!

Instead of having a program that says “hello” to the world, how about we write a program that greets us personally? Let’s call our butler program “Garfield”.

On your computer, let’s create a file named “Garfield.php” and store it at “/Documents/myprograms/” folder. Within the program (the file), we write the following.

<?php    echo 'Good morning master Lucas.';?>

Note: You may use any text editors to write a program. But I would recommend the following two editors since they are my favorites.
- Visual Studio Code: The most popular editor at the time of this writing.
- Sublime Text: Simple, fast and reliable. Can be downloaded at

Save the changes to the file and we can now run this program with command

C:\Documents\myprograms\php Garfield.php

"Good morning master Lucas." will be displayed as the result. Of course, you are free to change the world “Lucas” to your name and making this more personal.

See, it was pretty simple to program and instruct a computer to perform certain things for you, right?

Code Explanation

“<?php” at the very top and “?>” at the very end of the document is mandatory within a PHP file to mark the beginning and ending of a PHP program.

When a computer reads this file, it needs to know the location to start treating the sentences as PHP instructions. So, be sure to put these in a file when writing a PHP program.

“echo” is an instruction (or command) in PHP that tells the computer to display what’s written afterwards.

It is important to know that computers need a way to differentiate commands or instructions from information or data.

Commands are used to instruct the computer to perform a certain action, while data is what we have provided to the computer to perform the action with.

In our example above, we instruct the computer to perform a display action with “echo ”command. We also tell the computer to use “Good morning master Lucas.” as the contents(or data if you will) of the display action.

Note: To differentiate commands from data, we need to wrap our data with quotes (‘). That’s why you see ‘Good morning master Lucas.’ is wrapped inside (‘).

And of course, we need to use a delimiter(a symbol or special character) to inform the computer where each instruction ends. In our case of PHP, we use semicolon (;).

A delimiter will mark the end of an instruction and when a computer reads the file line by line, it will know the place to stop and perform a new instruction.

That wasn’t so bad for your first programming experience, right? Just remember,

  • Each line of code is simply instructions for the computer to perform a certain task.
  • The end of each instruction is marked by a delimiter (;) in PHP (or most other languages).
  • Data is wrapped inside of quotes (‘) to differentiate itself from instructions.

New articles are added every Wednesday. Please stay tuned.

--

--

Lucas F. Lu

Laravel Expert, AI enthusiasts. Recently fell in love with helping people rebuild their lives by learning how to program.