This book has been written with utmost care keeping in view of the young readers in the world of programming. This books is not just on V Programming, but will help you gain understanding of the foundational concepts of programming such as primitive data types, variables, constants, functions, structs and modules.
That’s not all! If you have trouble understanding the concept of concurrency, I strongly recommend you to give the chapters related to concurrency a try. There has been a tremendous effort made to explain concurrency with the help of a utter simple real-world use case.
For advanced readers or those who has grasp of other programming languages such as Go, Python, C Sharp or Rust, the learning curve is significantly shorter to get you started with V Programming.
This book also includes a bonus chapter Building a Microservice, that comes with an end-to-end demonstration of implementing a RESTful microservice using V Programming.Navule Pavan Kumar Rao, Author of Getting Started with V Programming
Table of Contents
- Getting Started with V Programming
- Who This Book Is For
- Key Features
- Book Description
- What you will learn
- Sections in this book
- Section 1: Introduction to the V Programming Language
- Section 2: Basics of V Programming
- Section 3: Advanced Concepts in V Programming
- Table of Contents
- What this book covers
Getting Started with V Programming
Learn a new statically typed compiled programming language to build maintainable and fast software with the help of this comprehensive guide to V programming.
V programming comes with high performance and simplicity, which allows software programmers to do quick and rapid prototyping of applications at scale.
Who This Book Is For
This book is for you if you are:
- a beginner who is interested in learning a programming language that comes with a quick and short learning curve
- an experienced programmer who is looking to switch to a new and better statically typed and compiled programming language
- willing to write quick and rapid prototyping of applications that scale using a new language with powerful concurrency features
Following are the key features of this book:
- Explore the features of the V programming language step by step with this beginner’s guide
- Gain strong foundational knowledge of core programming concepts such as arrays, maps as well as structs, functions and modules
- Gain concrete understanding and working knowledge of concurrency in V and channels: An advanced concurrency pattern
- Learn how to write super-fast programs and applications that compile in a matter of seconds
- Learn how to implement a RESTful microservice from the scratch
A new language on the block, V comes with a promising set of features such as fast compilation and interoperability with other programming languages. This is the first ever book on the V programming language, packed with concise information and a walk through of all the features you need to know to get started with the language.
The book begins by covering the fundamentals to help you learn about the basic features of V and the suite of builtin libraries available within the V ecosystem. You’ll become familiar with primitive data types, declaring variables, arrays, and maps. In addition to basic programming, you’ll develop solid understanding of the building blocks of programming, including functions, structs, and modules in the V programming language.
As you advance through the chapters, you’ll learn how to implement concurrency in V Programming. Also you will learn about an advanced concurrency pattern, Channels, which enables you to share memory by establishing communication among coroutines.
Finally, you’ll learn how to write test cases for functions in V. This book also comes with an end-to-end project that will guide you to build fast and maintainable RESTful microservice by leveraging the power of V and a bunch of built-in libraries in V.
By the end of the book, you’ll be well-versed with the V programming language and be able to start writing your own programs and applications.
What you will learn
This book will help you to:
- Become familiar with the basic building blocks of programming in the V language
- Install the V language on various operating systems
- Get started with absolute basics such as variables, constants and primitive data types in V programming
- Understand how to work with arrays and maps in V programming
- Get well-versed with writing modular code along with knowledge of structs and functions in V programming
- Discover how to implement concurrency in V programming
- Know about the best practice of sharing memory by communicating among coroutines using channels in V programming
- Get acquainted with writing tests in V programming
- Get to grips with building and querying RESTful microservice in V programming
Sections in this book
Section 1: Introduction to the V Programming Language
This section provides a detailed introduction to the V programming language. You will also gain an understanding of various features of V and the suite of modules and libraries available within the V ecosystem.
This section also introduces you to approaches to install the V programming language on the various operating systems, which will help readers get started with hands-on examples that will be covered in this book.
This section has the following chapters:
- Chapter 1, Introduction to V Programming
- Chapter 2, Installing V Programming
Section 2: Basics of V Programming
This section focuses on the basics of V programming. You will gain an understanding of the basic programming principles, such as primitive data types, declaring variables, constants, and adding code comments. You will also get an in-depth understanding of primitive data types in V and learn the usage of various operators, such as arithmetic, logical, bitwise, shift, and relational operators. In addition, this section also covers basic data structures in V such as arrays and maps.
You will also learn about writing conditional statements using if and match, and then you will learn different ways of writing iterative statements using for loops. In addition to basic programming, you will gain additional knowledge of the building blocks of programming, such as functions, structs, and modules in the V programming language.
This section has the following chapters:
- Chapter 3, Variables, Constants, and Code Comments
- Chapter 4, Primitive Data Types
- Chapter 5, Arrays and Maps
- Chapter 6, Conditionals and Iterative Statements
- Chapter 7, Functions
- Chapter 8, Structs
- Chapter 9, Modules
Section 3: Advanced Concepts in V Programming
This section covers advanced concepts in V that include writing highly concurrent code, where you will learn about the go keyword and its usage as well as the thread data type. This section will provide detailed info about various concurrency patterns that enable you to share data between concurrent routines using locks and also has a detailed chapter on an advanced concurrency pattern called Channels. In the detailed chapter on Channels, you will learn how to share data by establishing communication among concurrently running routines in V.
The last chapters of this section focus on writing tests in V. In addition to this, you will be introduced to the built-in libraries JSON and Object Relational Mapper (ORM) and we’ll cover building an end-to-end project having a RESTful microservice using the vweb web server.
This section has the following chapters:
- Chapter 10, Concurrency
- Chapter 11, Channels – An Advanced Concurrency Pattern
- Chapter 12, Testing
- Chapter 13, Introduction to JSON and ORM
- Chapter 14, Building a Microservice
Table of Contents
- Introduction to V Programming
- Installing V Programming
- Variables, Constants and Code Comments
- Primitive data types
- Arrays and Maps
- Conditionals and Iterative Statements
- Channels: An advanced concurrency pattern
- Introduction to JSON and ORM
- Building a Microservice
What this book covers
Chapter 1, Introduction to V Programming, introduces the V programming language and its features. It also looks at the past, present, and future of V. Learn about the cross-compatibility of V and the list of operating systems V runs on.
Chapter 2, Installing V Programming, offers step-by-step details that will help you learn how to install the V programming language on Windows OS and *nix OS. You’ll also learn how to ensure V is added to environment variables on Windows OS and creating symbolic links on *nix OS, which will facilitate you accessing V from any directory.
Chapter 3, Variables, Constants, and Code Comments, introduces you to basic programming concepts such as how to define and work with variables and constants in V. This chapter also covers how to add single- and multi-line comments in V.
Chapter 4, Primitive Data Types, acquaints you with the world of primitive data types. You’ll come to understand various primitive data types in V such as string, bool, rune, and other numeric types. You’ll also learn how to work with these types. This chapter also introduces you to the various operators you can use on these data types such as relational, logical, arithmetic, bitwise, and shift operators. If you are an absolute beginner to the world of software programming, this chapter is highly recommended to get you hands-on with the concepts related to the primitive data types that are similar in all other programming languages.
Chapter 5, Arrays and Maps, covers different ways to declare arrays and how to initialize them using various properties available to define an array. You’ll also see how to use in and << operators on arrays. We then walk through the details about working with fixed-size arrays and multi-dimensional arrays. You will also understand arrays by performing the most frequently performed operations on arrays, such as cloning, sorting, and filtering techniques.
You will also learn about maps that hold data in the form of key-value pairs. Maps in the V language are often referred to as dictionaries in other programming languages, such as C# and Python. You will learn how to work with maps, and understand various ways we can declare and initialize maps. You will also learn how to perform various operations on a map, such as retrieving the key-value pair given a key, and handling the retrieval of non-existent keys using or block. Then you will see how to add, update, and delete key-value pairs from a map.
Chapter 6, Conditionals and Iterative Statements, looks in detail at conditionals and iterative statements in the V programming language. You’ll learn about working with conditional blocks such as
if-else, and chaining
else-if along with the usage of
goto statements supported by labels. You will also learn in depth about
match blocks, which is used for use cases that involve pattern matching or conditional code branching. In the later parts of this chapter, we will look at the various types of operations performed on maps, arrays using
for loops, and then you will see the different ways to write iterative statements using a
Chapter 7, Functions, introduces the various types of functions V offers. You will then be able to write basic functions, anonymous functions, and higher-order functions. This chapter will also guide you through vast features that functions come equipped with, along with code examples for each feature.
Chapter 8, Structs, looks at how to write structs that involve struct fields having different access modifiers and also defining struct fields with default values. You will then learn the skill of defining and initializing structs. You will then have a fair understanding of how to add methods that belong to a struct and create and work with functions with structs as input arguments.
Chapter 9, Modules, first introduces the basic syntax to define and import modules. In the later sections, you will see how to create a simple project in V, and then learn how to create and import modules defined in our simple project. You will then learn how to create multiple files and work with those in a module and understand the access scope.
You will also learn about best practices that include the benefits of the initializer function and conditions to define the initializer function for a module. This chapter also covers problems that arise in V when we have cyclic imports while creating modules. In addition, you will to understand member scopes and the accessibility of members, including constants, structs, and embedded structs across modules. By the end of this chapter, you will be well-versed in the concept of modules and how to leverage them while writing programs in V.
Chapter 10, Concurrency, looks at concurrency, which is a crucial topic when it comes to V. The main essence of V lies in the concurrency capabilities that it offers programmers. In this chapter, you will learn in depth about the concept of concurrency, along with detailed code examples. This chapter begins with an explanation of a simple real-life scenario, which is about performing daily morning routines. The chapter also looks at a comparison of the results of the tasks when they were performed
sequentially, and the benefits when similar tasks are performed concurrently.
In addition to the more intuitive explanation on concurrency in this chapter, the chapter sets foundational knowledge on concepts such as time modules and thread types to get started with concurrent programming in V.
By the end of this chapter, you will be confident enough to write concurrent code in V using the
go keyword and handling concurrent functions using
thread types. You will be able to understand the benefit of writing concurrent code in contrast to sequential code. This chapter will also help you understand how to concurrently spawn void functions, functions that return values as well as anonymous functions. You will also learn how to share data between the main thread and the tasks that are spawned to run concurrently using locks.
Chapter 11, Channels – An Advanced Concurrency Pattern, covers Channels, which is the advanced concurrency pattern in V. They solve the problem of explicitly handling data synchronization techniques among coroutines. In the context of concurrency, channels facilitate us to share data by establishing a communication channel between concurrent tasks. These concurrent tasks are often termed coroutines, which share the data by communicating through channels.
We can communicate between coroutines with the help of shared objects. But the problem with this approach is you need to take explicit care of concurrency synchronization techniques such as protecting the shared objects using locks such as the read-only
rlock or the read/write
lock to prevent data races. This is where channels in V come into the picture. Channels implicitly take care of all the aforementioned data synchronization techniques among coroutines, which otherwise are cumbersome to manage manually.
In this chapter, we begin by looking at the syntax to declare channels and then understand different types of channels, such as buffered and unbuffered channels. We then learn about the properties of channels. Later, we learn about various methods available on a channel. Then we proceed to the end of chapter where we learn about channel select.
Chapter 12, Testing, covers how to write test cases for functions in V. This chapter also covers what the minimum prerequisites are for your code and file structure in order for V to identify and run them as tests.
When building data-driven applications, Object Relational Mappers (ORMs) become a crucial part to establish communication between the world of objects and the world of relational databases. This chapter also introduces the built-in library orm, which ships along with the V installer.
Chapter 14, Building a Microservice, looks at how to build a simple microservice in V using a RESTful approach. To achieve the implementation, you will be using the built-in libraries
orm. You will also leverage the power of SQLite, by installing it as a third-party library. With the help of the SQLite library, you will learn how to establish a database connection and interact with it. You will use the JSON data format as a form of communication.