The Grammar of programming. Hey everyone how are all of you guys… | by Contemporist | CodeX | Nov, 2021

Contemporist
“picture by Photo by luis gomes from Pexels

Hey everyone how are all of you guys doing, I hope you are well. Today I would like to deconstruct and bring the ‘the main parts of speech in programming’, and make it simple for anyone that needs to understand what programming is. This is a read intended for beginners and absolute beginners. I myself have started programming for a short period of time now, and I would like to explain things which often take a long time to understand for beginners and summarize how they work in the domain of programming.

Programming languages are basically languages which are comprehensible to the programmers for them to understand and write code. Python, the language founded by Guido Van Rossum is essentially the most comprehendible language up to now for humans to understand and program in. Each application has different programming languages for example, If you want to design a website display you would use HTML (hypertext markup language). Each language has it’s own structure and format backed by libraries of modules which make tasks easier. For example, if you wanted to create a 2d game, then you could use the Pygame module. Each module has different classes and methods which help you in designing the game you want to create. Each language has many engineers working on creating modules that interface to bring about many applications. Programming languages get converted into assembly and binary languages. Computers only understand binary languages. Thus, what python is called is a compiler and an interpreter. Interpreters fetch the code you have written and interpret them according to a certain structure and format, than the compiler parses that language into assembly and binary and passes that information to the processor(CPU). Parsing means to converting a format of something into something else. For ex, If you want to convert a word document to a pdf a parser designed to do the job will eventually do so. In short this is a summary of what programming languages are. In an upcoming article god-willingly I will be discussing the different types of languages and how they interface to create unique applications.

So, in simple terms input is the information or tasks you assign to a computer, it could be getting input from the user to anything you want the computer to do, like print a statement on the terminal.

ex, print(“hello world”)

print(4 + 4)

output is simply what the function executes and displays, whatever you want the function to do and execute will be defined in the output, it depends on the knowhow of functions and thier methods and what they are defined to do.

ex, hello world

8

This is basically the best part of programming that programmers can do, control flow is maneuvering a program till you find what you need or do what you need, this is classified into conditional statements and this is divided into 3 categories:

While loop : This means to run over a program until you find something you want, when you find that certain thing you want, than you can stop, I will give you an example.

“this is an example”

In this example we have two types of conditional statements, a while loop and an if and else statement.

above we have set the variable trys to zero, and while 0 is less than 3 we will add 1 to zero until 3. This will give us a total of 3 try’s.

while the user has 3 try’s he will have a chance to guess the secret word, which is already defined above. This is where the next conditional statement comes in.

If statement: an if statement, is a statement which checks an object in a program and see’s if it complies with the condition set, if it does not it will continue looping else it will not. Above in the program we want to see if the user input is equal to the secret word.

elif statement: we have not used an elif statement in the above program, but in general an elif statement is used if there is a second condition you wish a program to meet, you can use as many elif statements as you want.

else statement: if the above statements or statement is not met, you add the else statement to print out a message or do what is desired.

When looping over large files, either text or any other format, these statements are used to extract the information desired, this is just a brief synopsis.

In programming there are two types of data, either they can be iterable, meaning looped over by each element , or they can’t.

For loop: a for loop is a loop which loops over an object and goes through each element in the object until reaching the desired one, I will show you how an example with a half pyramid.

“an example program”

as you can see in the above program we have defined a variable with a range of 5. Conventionally a zero is the starting point of any range is something else is not defined. So, for each iteration in variable x with the range 5, we want to print an asteroid times the value of the iteration, and the value we get is in the output terminal.

So, basically we have defined what control flows are, they work by looping and conditioning the programs to do the most appropriate work.

This is the last part of the grammar and syntax of programming, we have to remember that writing long lines of code is unconventional and causes alot of hassles in programming, if we want to define a big program and use it do different types of operations, we can store functions like we have seen above and call them later and add them to larger programs. Remember that a function is a method, and I will show you how reusable code is distributed accordingly. Let’s say we want to make a game, which consists of a guessing game and printing out a half pyramid with the desired parameters. We will substitute that into a class which is named accordingly to it.

“an example of a class”

so, basically we have defined a constructor for the class which takes the self as an parameter, because everything contained in the class belongs to the class.

we have defined the function of the guessing game and we have placed it in the class, this becomes a class method, so does the half pyramid function. You can acess any of these functions by storing the class in a variable and using the dot notation to access these methods. When you create multiple objects such as classes and functions you can save them to one large package or directory or even a page and import them as modules or libraries.

This is the basic grammar of programmer ,

Thanks for reading….