Thursday, June 20, 2024

Python Basics, Variables, Data Types and Simulating Constants

The first thing you will notice about the Python programming language is that it differs from other programming languages in its simplicity. You should keep in mind that the Python programming language was created more out of a need to quickly code a solution when you have a programming or mathematical challenge. Everything considered unnecessary in programming languages, such as writing curly braces, was literally removed from it. Then some things that other programming languages have were added. For example, if we compare the Python programming language with the C# programming language, the first thing you will think is that it has fewer data types than the C# programming language, and these are basic ones.

Another significant difference of the Python programming language is that it is not a strongly typed programming language; rather, it is considered a dynamically typed programming language. This means that you do not have to declare data types of variables when defining them; the Python language interpreter itself determines the data type of a variable based on the value you assign to it. Likewise, in the Python programming language, you can change the type of a variable during program execution. If you have no experience with programming, you might wonder, what are variables? You can think of variables as small memory boxes of different sizes into which you can only put one type of data. For example, you cannot put letters in a box intended for integers.

A Programmer Codes in the Python Programming Language at Work

A Programmer Codes in the Python Programming Language at Work

However, you can put integers in a box for letters, but those numbers will no longer be numbers; they will be treated as a string of characters, just like letters. Simply put, variables in every programming language reserve space and store values in the computer's memory. When you create a variable and assign it a value, you are actually reserving free space in the computer's memory. That variable and its value remain in memory as long as your program is running. When you close the program, the variable is deleted. To permanently save a value, you need to write it to a file or database and use variables to transfer that value. Every programming language has different data types intended for different values, and so does the Python programming language.

In the Python programming language, an object is also a basic unit of data, just as it is in the C# programming language. The Python programming language, like the C# programming language, is an object-oriented programming language, which means that all values are treated as objects. Depending on the type of data you use, you will use the appropriate type of variable. It is important for you to learn what types of data are available, what data types you have at your disposal, and how to use them in the Python programming language in the best possible way. Therefore, we will focus solely on that. So, let's look at the basic types in the Python programming language:

bool - boolean type is used for data that can only be True or False.

int - integer type is used for whole numeric data.

float - numeric type used for floating-point numbers.

complex - complex data type used with various mathematical functions.

str - string type used for data consisting of letters and other characters.

list - list data type that can contain different types of data in the same list.

tuple - data type similar to the list data type, but the data can only be read.

dictionary - dictionary data type is a kind of hash table useful for key-value pair data.

Everything You Need to Know About Data Types in Python: Where are char, long, decimal, etc.?

Saturday, June 15, 2024

Learn Programming, Introduction to Python Programming Language

Probably all the visitors of our blog are wondering, what is this now; but you are C# programmers; why are you suddenly interested in the Python programming language? It seems that in the business world, knowing just one programming language has long been insufficient. If you look at the authors of many IT books, you will notice that they have knowledge of many programming languages. It all started with our interest in Visual Studio Code and .NET Core, but that awakened some pleasant memories of when we were involved in hacking and Linux operating systems. That's why we wiped the entire hard drive of our new laptop, which had Windows 10 Professional installed, and instead installed Kali Linux. Then, a whole new world of curiosity and new possibilities opened up to us.

Of course, this doesn't mean that we are abandoning the C# programming language; there is still much to learn and do on this blog, but it's time to turn to other programming languages as well. But why the Python programming language specifically? We will also deal with other programming languages; but we stumbled upon Python while looking for a language that is most commonly used on Linux operating systems. Then we discovered something we hadn't even dreamed of. The syntax and ease of learning the Python programming language, even compared to C#, is incredible.

A Professor Teaches a Student Python

A Professor Teaches a Student Python

The Python programming language is taught the most in many American as well as our schools, it is often declared the favorite programming language of the year, and it is used by many world companies like Facebook, Samsung, Google, YouTube, Yahoo, and others. With the Python programming language, you can easily automate many tasks, it is used for both desktop and Internet applications, and you can even program AI - Artificial Intelligence with it or use it together with other programming languages. Unlike the C# programming language, Python is a high-level interpreted language. This means it is not converted into machine code and therefore runs somewhat slower and does not hide your code.

