Introduction to Programming

Programming is the art of giving instructions to a computer to perform tasks. It’s like teaching the computer what to do, but instead of using human language, we use programming languages. These languages are a way to communicate with computers and instruct them to perform specific actions. If you’re new to this, don’t worry—this article will break it down for you in simple terms, even if you have no prior programming experience.

Types of Programming Languages Based on Complexity

Programming languages can be broadly classified into two categories based on their complexity: Low-level and High-level languages.

  1. Low-level languages: These languages are closer to the machine’s hardware, meaning they provide little or no abstraction from a computer’s instruction set. They are difficult for humans to understand but are more efficient for the machine. Examples of low-level languages include:
    • Machine language: The lowest level, consisting of binary code (0s and 1s).
    • Assembly language: A slight abstraction from machine language, where simple instructions like ADD and MOV are used.
  2. High-level languages: These are designed to be easier for humans to read and write. High-level languages provide a significant level of abstraction from the machine, meaning they are more focused on problem-solving and less on how the machine works internally. These languages include:
    • Python: Popular for beginners due to its simplicity.
    • Java: Commonly used in enterprise applications.
    • Salesforce Apex: A language used for customizing and building applications on the Salesforce platform.

High-level languages make programming accessible to beginners because they are closer to human languages and take care of many complex details like memory management for you.

Types of Programming Languages Based on Typing

Another way to classify programming languages is by their typing system. Typing refers to how strictly a language checks the types of variables.

  1. Strongly typed languages: These languages enforce strict rules about how data types can be used. If you try to use a variable in a way that doesn’t match its type, the program won’t work. Examples include:
    • Java: If you declare a variable as an integer, you can’t later treat it as a string without explicitly converting it.
    • Salesforce Apex: Like Java, Apex is a strongly typed language. This means when you define a variable as a particular data type (e.g., integer, string), you must stick to that type.
  2. Dynamically typed languages: In these languages, variables are not bound to a specific type. You can change the type of a variable at runtime, making these languages more flexible but sometimes prone to errors that are hard to detect. Examples include:
    • Python: You can assign a number to a variable, and later in the code, assign a string to the same variable without an issue.

For beginners, dynamically typed languages may feel easier to work with at first because you don’t need to worry too much about types. However, strongly typed languages are often more predictable and help prevent certain types of bugs.

What Is an Instruction and a Program?

An instruction is a single command given to a computer to perform a specific task. For example, telling the computer to add two numbers together or to display some text on the screen.

A program is a collection of instructions that work together to accomplish a task. For example, when you use a calculator on your computer, there’s a program running in the background that handles all the math.

Salesforce Apex: A High-Level, Strongly-Typed Language

Now, let’s talk about Salesforce Apex in context. Apex is a high-level language used to build and customize applications on the Salesforce platform. It allows developers to write code that automates processes and interacts with the Salesforce database. Since it is a high-level language, Apex abstracts away the complex details of machine operations, making it easier to work with, especially for developers focusing on business logic rather than technical details.

Moreover, Apex is a strongly typed language, which means when you declare a variable in Apex, you must specify its data type (e.g., Integer, String, Boolean). This reduces the chances of errors related to type mismatches, making your programs more stable and easier to debug.

Here’s a simple example of an Apex class that calculates the area of a rectangle:

public class Rectangle {
    // Declare variables with specific types
    Integer length;
    Integer width;

    // Constructor to set the values of length and width
    public Rectangle(Integer l, Integer w) {
        this.length = l;
        this.width = w;
    }

    // Method to calculate the area of the rectangle
    public Integer calculateArea() {
        return length * width;
    }
}

In this example:

  • The length and width variables are explicitly declared as Integer types. Because Apex is strongly typed, if you try to assign a value that’s not an integer (like a string), the system will show an error.
  • The calculateArea method multiplies length by width and returns the result as an integer.

Let’s see how you would use this class in practice:

// Create a Rectangle object with length 5 and width 10
Rectangle myRectangle = new Rectangle(5, 10);

// Calculate and display the area of the rectangle
System.debug('The area of the rectangle is: ' + myRectangle.calculateArea());

This example creates a Rectangle object with specific dimensions (length = 5, width = 10) and then calls the calculateArea() method to find and print the area. Because Apex enforces strict typing, you can be confident that the variables will behave as expected, reducing the chance of bugs.

By using Apex, developers can write clean, efficient code that follows strict rules regarding data types, making it a robust choice for building enterprise applications.

This coding example helps demonstrate how Apex works as both a high-level and strongly typed language in real-world scenarios.

Conclusion

Programming might seem complex at first, but understanding the basics like types of programming languages and how they are used can make the journey easier. Salesforce Apex, being both a high-level and strongly typed language, offers a great balance between simplicity and precision, which is why it’s widely used in building enterprise-level applications.

By learning the basics of programming and starting with tools like Salesforce Apex, you’ll be on your way to building powerful applications in no time!