Skip to main content

Learning Python part 1: Intro to programming

Welcome everyone to this series on learning python programming. This post will be the first in this series and we will see basic introduction to the world of programming before we dive deep into it. This is just to have basics sound and clear. If you are already well versed with it, feel free to skip further to required section. So without any further delay, let's get started!!!!
What is a Computer program?
  • Well, a computer program is nothing but set of instructions grouped together and executed in order to get required result. 
  • For example, We can write a simple Calculator program code in Python as below for some mathematical operations.
  • You can find below code at gitHub.
What is Programming?
  • As per technical definition, computer programming is the process of designing and building an executable computer program to accomplish a specific computing result.
  • Basically programming involves tasks such as: Information gathering, analyzing, identifying requirements like algorithms, generating algorithms if required in a chosen programming language (commonly referred to as coding).
Why do we need programming?
  • Well, Computers are powerful entities, yet they need to be told (input) almost everything like how to perform tasks, evaluate a condition, how to handle data, & how to react if something goes wrong. 
  • I know you might think, how about AI and ML then? The fact is that AI (based on logic programming paradigm) and ML are also dependent of programs written in some programming language like Python.
Why programming language?
  • Logic here is quite simple. We, humans use high level languages (i.e English and others) in our day to day activities.
  • Computers use assembly language (i.e. 0’s and 1’s (Binary) to perform its tasks.
  • So we use programming language as bridge (interpreter) between our language(High level languages) and computer language(Assembly)
  • For list of available programming languages, check this link: 
https://en.wikipedia.org/wiki/List_of_programming_languages
Programming paradigms and languages:
  • Programming paradigm, we can put it as an approach towards programming based on operational requirements. 
  • What I mean by this? well, if you are a NASA scientist, you may deal with kind of mathematics, physics and so on due to space science and calculations, which might be alien concept to a normal person. So you will require an approach that fulfils your requirement.
  • Whereas if you are a simple IT programmer, your requirements will be also according to business needs.
  • Based on your requirement, you will need to select correct language that meets your requirement of programming. Basically, If you want build website, then HTML, JavaScript might help you better than C or C++. 
  • The simple fact is that, there is no single language that has all features in it.
  • Programming paradigm helps to classify programming languages based on their features. 
  • Languages can belong to multiple paradigms. Like Python includes functionalities of Procedural, OOP and functional programming.
  • I will not go in much details here about paradigms as it will take sideways as there are number of paradigms that are available. You can read more about them here at 
https://en.wikipedia.org/wiki/Programming_paradigm
  • We will take few examples only as our focus is on Python programming
Some of the common programming paradigms include:
Imperative: 
In this approach, programmer instructs the machine how to change its state,
  • Procedural: 
    • Procedural paradigm groups instructions into step by step procedures
  • Object-oriented (OOP): 
    • In OOP, programs are treated as a set of interacting objects. 
Declarative: 
In this paradigm,  the programmer declares properties of the desired result, but not how to compute it
  • Functional: 
    • Treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
    • The output value of a function depends on its arguments, so calling a function with the same value for an argument always produces the same result. 
    • JavaScript, one of the world's most widely distributed languages, has the properties of a dynamically typed functional language.
    • SQL also uses some elements of functional programming.
    • Other examples like Perl, PHP, Kotlin do have functional programming support though they are not designed specifically for functional programming.
    • Example:
      Function is called: > (avg 10.0 20.0) Function returns output as: 15.0
    • Here avg() is called against input numbers 10.0 and 20.0. So avg output is 15. But if you notice, we have not written any code or formula to do this operation because it is already there in the system. 
  • Logic: 
    • The desired result is declared as the answer to a question about a system of facts and rules.
    • An important concept in logic programming is the separation of programs into their logic component and their control component.
    • Example: In this example, simple logic is that, all animal beings die some day and due to this fact, horse named Caesar being an animal will also die some day.
    • Domains being = symbol
      Predicates animal(being) % all animals are beings horse(being) % all horses are beings die(being) % all beings die Clauses animal(X) :- horse(X) % all horses are animals horse(caesar). % caesar is a horse die(X) :- animal(X) % all animals die
Imperative Paradigm: 
Procedural languages:
  • Procedural languages are third-generation languages (described as first high-level languages) after machine code and assembly language.
  • They describe, step by step procedure that should, according to the programmer, be followed to solve a specific problem.
  • They use vocabulary related to the problem being solved. For example,
    • COmmon Business Oriented Language (COBOL) – uses terms like file, move and copy.
    • FORmula TRANslation (FORTRAN) – mathematical language, it was developed mainly for scientific and engineering problems.
    • ALGOrithmic Language (ALGOL) – focused on appropriate language to define algorithms, while using mathematical language terminology, targeting scientific and engineering problems, like FORTRAN.
    • Programming Language One (PL/I) – a hybrid commercial-scientific general purpose language supporting pointers.
    • Beginners All purpose Symbolic Instruction Code (BASIC) – it was developed to enable more people to write programs.
    • C – a general-purpose programming language, initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.
Object-oriented programming
  • Based on the concept of "Objects”.
  • We will talk about "Objects" in detail later in this series.
  • This is one of the most widely used paradigm due to its nature.
  • Object-oriented programming aims to implement real-world entities in programming. 
  • Other paradigms are  mostly specific to their approach and does not offer flexibility to relate with real world. What I mean by this is that, If you are working for some online shopping company like Amazon, only functional, mathematical or procedural paradigms might not be good choice considering the business structure. 
  • Many of the most widely used programming languages (such as C++, Java, Python, etc.) are multi-paradigm languages and they do support OOP to a greater or lesser degree.
  • The object-oriented paradigm provides key benefits like flexibility, reusability of the code and code extensibility. For more details about OOP, do check Geeks for Geeks

Comments

Popular posts from this blog

Learning Python Part-6: Python Comments

When it comes to writing a python program, based on the requirements, programs can simple programs of limited number of  lines or it can be really large program which might even span multiple python modules. Now the point here is that, even if we know how to write the program and even we follow correct concepts and syntaxes while writing program, we cannot keep it in our mind forever. We cannot remember each and everything about the program like variables, classes, concepts, functions and so on after some period of time. If the program written by us at some point in time back, once we open it after a period of time, it should not be a situation that we are blank, or guessing why particular code, function and so on. Even it may happen that you are working in a team and program code writing tasks might be shared. So when you put all pieces together written by multiple programmers in your team, you should be able to understand the code. This is where we bring in the concepts of

Learning Python Part-4: Python Keywords

Python has a set of keywords that are reserved words that cannot be used as variable names, function names, or any other identifiers They are used to define the syntax and structure of the Python language. In Python, keywords are case sensitive. There are 33 keywords in Python 3.7.  All the keywords (except True, False and None) are in lowercase. Below is the list of keywords in Python 3.7 I will not be using just syntax to explain these keywords, rather I will use some simple yet enough code examples considering new plus experienced people. For those who are new to python, if you find it difficult  to understand the complete code, just try to see the context and usage of keyword.  False :  This keyword is used to represent a boolean false. If a statement is false, “False” is printed. False in python equals to 0. True: This keyword is used to represent a boolean true. If a statement is true, “True” is printed. True in python equals to 1. None:

Welcome

Welcome everyone to CodeZen. Learn to code with simplified tutorials and examples.  Our focus will always be on simplicity. Hence all programming tutorials and examples are written in simple, understandable language for everyone including beginners.  The only way to learn to program is by writing code. So we encourage you to try the example we provided, implement your imagination and take it to next level.  We know that there are thousands of resources available on these topics. We just want make difference in how the information is presented so that everyone can understand. We simply want to present a different approach of detailed yet simple, with other - more interesting - examples, and so on.