However, there are tools that can compile your Python program into binaries and eliminate these drawbacks if necessary. The author of this language is Guido van Rossum from the Netherlands, who created it back in the late 80s. Python supports imperative and object-oriented programming styles and comes with an interpreter and a very developed standard library of modules. It supports almost all operating systems; it comes pre-installed on most Linux systems, so you can start programming in the terminal immediately, and the current version is 3.12.

There is a significant difference and incompatibility between versions 3.12 and 2.7, for example, so make sure to always have the latest 3.x version installed. To learn Python, you can use many programming environments as it is exceptionally well-supported, and you can write your programs in any text editor. The choice is entirely up to you. The name Python for this programming language does not come from the name of the snake, but from the Monty Python group, the actors of the British comedy series of the same name. That is why Python programmers are often called Pythonistas.

Setting Up the Environment: What Do You Need to Program in Python?

Wednesday, June 05, 2024

Key Differences in Code Organization, CommonJS and ES6 Module Formats in Node.js

For every beginner starting to learn and use the Node.js platform, regardless of their level of JavaScript knowledge, it can be very confusing that Node.js uses both CommonJS and ES6 module formats. And when you're asked about the ES7 specification of the scripting language, I think that's the first thing that needs to be explained. CommonJS initially emerged as a project to standardize the module ecosystem for the JavaScript programming language outside of web browsers. The CommonJS specification on how modules should work is widely used today for JavaScript on the server-side with the Node.js platform, but it is also used for JavaScript on the client-side. However, that code needs to be bundled with a transpiler since browsers do not support CommonJS. So, CommonJS is an older standard used in the Node.js platform for the module format and is now treated as the default.

Most built-in modules are created in the CommonJS module format. With the advent of ECMAScript 2015, or ES6, the module format became a significant improvement for the entire JavaScript programming language world, as well as for newer versions of the Node.js platform. Today, Node.js supports both CommonJS and ES6 module formats, and although both module formats are conceptually similar, they differ significantly in practice. Regarding the newer ES7 module format in the Node.js platform, such a thing does not exist because ES7 did not bring any new changes to the module format; rather, ES7 mainly focuses on other language features. What will change in the future, we can only speculate for now; but until then, the current support for the Node.js platform relies exclusively on CommonJS and ES6 module formats. The ES6 module format is becoming increasingly popular and a better choice for newer projects, especially in newer Node.js versions, but CommonJS is definitely still in use.

A Programmer Drinks Coffee and Thinks Before Continuing Coding

A Programmer Drinks Coffee and Thinks Before Continuing Coding

Regarding the difference between CommonJS and ES6 module formats in Node.js, the first difference is that CommonJS modules must be loaded from a module repository, such as npm. Secondly, CommonJS modules can only be accessed from the context of a Node.js application. CommonJS modules do not have exports or prototypes like ES6 modules do. Finally, the `require` function in CommonJS is not equivalent to the `import` function in ES6 modules. The main difference between CommonJS and ES6 modules is the folder structure. With CommonJS, all project dependencies are stored in a single folder called `node_modules`. With ES6 modules, each dependency is stored in its own files. This allows developers to better control how their dependencies are used and facilitates software versioning. But you should also know that CommonJS is a module system inspired by Microsoft’s AMD API.

It allows modules to be written similarly to AMD modules, with the main difference being that CommonJS modules can be loaded in any Node.js environment. ES6 modules are a new module system developed by Google that enables greater modularity and reusability across different programming languages. The advantage of using ES6 modules is that they can be translated into native code, making them faster and more efficient than CommonJS modules. However, the most important thing for any beginner regarding the Node.js platform is simply that CommonJS supports dynamic module loading, meaning you can import modules during program execution. Module loading in CommonJS is synchronous, which means it is blocking. This can lead to performance issues in some situations. Variables defined within a module are private and invisible outside the module, achieving local scope.

However, ES6 represents a significant update to the JavaScript programming language, bringing numerous new functionalities and improvements. Notably, arrow functions provide a shorter and more readable way to define functions while maintaining the value of `this` within the function to the value that was current when the function was defined. ES6 allows for the destructuring of objects and arrays to easily extract data and also introduces promises for better handling of asynchronous operations instead of using callback functions. We could list differences endlessly, but it’s best to recognize them through practice and using both module formats in Node.js.

