The History of ‘Hello, World!’ program

If you ever stumbled on any programming language tutorial regardless of your background, you certainly have already seen the “Hello, World!” written somewhere in the tutorials. It is considered a standard program for introducing a programming language to the students, wherein it simply prints “Hello, World!” to the console screen. It was first introduced in the introductory book on C: The C Programming Language which was written by Brian Kernighan and Dennis Ritchie. It was written as “hello, world” (without capital letters or exclamation mark) in the book. As the book was considered the best introduction to the programming language (C; which was hugely popular in the era), since then it is used as the first program to introduce the basic details of a programming language whenever a programming language is being taught to students.

The above program was written for the original version of C, which was translated from a program written in A Tutorial Introduction to the Language B By Kernighan for illustrating external variables:

In modern C, the program can be written as follows:

Due to the rise in popularity of the “Hello, World!” program, many modern programming languages incorporate the program in a similar fashion, but with the addition of the sophistication or the style of the language. For instance, in Python you can write the program in a single line:

Overall, the “Hello, World!” program introduced a topic of interest to the programming enthusiasts who like to figure “everything” out.

Compiled vs Interpreted Languages – Which ones are better?

Imagine a guy who just started programming. He searched the google for the articles on his “favorite” programming — the choice he made subconsciously, because his friends told him so. He found people talking about the programming, but he misunderstood things, including “compiled”, “interpreted”, etc., because his private language (the language he speaks) has different meanings of the words written there. To reduce the complexity in another newbie programmer, I am writing a short tutorial to highlight the difference between compiled and interpreted languages.

Compiled vs Interpreted Languages

Compiled languages are those in which the code is compiled line-by-line, which means that a compiler tries to understand every line of code in a program (including different files within a single project), and then translates it into the machine language of the architecture, which often happens after it’s translated to assembly instructions in .obj files – also known as object files, which are then linked together to create an executable file which a user can run on a target machine.

Interpreted languages, on the hand, are the ones that translates the code to the bytecode (i.e., the code format that is understood by the virtual machines) line-by-line on the fly, which means that it will start interpreting the code from the start and then execute the results through virtual machines, which could be seen through the console (in the form of logs or actual results). Virtual machines are provided by the vendors of the language to convert the bytecode to the machine language of the target machine.

Many programming languages are both interpreted and compiled, including Java, C#, Python, etc. These are called “bytecompiled” languages. In these languages, the code is compiled by the compiler to the bytecode of the language which can be run on the fly through the Virtual Machines (VMs) that are specifically developed for translating the code to platform dependent machine code on the fly. So, for instance, if you have different .class files which are basically Java bytecode that are independent of the architecture, then the JVM (which should be installed on the target machine) can convert the .class files in a real-time to the machine language of the computer architecture on which the program is running (i.e., x86, x64).

Which ones are faster?

As compiled languages need to only compile for once, the compiler make sure to add every kinds of optimization for the particular machine on which the program is compiling. This results in the faster execution of program on the average with the cost of slow compile-build-run process, as you would need to compile the whole program when you change a single-line of code, though modern compilers are getting better in recognizing the areas that need to be recompiled through carefully investigating the object files (.obj).
Interpreted languages, on the hand, require a two-step process: first the compiler compiles the whole program into the bytecode. Now, a compiler doesn’t know anything about the machine on which the program will run, so the bytecode which is produced by the compiler is platform neutral or independent. Once the bytecode is available, it is then run by the virtual machines installed on the target machine. At this stage, a virtual machine can optimize the bytecode as per the machine specifications, but the optimization isn’t very good as compared to the compiler in the compiled languages.

Which ones are better?

I don’t think there is a conclusive answer to the question. These days interpreted languages are quite in-demand due to the fact that virtual machines have been greatly optimized since the past few years (due to the addition of JIT techniques) plus the average users are using the modern computers that can run the code through virtual machine in almost the same speed as if it is written in a compiled language.
Most interpreted languages can be used interactively where you can run the code on the fly through the shell line-by-line (REPL). For instance, Python provides an interactive shell through which you can type the function or statement to do something (such as, printing the number, adding the numbers, etc.), and it will work instantly and give the results to the console, even on the website. There are few compiled languages that can run interactively, such as, Clojure (Lisp), Haskell, etc. Interpreted languages can also be very convenient for dynamic typed languages.
Please note that compilation or interpretation is a matter of implementation, not the language itself. Most often than not, many languages considered “interpreted” also provides a compiler to translate the code to machine language. But, as newbie programmers tend to search “compiled vs interpreted languages”, we were forced to use such title for our tutorial.
If you have any question, then you can ask in the comment section below!

