August  Murray

August Murray

1626405900

Infrastructure-as-Code (IaC): Methodologies, Approach, and Best Practices

IaC Overview

As everything is digitized now, especially after the Covid pandemic, it is now even more important to properly manage the IT infrastructure of an organization.

Earlier, this management of IT infrastructure was done manually by the system administrators. They managed all the hardware and software that was required for an application to run. Tech has progressed a lot in the past few years, and now there is an alternative to this manual management, called Infrastructure as Code or IaC in short.

Let us define IaC in more descriptive terms. Infrastructure as code is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.

IaC tackles problems that were present before its use, such as manual environment build process, manual approval process, high costs, hardware issues, and errors caused by human beings.

IaC Methodologies

Let us now see the four methodologies of Infrastructure as Code, which are as follows:

Ad Hoc Scripts

Ad Hoc Scripting is the most straightforward approach for the automation of processes. These scripts convert manual processes to automated processes just by simply breaking them down into discrete steps. You can achieve this with the help of scripting languages like Ruby, Python, Bash, PowerShell, etc.

If you run an ad hoc script, it will definitely give the expected results, and the running process is also fairly easy. However, there are chances of an error if you run the same ad hoc script multiple times. For instance, if you create a folder using an ad hoc script, then you would have to check again later if that folder still exists or not.

#cloud #devops

Infrastructure-as-Code (IaC): Methodologies, Approach, and Best Practices
Tyrique  Littel

Tyrique Littel

1604008800

Static Code Analysis: What It Is? How to Use It?

Static code analysis refers to the technique of approximating the runtime behavior of a program. In other words, it is the process of predicting the output of a program without actually executing it.

Lately, however, the term “Static Code Analysis” is more commonly used to refer to one of the applications of this technique rather than the technique itself — program comprehension — understanding the program and detecting issues in it (anything from syntax errors to type mismatches, performance hogs likely bugs, security loopholes, etc.). This is the usage we’d be referring to throughout this post.

“The refinement of techniques for the prompt discovery of error serves as well as any other as a hallmark of what we mean by science.”

  • J. Robert Oppenheimer

Outline

We cover a lot of ground in this post. The aim is to build an understanding of static code analysis and to equip you with the basic theory, and the right tools so that you can write analyzers on your own.

We start our journey with laying down the essential parts of the pipeline which a compiler follows to understand what a piece of code does. We learn where to tap points in this pipeline to plug in our analyzers and extract meaningful information. In the latter half, we get our feet wet, and write four such static analyzers, completely from scratch, in Python.

Note that although the ideas here are discussed in light of Python, static code analyzers across all programming languages are carved out along similar lines. We chose Python because of the availability of an easy to use ast module, and wide adoption of the language itself.

How does it all work?

Before a computer can finally “understand” and execute a piece of code, it goes through a series of complicated transformations:

static analysis workflow

As you can see in the diagram (go ahead, zoom it!), the static analyzers feed on the output of these stages. To be able to better understand the static analysis techniques, let’s look at each of these steps in some more detail:

Scanning

The first thing that a compiler does when trying to understand a piece of code is to break it down into smaller chunks, also known as tokens. Tokens are akin to what words are in a language.

