Introduction to programming: Types of languages and memory management

A gentler version

Introduction to programming: Types of languages and memory management

“There are only two kinds of languages: the ones people complain about and the ones nobody uses.”

  • Bjarne Stroustrup

What is Programming?

Programming is a way to instruct the computer to perform various tasks. At the very core, the computer is just a bunch 0's and 1's i.e. they understand binary language. It will be very difficult to communicate with computers with 0's and 1's as humans. To solve this issue we have programming languages.

Programming language:- It is a computer language used by programmers to communicate with computers.

Programming Paradigms

Now, before we jump to types of programming languages let's know about paradigms. Programming paradigms are different ways or styles in which a given program or programming language can be organized. Each paradigm consists of certain structures, features, and opinions about how common programming problems should be tackled.

The question of why are there many different programming paradigms is similar to why are there many programming languages. Certain paradigms are better suited for certain types of problems, so it makes sense to use different paradigms for different kinds of projects.

Types of programming languages

Procedural Programming

  • Specifies a series of well-structured steps and procedures to compose a program.

  • Contains a systematic order of statements functions and commands to complete a task.

Functional Programming

  • Writing a program only in pure functions i.e. never modify variables but only create new ones as variables.

  • Used in situations where we have to perform lots of different operations on the same set of data like machine learning.

Object-oriented Programming

  • It revolves around objects that represent a mental model of an actual object in the real world.

  • Developed to make it easier to develop, debug, reuse, and maintain software.

Now modern languages can support different programming paradigms. Python is a language that can support all the above three types. While Java is almost a pure object-oriented language but still supports procedural.

Static vs Dynamic languages

In statically typed programming languages, type-checking occurs at compile time. At compile time, source code in a specific programming language is converted to a machine-readable format. This means that before source code is compiled, the type associated with each and every single variable must be known.

In dynamically typed languages, type-checking takes place at runtime or execution time. This means that variables are checked against types only when the program is executing.

StaticDynamic
Perform type checking at compile timePerform type checking at run time
Errors will show at compile timeErrors might not show till programs run
Declare datatypes before useNo need to declare datatypes of variables
More controlSaves time in writing code but might give error at run time

Memory management

In Java, There are 2 types of memory Stack and heap

When we declare a variable then the reference variable stored in stack memory points to the object of that variable stored in heap memory.

For ex:- a = 10

Here a is called the reference variable, and 10 is the object of that reference variable

  • Reference variables are stored in stack memory.

  • Heap memory stores the objects of reference variable.

Points to remember:-

  • More than one reference variable can point to the same object.

  • If any changes are made to the object of any reference variable that will be reflected to all other variables pointing to the same object.

  • If there is an object without a reference variable then the object will be destroyed by garbage collection

Memory management approach

Some programming languages use multiple approaches to memory management and some let the developer manage memory manually like in C/C++. The key difference is that Java's garbage collection is automatic and happens in the background, while in C, you have to explicitly allocate and deallocate memory using pointers. They provide the malloc,realloc and calloc methods to manage memory. Java's approach to memory management enhances safety and reduces the burden on developers, but it comes at the cost of reduced control over memory and the potential for occasional performance overhead due to garbage collection activities.

Conclusion

As you delve deeper into the world of programming, remember that practice and experimentation are key to mastery. Whether you're aiming to develop software, explore data, or create innovative solutions, the knowledge gained here is the foundation for your coding journey. So, keep coding, keep learning, and embrace the endless possibilities that the programming world has to offer.

Thanks for reading :)

You can connect with me on LinkedIn and Twitter.