Introduction to Programming

Photo by Ilya Pavlov on Unsplash

Introduction to Programming

A glimpse into the vast word of programming.

ยท

3 min read

What is programming?

Simply put, it's like giving your computer instructions, telling it what to do step-by-step. These instructions, written in specific languages, allow you to build anything from a simple calculator to a complex game engine.

But wait, there are countless programming languages!

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

That's true! Just like we have different languages for communication, each programming language has its strengths and weaknesses.

Types of Programming Languages

  • Procedural Languages: Think of these as recipe instructions. You tell the computer each step it needs to take, one after the other, to achieve a specific outcome.

  • Examples include C, Python (in some aspects), and Java.

  • Functional Languages: Imagine building with LEGOs. Each function is a piece; you click them together to create the final program. They focus on what to do rather than how to do it.

  • Examples include Haskell and Lisp.

  • Object-Oriented Languages: This is like building with pre-made modules. You have objects with properties and functions, and they interact with each other to create the program.

  • Popular examples include C++, Java, and Python (in most cases).

๐Ÿ’ก
Now, let's dive deeper into two key concepts

Static vs Dynamic Languages

  • Static Languages: Think of these as strict teachers. They check your code thoroughly before you even run it, ensuring everything is written correctly. Examples include C++, Java, and Go.

  • Dynamic Languages: These are more like laid-back friends. They trust you to write the code and only complain if something goes wrong during execution. Examples include Python, JavaScript, and Ruby.

StaticDynamic
Perform type checking at compile timePerform type checking at runtime
Errors will show at compile timeAn error might not show till the programs run
Declare datatypes before useNo need to declare datatype of variables
More controlSaves time in writing code but might give errors at runtime
๐Ÿ’ก
But where does all this code and data live? Enter the world of memory allocation!

Memory allocation

Your computer has two main areas for storing program data: the stack and the heap.

  • Stack: Imagine a stack of plates. Variables declared inside functions live here, and when the function finishes, its plates (variables) are removed, freeing up space. It's fast and efficient but limited in size and temporary.

  • Heap: Think of this as a messy closet. Dynamically allocated data, like arrays and objects, live here. It's more flexible, but managing this space manually can be tricky.

    We don't store the actual objects (like furniture) in the closet, just labels (reference variables) pointing to them. This saves space and allows objects to be shared easily.

    For example:- ๐‘Ž = 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.


This blog is written on my learning knowledge and examples and some points are taken from Kunal Kushwaha DSA BootCamp notes.

"THANKS FOR READING"

ย