Self-teaching how to code with Python, part 1: Basic Concepts

in #python6 years ago (edited)

Introduction

Long story short, I currently know nothing about how to code. But, since I started to get involved with crypto, I think that it is mandatory to become tech-savvy if I want to fully grasp the true dimension of this huge historical possibility for human society to get a fair, transparent, and decentralized paradigm (a.k.a. Blockchain Technology).

Therefore, I intend to use the awesome features of the Steem Blockchain to record my progress and to share the experience with any who is willing to give me a hand or with one who is willing to walk through the same path.

From here on I will write the primary understanding that I get from each topic and will try my best to express the core idea embed in each definition.

Why write these posts in English? Simply because you have to write in English when coding, and because writing in some foreign language boost my concentration when actually writing the post.

Learning the basics

The Python Interpreter:

It seems that the code that we write needs to be translated to a more basic language for the hardware of our device to understand our instructions. The program that carries this duty is called the interpreter, and when coding in Python we always need to run the interpreter when we want to execute our code.

In its simplest view, when we make a program in Python we write a text file containing Python statements (instructions), and when we execute the program we have Python to execute all the statements on the text file from top to bottom. There are more interesting and subtle details involved in all this.

Byte code

Before executing a program, Python compiles the source code from the text file to a platform-independent lower-level representation of the code called byte code. The compilation speed is the same as the execution speed since byte code can be executed faster than the original source code from the text. If Python has write permissions the byte code will be stored as a .pyc, and for runtime optimization Python automatically runs the byte code file if we have not updated the original source code text file.

Python can run programs if it only has byte code files. Actually, the time needed to run byte code files is shorter because Python can skip the compilation step. This is especially useful when coding large programs.

Python Virtual Machine (PVM)

This is the last part of what is known as the Python Interpreter", the PVM is the actual runtime engine of Python, it is a loop that iterates through our code and executes our byte code instructions, one by one, to carry out our operations.

This working scheme has its implications, Python is slower than C or C++ because the PVM needs to interpret the byte code and it requires more computational work than C binary code CPU instructions. But Python does have an internal compilation step, thus there is no need to analyzing and reparsing each source instruction. Thus Python's run speed is somewhere in between traditional compiled languages and traditional interpreted languages.

Python has three main implementations, namely CPython, Jython, and IronPython. CPython is the standard implementation and its inner workflow is as follows:

  1. Parse source code into a parse tree
  2. Transform parse tree into a Abstract Syntact Tree
  3. Transform Abastract Syntact Tree into a Control Flow Graph
  4. Byte Code generation from Control Flow Graph

More on this will be elabotared on next posts.

Source

Sources:

Sort:  

This post has received a 4.29 % upvote from @boomerang.

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by joelsegovia from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Congratulations @joelsegovia! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62904.22
ETH 2571.38
USDT 1.00
SBD 2.76