Step by Step: How to efficiently port CommonJS code to ES6 modules

Building Node.js Modules, From Concept to Implementation

If you have familiarized yourself with what Node.js is and what it isn't, take a look here; and if you have already installed Node.js on your computer; completed lesson 1; created a small Hello World program. Additionally, if you are using a Linux operating system, such as the Ubuntu distribution, even on a virtual machine, and you have Visual Studio Code installed; then you are definitely ready to learn and code in the JavaScript programming language globally using the Node.js platform. We say globally because not every JavaScript code will work on the Node.js platform. Some things are coded differently. Yes, it is true that you can follow our Node.js tutorial on any operating system; similarly, instead of Visual Studio Code, you can use any IDE - Integrated Development Environment, our recommendation remains Ubuntu and Visual Studio Code.

Of course, the choice is always yours. Unlike various frameworks, when we talk about Node.js, we are talking about a platform, more precisely a multi-platform environment. The Node.js platform allows us to execute JavaScript programming language on the server side or completely outside of the web browser. Node.js has an event-driven architecture capable of performing asynchronous input and output. Which essentially also means that the entire Node.js ecosystem is based on modules through which such events are executed. But what are modules? You can easily understand modules as smaller building blocks of code that divide an application into smaller parts or can even be used in entirely different parts of a program and other programs.

A Programmer Create Node.js Modules

A Programmer Create Node.js Modules

Modules in the Node.js platform mostly contain some functionality coded in the JavaScript programming language, but in such a way that they hide the implementation and provide an explicitly declared API - Application Programming Interface for the module. There are two basic types of modules in Node.js. The first is built-in or Core modules, while the second is non-standard or Custom modules. When it comes to built-in modules, they can also be produced by various other manufacturers. Built-in modules are usually installed into the project you are working on, and the installed module is called a package.

The npm package repository is a vast library of modules available to you to create and develop your Node.js application more easily, better, and faster. As for non-standard modules, you can create and use them in your own project. These modules are user-defined and are not built into Node.js by default. They are used when you want to organize your code into multiple files for better readability and maintenance. However, you can also publish your own packages, which other developers can then use. When Node.js was created, the ES6 module format did not exist, and only the CommonJS module format was used.

Today, both are used. You can recognize the ES6 module format by the *.mjs file extension, although Node.js can be configured to recognize *.js files as ES6 module format. Both types of modules are conceptually similar but differ significantly in practical terms. Working with modules in Node.js is a vast concept that extends throughout the entire Node.js tutorial, and only through practical work with many lessons will you gain a true insight into modules in Node.js. Therefore, consider this lesson just the beginning of the journey through modules in Node.js. It's time to move to the practical level and, through small practical steps, get to know the great possibilities and features that Node.js offers.

From scratch to modules: How to create and run your first Node.js module?

Monday, June 03, 2024

Node.js from Scratch, Getting Started with Backend Development

What is Node.js? Before we answer this question, it’s better to first clarify what it is not. Node.js is not an enhanced JavaScript programming language, nor is it a framework for JavaScript developers. In short, Node.js is a platform for developing web applications, application servers, any type of network server or client, and a general-purpose development environment based on JavaScript that executes on the server side and is built on asynchronous events. When we say platform, we mean much more than a platform; we mean cross-platform, which has no equivalent translation for many foreign languages, but it means that Node.js works on different operating systems like Windows, MacOS, Linux, and others.

It is an open-source platform, of course, free under the MIT license. It is a platform that is not a framework; frameworks are just a part of this platform, like Express.js. With Node.js, you create highly scalable and highly performant web applications. It is a wrapper around the Chrome V8 browser engine. With Node.js, you can easily create desktop GUI applications in JavaScript. Visual Studio Code, Atom, Postman, etc., are based on Node.js. It is also very popular for developing micro servers and in the world of IoT - Internet of Things. It is simply incredible how powerful this platform is, how it simplifies complexity, and what you can do with it; we simply don’t know how to explain all this in brief to a programming beginner.

