Getting Started with V Programming: An end-to-end guide to adopting the V language from basic variables and modules to advanced concurrency
- Length: 408 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2021-12-10
- ISBN-10: 1839213434
- ISBN-13: 9781839213434
- Sales Rank: #957611 (See Top 100 Books)
Learn a new statically compiled programming language to build maintainable and fast software with the help of this comprehensive guide to V programming
Key Features
- 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 modules, functions, and structs
- Learn how to write super-fast programs and applications that compile in a matter of seconds
Book Description
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 book on the V programming language, packed with concise information and a walkthrough 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 built-in 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 a 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, and finally learn how to write test cases for functions. This book takes you through an end-to-end project that will guide you to build fast and maintainable RESTful microservices by leveraging the power of V and its built-in libraries.
By the end of this V programming 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
- Become familiar with the basic building blocks of programming in the V language
- Install the V language on various operating systems
- Understand how to work with arrays and maps in V programming
- Discover how to implement concurrency in V programming
- Understand best practices of sharing memory by letting coroutines communicate with each other using channels in V
- Write modular code and build on your knowledge of structs and functions in V
- Get acquainted with writing tests in V programming
- Get to grips with building and querying RESTful microservice in V
Who this book is for
Whether you’re a beginner interested in learning a programming language or an experienced programmer looking to switch to a new and better statically compiled programming language, this V programming book is for you.
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
- Functions
- Structs
- Modules
- Concurrency
- Channels: An advanced concurrency pattern
- Testing
- Introduction to JSON and ORM
- Building a Microservice
B15555_14_ForIndexing_VR Getting Started with V Programming: An end-to-end guide to adopting the V language from basic variables and modules to advanced concurrency 1 Introduction to V Programming The past, present, and future of V V is a statically typed and compiled programming language Simple and maintainable syntax Backward compatibility, stability, and easy to upgrade to future versions Features of V programming Performance Speed No null values No global variables No undefined values Error handling Powerful concurrency Easy cross-compilation V to JavaScript conversion Profiling V as a framework Memory management using the autofree engine Inbuilt ORM Built-in web server Native cross-platform GUI library Vinix – an operating system/kernel written in V Operating systems V supports Summary 2 Installing V Programming Technical requirements Installing V on Windows OS Approach 1 – installing V from portable binaries on Windows OS Approach 2 – installing V from source on Windows OS Adding V to environment variables in Windows OS Accessing V programming using REPL Installing V on Linux OS (Ubuntu) Using Symlink V to make V accessible globally in Ubuntu Summary 3 Variables, Constants, and Code Comments in V Technical requirements Understanding variables in V The variable naming convention Variable assignment Features of variables in V The limitations of variables in V Working with constants in V Naming conventions for constants Defining constants Defining complex constants Best practices when working with constants Variables versus constants Adding code comments in V Single-line comments Multiline comments Summary 4 Primitive Data Types in V Technical requirements Introducing primitive data types The Boolean data type Logical operators Relational operators Numeric data types Signed and unsigned integers Floating-point types Promoting numeric types Operations on numeric data types Arithmetic operators Bitwise operators Shift operators The string data type Working with the string data type The rune data type Operations on the string data type String interpolation String manipulation techniques Summary 5 Arrays and Maps in V Technical references Arrays Different methods to declare arrays Working with the len and cap array properties Accessing array elements using the index Accessing array elements using slices Operators used with arrays Fixed-size arrays Multidimensional arrays Performing various operations on an array Maps The explicit initialization of a map The short syntax initialization of a map The count of key-value pairs in a map Retrieving a value given the key of a map Accessing a non-existent key from a map Handling the retrieval of missing keys in a map Updating the value of the key in a map Deleting a key-value pair from a map Summary 6 Conditionals and Iterative Statements Technical requirements Conditional blocks The if statement match Iterative statements A for loop on maps A for loop on arrays A for loop without index on array A traditional C-style for loop A reverse for loop A for loop on a range A bare for loop or an infinite for loop Using break in a for loop Using continue in a for loop Using the continue and break statements with labels Summary 7 Functions in V Technical requirements Introducing functions Understanding function types The main function Basic functions Anonymous functions Higher-order functions Understanding function features Functions can return values or simply perform operations Functions can take zero or more input arguments Functions can return multiple values Ignoring return values from functions Functions can call other accessible functions Functions allow only arrays, interfaces, maps, pointers, and structs as mutable arguments Function declarations in script mode should come before all script statements Functions do not allow access to module variables or global variables Functions do not allow default or optional arguments Functions can have optional return types Functions are private by default and can be exposed to other modules using the pub access modifier keyword Functions allow you to defer the execution flow using the defer block Functions can be represented as elements of an array or a map Summary 8 Structs Technical requirements Introducing structs Defining a struct Initializing a struct Accessing the fields of a struct Understanding heap structs Updating the fields of a struct Approaches to defining struct fields Adding multiple mutable fields to a struct Grouping fields in a struct using access modifiers Defining required fields in a struct Defining struct fields with default values Defining methods for a struct Adding a struct as a field inside another struct Modifying the fields of a struct type inside another struct Structs as trailing literal arguments to a function Summary 9 Modules Technical requirements Introducing modules The syntax to define a module The syntax to import a module Working with modules Creating a simple V project Creating a module Importing a module Accessing members of a module Working with multiple files in a module Member scope in the module Implications of cyclic imports The init function for a module Accessing the constants of a module Accessing structs and embedded structs of a module Summary 10 Concurrency Technical requirements Introducing concurrency Understanding parallelism Learning the basic terminology Getting started with concurrency Understanding the time module Understanding the thread type Implementing concurrency in V go keyword syntax Spawning a void function to run concurrently Waiting on a concurrent thread Implementing a real-life concurrency scenario programmatically Running multiple tasks in a sequence Spawning multiple tasks to run concurrently Comparing sequential and concurrent program runtimes Learning different approaches to implement concurrent programs Spawning functions with return values to run concurrently Spawning anonymous functions to run concurrently Spawning anonymous functions that have no input arguments Spawning anonymous functions that accept input arguments Sharing data between the main thread and concurrent tasks Summary 11 Channels – An Advanced Concurrency Pattern Technical requirements Syntax to define a channel Unbuffered channel Buffered channel Channel operations Arrow operator <- Push operation Pop operation Channel properties Understanding channel properties using examples Channel methods Using try_push() on unbuffered channels Using try_push() on buffered channels try_pop() close() Working with unbuffered channels Understanding the blocking nature of unbuffered channels Dealing with the blocking behavior of unbuffered channels Synchronizing data between coroutines that communicate via an unbuffered channel Working with buffered channels Understanding the behavior of a buffered channel Establishing buffered communication channel between coroutines Synchronizing data between coroutines that communicate through a buffered channel Channel select Summary 12 Testing Technical requirements Introduction to tests in V The assert keyword Writing a simple test Running tests Understanding testsuite functions Demonstrating the usage of testsuite functions The AAA pattern of writing tests Writing tests for functions with optional return types Approaches to writing and running tests Writing tests for a simple program Running tests contained in _test.v file Writing tests for a project with modules Running tests contained in a module Writing tests for members of a sub-module from the main module Running all the tests contained in a project Running tests with stats Summary 13 Introduction to JSON and ORM Technical requirements Getting started with JSON Decoding a JSON object Encoding an object into JSON data Getting started with ORM Understanding ORM attributes Creating a struct for ORM Working with the ORM library Briefly understanding database operations using V's ORM Performing DDL operations using V's ORM Performing DML operations using V's ORM Summary 14 Building a Microservice Technical requirements Introducing vweb Creating a project and organizing files Setting up the vweb web server Setting up utility functions and constants for the microservice Implementing RESTful endpoints The list of RESTful endpoints in our microservice Defining the Note struct Implementing an endpoint to create a note using HTTP verb POST Defining the route to create a note Processing requests and handling custom responses for the create endpoint Inserting a record using the ORM query Building a response body for the create endpoint Implementing an endpoint to retrieve a note by id using HTTP verb GET Defining a route to retrieve a note by id Selecting a record given its id using the ORM query Handling a custom response for the read a note endpoint Building a response body for the read endpoint Implementing an endpoint to retrieve all notes using HTTP verb GET Defining a route to retrieve all notes Selecting all the records from a table using the ORM query Building a response body for the read all notes endpoint Implementing an endpoint to update a note using HTTP verb PUT Defining a route to update a note by id Processing requests and handling custom responses for the update endpoint Verifying a record exits given its id using the ORM query Verifying the uniqueness of the message field of note Updating the record using the ORM query Building a response for the update endpoint Implementing an endpoint to delete a note using HTTP verb DELETE Defining the route to delete a note by id Deleting a record given its id using the ORM query Building a response for the delete endpoint Running the microservice Querying REST endpoints using Postman Using Postman to create a note with the POST HTTP verb Using Postman to retrieve a note by id with the GET HTTP verb Using Postman to retrieve a collection of notes with the GET HTTP verb Using Postman to update a note with the PUT HTTP verb Using Postman to delete a note with the DELETE HTTP verb Summary
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Getting Started with V Programming: An end-to-end guide to adopting the V language from basic variables and modules to advanced concurrency
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.