Procedural Programming vs Object-Oriented Programming – Which would win the battle?

Programming languages comes in a different flavors through different programming paradigms which provide a particular style to write the code. The style could include syntax, features, indenting, etc. Two of the most used programming paradigms are procedural and object-oriented. In the recent development of programming languages, the object-oriented style pretty much took over the old procedural style that was dominating in the early programming days.

In this tutorial, I am going to show you the difference between these two paradigms, and the pros / cons of these styles. Let’s get started!

Procedural Programming

Procedural programming is the part of imperative programming. In imperative programming, we tell the computer “how to do” rather than “what to do”. In procedural programming, we use statements to change the state of the program. Statements include the lines of code which are instructions telling the machine “how” something should be done. As we would need to write hundreds of code to perform the tasks, sometimes it becomes necessary to carefully select those lines of code or statements that are used excessively within a same program and then copy it somewhere and then paste on those places where they are required. Thankfully, procedural programming provides procedures, also knows as subroutines or functions, which can be used to hold the commonly repeated lines of code, and then use it whenever you require it in your programs.

What are procedures?

Procedures are routines / functions that holds several lines of code, which can be placed whenever you need to do something instead of writing the same lines of code again and again. Thus, it’s a way to organize the code to reduce duplication. Procedures can be called in other procedures, and even in themselves. In procedural programming, we create / define different procedures (i.e., printName, changeColor, etc.) and call them whenever we like to perform a required task.

Following is the example of the program in C, which is enough to show the procedural programming style:


Pros

  • Easier to learn the programming language
  • Encourages coding in a straight-forward way
  • Can be a good start for the newbie programmers

Cons

  • Hard to organize code
  • Looks outdated
  • Hard to add the support of new features
  • Lack flexibility

Object-oriented Programming

Object-oriented programming came later in the programming community. It is often contrasted with procedural programming, because here we deal with the objects that are created through a class — a sort of a blueprint which holds different methods / attributes — which then are manipulated and used with each other to change the state of the program. It emphasis objects rather than “actions” and data rather than “logic”.

What are objects?

When we say “object-oriented programming”, we mean that our programming revolve around the objects. An object is an entity that is created through the use of a class, so we need to first create a class for a particular object (i.e., apple, rectangle, car, etc.). It is sort of a variable or an identifier in other programming languages, however, the difference here is that it holds properties of a class (through which it is created) and the methods (also called “fields”; “functions” in procedural programming) of a class to manipulate the other objects or itself. Thus, through manipulation of the different objects, we change the state of the program.

Following is the example of a program written in Java, which can be considered a beginner example of OOP:

Here, we’ve created two classes: PrintNumber and Main. In Java, the creation of at least one class is necessary to do anything, therefore, we used the Main class as the start point of the program. Then, we’ve created PrintNumber class through which we’ve created an object named “num”. Then, we called a method “print” through “num” object, thus manipulating it.

Apart from simple classes to manipulate objects, OOP also provides several features to build relationship between objects, and to further facilitate the organization of code. These features include inheritance, polymorphism, templates, etc.

Pros

  • Encourages organization of code
  • Easier for other developers to build based on previous code
  • Very flexible to create modules

Cons

  • Slow initial startup; need to write boilerplate code even for small tasks.
  • Takes more lines of code for simple programs; need to create classes for everything
  • Often feels bloated in features

Conclusion

In this tutorial, I have highlighted the difference between procedural and object-oriented programming. I would argue that it’s not good to debate about the importance of either of these styles, as they both provide enough features and rules for building certain kinds of applications. Procedural programming proponents use this style for simplicity (because they love to simplify the code!) and the fact that they don’t like bloated (or extra) features that comes with object-oriented programming, so they resort to programming in the old ways. Object-oriented programming proponents use this style for the better code management (in case they want other people to work on their projects!) and their expectation of the growth of their applications force them to think in a long-run.
If you have any question that you think I’ve missed (unfortunately) in the article, then you ask in the comment section below!