Node.js is otherwise intended for experienced programmers who are proficient in coding applications, developing web applications, and knowing the JavaScript programming language. But there is no need for this to discourage you; you will just have to roll up your sleeves much more than when you are learning the JavaScript programming language. Even if you know JavaScript, it doesn’t mean you can fully use all JavaScript commands in Node.js. For example, this simply won't work in Node.js:


Simply put, HTML DOM is not built into Node.js. You cannot use the document or window objects. Instead of this line of code, you would use Puppeteer, a Node.js library that provides a high-level API. But, not to complicate things now, Node.js is also not a new programming language; it uses the JavaScript programming language but does some things differently.

Node.js Application

 Node.js Application

If we go back in time, to 1995, a new programming language called LiveScript appeared under the code name Mocha. But due to the popularity of the Java programming language, it was renamed JavaScript. On May 27, 2009, Node.js was released. The Java programming language has the motto "Write once, run anywhere!" And now, Node.js has the motto "JavaScript for everything!" It's clear that both programming languages tend to be used everywhere. Node.js made it possible for JavaScript to overcome some limitations of the Java programming language in such a way that you can use the Java programming language within Node.js.

Do you now understand the capabilities of Node.js we are talking about here? As early as 2009, Node.js literally gave wings to the JavaScript programming language, allowing JavaScript to be executed on the server side and outside the scope of any browser, which is not the case with the JavaScript programming language itself. Node.js is an extremely popular choice for creating and developing command-line tools used in software development. Babel is often used to transpire modern ES-2016 code to run old code for viewing on older browsers. Node.js allows you to easily test web user interfaces.

The Puppeteer library provides control over a headless instance of the Chrome web browser. Electron and NW.js are frameworks for developing desktop applications on Windows, MacOS, and Linux operating systems. Applications use HTML5, CSS3, JavaScript, and frameworks like Bootstrap, React, Vue.js, or AngularJS. With Node.js, you can also create mobile applications. But note that Apple's App Store rules do not allow JIT capabilities. Regarding IoT - Internet of Things; Node.js runs on most computers that support ARM.

What Makes Node.js So Special: Benefits That Can Change Your Approach to Programming

Thursday, May 30, 2024

Data Integrity, Implementation of Relations in Microsoft SQL Server

In the database domain, relationships - often called dependencies - essentially contribute to data integrity. In mathematics, relations are subsets that are not empty and are part of the Cartesian product of sets. However, when talking about databases, the term "relationships" is less often used unless you are talking to fellow experts. Despite the similarities, the mathematical relationships and those in MSSQL - Microsoft SQL Server differ significantly. Instead of storing all the data in one table, consider creating multiple tables and linking them using relationships. This approach offers significant advantages, especially in terms of data integrity. In this way, you minimize empty fields in tables and data redundancy.

The best database administrators and developers follow the golden rule: "Enter data once, but use it as many times as necessary." This principle applies to database records. For example, imagine that you have to enter customer first and last names into multiple tables - this would take a lot of time and your tables could become unwieldy. Thanks to the relationships between the tables, you can enter the customer's first and last name only once, and then use that data in other tables where necessary. This simplifies data entry, speeds up tasks and ensures a more professional workflow. Your tables become more concise, with fewer empty fields and less duplicate data. Even if you create more tables, maintaining and hosting your database becomes easier.

Moreover, relationships make life easier for developers and all users of your database. Therefore, it is crucial to have the experience and talent to accurately translate business logic into tables and their relationships. Examples such as the Northwind or AdventureWorks databases serve as excellent 
models for understanding relationships. You can download them here. If you are new to database design, I recommend installing these sample databases for learning purposes. Start by exploring the relationships between the tables within these databases. Remember that as a developer you can't always 
rely on database administrators to create your tables, you have to master this skill yourself.

Data Integrity - Relations

Data Integrity - Relations

In database design, relationships between tables play a crucial role in maintaining data integrity. Let’s explore the common types of relationships:

One-to-One (1:1): In a one-to-one relationship, each record in one table corresponds to exactly one record in another table. This type of relationship is relatively rare but can be useful for scenarios where data needs to be split into separate tables for organizational or security reasons. For example, consider a database where each employee has a unique employee ID, and there is a separate table for storing sensitive employee information such as salary details. 

One-to-Many (1:N): In a one-to-many relationship, each record in one table can be associated with multiple records in another table. This is the most common type of relationship. For instance, in an e-commerce database, each customer can have multiple orders, but each order belongs to only one customer.

Many-to-Many (N:N): In a many-to-many relationship, multiple records in one table are related to multiple records in another table. To implement this relationship, an intermediary table, often called a junction or bridge table is used. For example, consider a music library database where songs can belong to multiple playlists, and each playlist contains multiple songs. Choosing the right type of relationship depends on the specific requirements of your application. Consider factors such as data redundancy, performance, and ease of querying when designing your database schema.

Unlike Microsoft Access, which provides a graphical interface for managing relational databases, Microsoft SQL Server relies on the Database Diagrams tool. It’s essential to create at least one diagram in your database to visualize all tables and their relationships. These diagrams help you understand the database structure and ensure data consistency. You can add tables to the diagram, define relationships, and manage them using the Database Diagrams feature. Additionally, you can create relationships using T-SQL language commands directly in your SQL scripts. Remember that well-designed relationships contribute to efficient data management, reduced redundancy, and improved query performance.

One to One Relationships: Theory and Implementation in Practice

Monday, May 20, 2024

Microsoft SQL Server, Basics of Working with Tables

When you create a database, the first thing you need to do is to think carefully about what information your database needs to contain and how that information should be stored in tables. Your ability to discern which information to store in the database, which not; some can be recalculated; and how to properly arrange them in tables so that they can be properly connected and used is primarily a professionalism of years of experience working with databases. That’s why this job in companies is not left to just anyone but to professional database administrators. But that doesn’t mean they will make tables for you when you need them.

You as a developer must be able to professionally build an entire database with all objects at any time of day or night and properly connect it to your application that you are programming. Otherwise, even the smallest irregularity in your database can cause fatal errors, ruin all your programming work, and cost you dearly. Therefore, being a programmer without professional knowledge of working with databases is like being a lifeguard who can’t swim in a pool. Another important thing to understand is that strict rules when creating everything related to databases cannot be ignored. Instead, all rules must be known and applied in the best possible way with every business segment. And no, it’s not a question of what database administrators will do if you as a developer also create databases; they have work to do even when your database functions excellently.

Microsoft SQL Server, Creating Tables

Microsoft SQL Server, Creating Tables

Each table consists of columns and rows. Sometimes columns are also called fields. Each table must have a different name from other tables in the database, but similarly, each column in the table must have a different column name within that table. You can have the same column name if they are in different tables. For each table, you need to set the data type attribute for each column. A column can only contain one data type, and you can only enter data into that column that corresponds to that data type. The data type simply determines what kind of data can be stored in the column. SQL data types are similar to variable types in programming languages, but some differ. In SQL, you can create your own data types, although you don’t usually need to.

Before you familiarize yourself with data types, for almost every table you create, you need to define one column as the primary key or, in most cases, create a special column, often the first column, specifically for generated integers. This column automatically increments by 1 each time a new row is created in the table, and you designate it as the primary key. You can enter the same data into a column if you haven’t restricted the column to disallow duplicates, but you can’t do that with a column that you want to set as the primary key. With such a unique column, one that cannot contain empty values or duplicates, simply put, by using the primary key, you uniquely identify a row in the table.

Your primary key should be short, stable, and straightforward to facilitate faster and easier searching of all data in the table. Therefore, it’s not a good solution to use a string-type column as your primary key; instead, consider using a positive integer or a UNIQUEIDENTIFIER column which, again, consumes more memory than an Int type. Your table can also contain other columns defined as foreign keys. Even alongside a primary key, you can have multiple columns defined as foreign keys, but more about foreign keys and table relationships will be discussed in the next lesson of this tutorial. For now, focus exclusively on creating tables and thoroughly studying SQL data types.

Different data types in Microsoft SQL Server and their allowed values