A token might consist of either a single character, like (, or literals (like integers, strings, e.g., 7Bob, etc.), or reserved keywords of that language (e.g, def in Python). Characters which do not contribute towards the semantics of a program, like trailing whitespace, comments, etc. are often discarded by the scanner.

Python provides the tokenize module in its standard library to let you play around with tokens:

Python

1

import io

2

import tokenize

3

4

code = b"color = input('Enter your favourite color: ')"

5

6

for token in tokenize.tokenize(io.BytesIO(code).readline):

7

    print(token)

Python

1

TokenInfo(type=62 (ENCODING),  string='utf-8')

2

TokenInfo(type=1  (NAME),      string='color')

3

TokenInfo(type=54 (OP),        string='=')

4

TokenInfo(type=1  (NAME),      string='input')

5

TokenInfo(type=54 (OP),        string='(')

6

TokenInfo(type=3  (STRING),    string="'Enter your favourite color: '")

7

TokenInfo(type=54 (OP),        string=')')

8

TokenInfo(type=4  (NEWLINE),   string='')

9

TokenInfo(type=0  (ENDMARKER), string='')

(Note that for the sake of readability, I’ve omitted a few columns from the result above — metadata like starting index, ending index, a copy of the line on which a token occurs, etc.)

#code quality #code review #static analysis #static code analysis #code analysis #static analysis tools #code review tips #static code analyzer #static code analysis tool #static analyzer

Static Code Analysis: What It Is? How to Use It?

Code Trashing Symptom

There are a set of skills and qualities which make the ideal software

developer we are all searching to be or searching for to employ. However, right now I am going to emphasize the importance of a quality that is mostly found in senior developers.

As a beginner, I remember the enthusiasm when I implemented my first app. It was in VisualBasic v6.0 with very basic UI and logic. From there on,

it was very hard to leave the keyboard without writing code daily. At

first, it was VB, then some HTML, JavaScript (when it was very buggy),

Java, and sometime later I became a true working developer/team-leader

for many years.

Reliving those days when I was an enthusiast developer, I remember the powerful feeling that kept me on my path. I was (and still) addicted to code. But it is not code I was after. It is the vast feeling of creating something your own. Creating something from within. This strong feeling of a new creation is addictive.

The problem with addiction is that you don’t recognize the limits of

yourself and your creations. Consequently, you are not guided by your

consciousness.

As a leader of development teams in different projects, I came across a

variety of situations with different developers. But this same question I kept hearing from time to time, “This is a great piece of code, do you really want me to remove it?”, and it is really a great piece of code with the ultimate design.

But what you shouldn’t forget that you and your team are here to accomplish something meaningful for your clients and users! Thus writing a greatly designed code with low correlation to requirements isn’t going to change anything.

When I moved to my current team and project, I found out that the project’s code was written beautifully and well designed. But it was insignificant to our client’s future requirements.

One of the best decisions I made was to gradually re-implement (remove old code and write a new one without reference nor copy-pasting any parts). The reason being the already written code was a big hurdle to bend to any new requirements we received

Sometimes it’ll be hard to ask for, especially when you’re asking the original author of the code. But always remind him of these facts: your main focus is your clients; if you miss your code, Github will always remember it for you.

Acknowledging your addiction to code is your first step to overcoming your unconscious desire to create worthless stuff that no one will use (and believe me, it hurts more to find out that your code is useless than

removing a code you’ve written).

Final Thoughts

From my personal experience, when you implement something hard to solve the first time, most of your energy and thoughts are invested in solving the problem and not in the most relevant design for the given requirements.

Rewriting the same code a second time gives you a second chance to spend your time (almost solely) in design (since the problem is already

solved).

The best design is a design made for the current (known) requirements and not future mystic stuff that we just came up with.

**Remember: **Refactor! Don’t predict!

#clean-code #best-practices #programming #development #refactoring #coding #coding-skills #coding-life

Code Trashing Symptom
Seamus  Quitzon

Seamus Quitzon

1600061880

How to write clean code ? follow these best practices for writing clean code

Hey programmers , this article is not about some java related feature or concept but more than that . Basically I’m going to explain what all mistakes a java developer does while writing the code and hence how you can minimize it and you don’t have to refactor your code .So this article is about BEST PRACTICES a developer should always follow .

1. What’s there in the name :

A developer should always try to give a meaningful name to the variables, methods and classes . It becomes too easy to understand what the method or class or variable is about when some one reads your code while reviewing it or debugging it. Giving name like a ,b,c to variable do not intent any meaning and becomes less relevant while debugging the code .

  1. Always start the name of a class with upper case .Eg.
public class Employee {

}

here **Employee **is class name and other developers can easily understand that this class deals with employee related stuff.

2. Always start a variable name with lower case .Eg.

private int salary;

here **salary **tells about salary of employee .

3.Always start method name with lower case and do not include And and Or words in method name .Eg.

public int calculateSalary(int noOfDaysWorked , int baseSalary)

4. Write constants in upper case and separate them with under score .Eg.

public final int RETIREMENT_AGE = 58;

Note : do not use special symbols while writing variables ,methods , constants or classes names .

#programming #best-practices #code-review #java #coding

How to write clean code ? follow these best practices for writing clean code
Osiki  Douglas

Osiki Douglas

1624789560

Best Practices to Write Clean Python Code

Python is one of the most loved programming languages today. Shockingly, Python has overtaken Java in the list of top programming languages and is now the most studied language! It is the second most used language after JavaScript and is slowly beating the competition to be on the top. It is used extensively across various domains like web development through popular frameworks like Django and Flask, web scraping, automation, system administration, DevOps, testing, network programming, data analysis, data science, machine learning, and artificial intelligence. In fact, the first language which comes to someone’s mind when talking about data-related technologies is Python!

Along with being a heavily used language by beginners due to its ease of learning, it has huge community support and extensive documentation. But a lot of people when switching from other languages like Java, C, C++, JavaScript etcetera, find it a little difficult to follow along with the best practices that should be adopted to write clean code in Python. Clean code is easier to read and understand, debug, and elegant. So today we will be discussing all of them in detail, therefore you will get a better idea of them. So let’s get started!

#gblog #python #best practices to write clean python code #clean python code #best

Best Practices to Write Clean Python Code
Wiley  Mayer

Wiley Mayer

1603976400

Infrastructure as Code vs. Infrastructure as Software

Infrastructure as Code has been the hottest trend in cloud-native application development in recent years. By transforming infrastructure management into simple coded runtimes and routines, Infrastructure as Code or IaC allows developers to be more involved in the deployment part of their CI/CD pipelines. Even the most complex cloud infrastructure can be created with several lines of code.

IaC also means that server management, resource provisioning, and even long-term maintenance of complex cloud infrastructures are entirely simplified. Tools like Terraform certainly make maintaining a production environment that is both capable and efficient easy, even when there is no dedicated infrastructure team to handle the associated tasks.

A new trend that we’re seeing right now is further simplification of IaC, mainly known as Infrastructure as Software or IaS. Now that cloud services and the providers behind them are easier to access and control using tools and software, it is not impossible for the entire cloud infrastructure to be provisioned and managed as software libraries.

How does Infrastructure as Code differ from Infrastructure as Software? Which approach is better? We are going to answer these questions, and several others about these two trends, in this article.

IaC and IaS

The two approaches have some stark differences, but we are going to take a closer look at each of them first before we start differentiating the two. Infrastructure as Code is obviously the older approach of the two, and it has been very popular among developers. Using tools designed for managing infrastructure through lines of code, you can either manage the configurations of your cloud infrastructure or manage the provisioning of cloud resources; or both.

Terraform, a popular tool used by millions of developers, applies the second approach. The tool is not just handy for managing multiple configurations and making sure that key infrastructure variables are coded properly; it is also capable of provisioning resources and automating server deployment as needed. Terraform is very extensive in this respect.

Upon close inspection, Infrastructure as Software performs similar⁠—if not the same⁠—tasks using similar tools. You can deploy new server instances or configure the entire architecture using a few lines of codes. You can also automate provisioning and management, and you can still integrate IaS with your existing CI/CD pipelines.

Services that are available today support both approaches in most cases. The tools that fall into these two categories basically use the same API calls and available cloud resources to perform their runtimes, but they take different approaches when it comes to management. That actually brings us to our next point.

IaC vs. IaS

Now that we know how the two approaches are relatively similar, it is time to get the obvious out of the way. Infrastructure as Code and Infrastructure as Software has one huge difference, and that difference lies in the programming languages used by the tools. The easiest way to understand this difference is by comparing Terraform with Pulumi, which is a popular IaS tool.

Terraform requires you to use its native programming language. The HCL language is used for low-level programming. While the language is also used by other tools, the way it is used by Terraform is not always as straightforward as it seems. Terraform also supports JSON syntax but parsing and generating can quickly become bottlenecks as you try to organize massive cloud infrastructure environments.

Pulumi, on the other hand, uses programming languages you are already familiar with. It actually supports many of them, including Python, Go, and JavaScript. Don’t forget that loops and the programming structure of these familiar languages are carried over, so you define your cloud infrastructure the way you code functions in your cloud-native apps.

Since the programming language being used carries its own best practices and things like package management, you can implement the same set of elements into your IaS routine. No need to worry about having difficulties pushing infrastructure modules or doing plenty of adjustments in order for the configuration to be deployed at all.

#blog #code #continuous delivery #continuous integration #ci/cd pipeline #infrastructure as code #infrastructure as software #pulumi #terraform

Infrastructure as Code vs. Infrastructure as Software