kids encyclopedia robot

Programming language facts for kids

Kids Encyclopedia Facts
C Hello World Program
This is a simple computer program written in the C programming language. When it runs, it will show the words "Hello, world!" on the screen.
Manchester Mark2
The Manchester Mark 1 computer ran programs written in a language called Autocode starting in 1952.
Bangalore India Tech books for sale IMG 5261
Books like these teach people how to write computer programs. There are thousands of different programming languages that have been created over time.
Python add5 parse
Parse tree of Python code showing how a computer understands it.

A programming language is a special written language that tells computers exactly what to do. Think of it like giving a computer a set of instructions. These languages are used to create all the computer programs and software you use every day.

A person who writes programs is called a programmer. They write the instructions, known as source code, using a programming language. Many programming languages use words that look like English, which makes them easier for people to read. They also use punctuation, just like regular languages.

Many programs are "compiled". This means a special program translates the source code into a language the computer understands much faster. This computer language is often called machine language. It is very hard for humans to read, but super fast for computers.

Computer programs must be written very carefully. If a programmer makes a mistake, the program might "crash" or stop working. A problem in the code is called a "bug". Even a tiny mistake, like forgetting a comma, can cause a big problem.

Different Kinds of Programming Languages

There are many different types of programming languages. Most languages can fit into more than one type. This makes it tricky to put each language into just one group. We will look at some of the most common types below.

Telling Computers What to Do

Some programming languages are declarative. This means you describe what you want the computer to do, but not exactly how to do it. It's like telling a friend, "I want a sandwich," without giving them step-by-step instructions on how to make it. Languages like Prolog and SQL are examples.

Other languages are imperative. These languages give the computer step-by-step instructions. You tell the computer exactly how to solve a problem. Most common programming languages are imperative because they are often easier to use for many tasks.

Functions and Procedures

Functional programming languages treat programs like functions in mathematics. A program gets some input (information) and uses it to create output. It doesn't change anything else outside of this process.

Procedural programs are like a list of steps or actions the computer should follow. Each step changes the program's "state" or what it is currently doing.

Stack-Based Languages

Stack-based languages use a special part of the computer's memory like a stack of plates. You can only do a few things with this stack:

  • You can "push" a new item onto the top of the stack.
  • You can "pop" an item off the top of the stack.
  • You can "peek" at the item on top without taking it off.

For example, if you tell a program "push 5; push 3; add; pop;", it will:

  1. Put 5 on the stack.
  2. Put 3 on top of the 5.
  3. Add the top two numbers (3 + 5 = 8).
  4. Replace the 3 and 5 with the 8.
  5. Print the top number (8).

Languages like Postscript and Forth use this method.

Object-Oriented Programming

Object-oriented programming languages (often called OOP) group data and the actions that change that data into single units. These units are called "objects". Imagine an object as a digital "thing" that can store information and do actions. For example, a "Dog" object might store its color and breed, and it could also "bark" or "wag its tail".

Objects can interact with each other. This way of organizing code helps keep things neat and makes programs easier to manage. Most modern programming languages use object-oriented ideas. Some examples are Java, C++, and C#.

Flow-Oriented Programming

Flow-oriented programming looks at a program as different parts connected together. These parts send messages to each other. A single part can be used in many different programs without needing to be changed inside.

Rules of Programming Languages

Every programming language has its own set of rules. These rules decide what you can and cannot do when writing code. They cover things like:

  • What kinds of numbers you can use (whole numbers, decimals, etc.)
  • How big or small numbers can be
  • Which words are special commands (called "reserved words")
  • Whether uppercase and lowercase letters matter (this is called "case-sensitivity")

Most languages have official standards. These standards are like rulebooks that explain exactly how to write the source code. Sometimes, a language might have a new standard that replaces an old one. For example, the Perl 5 standard replaced Perl 4 in 1993.

Object-Oriented Programming (OOP) Explained

Object-Oriented Programming (OOP) is a popular way to build programs. In OOP, everything in your program is seen as an "object". Objects are like reusable building blocks of code. They hold information and can perform actions.

Think of an object as a blueprint for something real. A bank account, a picture on your screen, or a hero in a video game could all be objects in a program.

Objects have:

  • Properties: These are pieces of information the object stores. For a "Dog" object, properties might be its height or hair color.
  • Methods: These are actions the object can do. A "Dog" object's methods might be `bark()` or `wagTail()`.

All objects are created from special templates called classes. You can imagine a class as a cookie cutter. The class defines all the properties and methods that any object made from it will have. Objects created from a class are called instances of that class.

A class can also extend another class. This means it takes all the properties and methods from the first class and can then add its own unique ones.

Here is an example of what a class might look like in a programming language:

class Dog extends Mammal{

  //These are properties (information about the dog):
  String breed = "Collie"
  String type = "Herding Dog"

  //These are methods (actions the dog can do):
  void wagTail(){
    // Instructions for wagging the tail go here
  }

  void bark(){
    // Instructions for barking go here
  }

}

In this example, the `Dog` class "extends" the `Mammal` class. This means all `Dog` objects will automatically have properties like `hairLength` and methods like `eat()` or `sleep()`, because `Mammal` objects have them.

Object-oriented programming is used in many popular languages today. These include Java, C#, C++, Python, Ruby, and Javascript.

Examples of Programming Languages

Let's look at how the same simple program can be written in different languages. This program asks you your age and then gives a different message based on your answer.

Example in Visual Basic

Here is the program written in Visual Basic:

 Dim Input
 Input = InputBox("How old are you?")
 If Not IsNumeric(Input) Then
   MsgBox "That's not a number!"
 ElseIf Input < 0 Then
   MsgBox "You cannot be less than zero!"
 ElseIf Input > 100 Then
   MsgBox "That's old!"
 Else
   MsgBox "You're " & Input & " years old."
 End If

This code asks for your age. If you type something that isn't a number, or a number less than zero, or a number over 100, it gives a special message. Otherwise, it tells you how old you are.

Example in Python

Here is the same program, but written in Python:

 try:
     age = int(raw_input("How old are you? "))
 except ValueError:
     print "That's not a number!"
 else:
     if age < 0:
         print "You cannot be less than zero!"
     elif age > 100:
         print "That's old!"
     else:
         print "You're %s years old." % age

Example in C#

And here is the same program written in C#:

using System;

public class Hello
{
    public static void Main()
    {
        Console.WriteLine("What is your age?");
        int age;
        if (!int.TryParse(Console.ReadLine(), out age))
            Console.WriteLine("That's not a number!");
        else if (age < 0)
            Console.WriteLine("You cannot be less than zero!");
        else if (age > 100)
            Console.WriteLine("That's old!");
        else
            Console.WriteLine("You're {0} years old.", age);
    }
}

Example in Haskell

Finally, the same program written in Haskell:

import Text.Read
main = do
  putStrLn "What is your age?"
  input <- fmap readMaybe getLine
  putStrLn $ case input of                   
    Just age | age < 0 ->   "You cannot be less than zero!"
             | age > 100 -> "That's old!"
             | otherwise -> "You're " ++ show age ++ " years old."
    Nothing -> "That's not a number!"

See also

Kids robot.svg In Spanish: Lenguaje de programación para niños

kids search engine
Programming language Facts for Kids. Kiddle Encyclopedia.