Nim in Action
Dominik Picheta
  • August 2017
  • ISBN 9781617293436
  • 320 pages
  • printed in black & white

A great resource for an incredibly powerful language.

Jonathan Rioux, TD Insurance

Nim is a multi-paradigm language that offers powerful customization options with the ability to compile to everything from C to JavaScript. In Nim in Action you'll learn how Nim compares to other languages in style and performance, master its structure and syntax, and discover unique features.

About the Technology

Nim is a multi-paradigm programming language that offers powerful customization options with the ability to compile to everything from C to JavaScript. It can be used in any project and illustrates that you don't have to sacrifice performance for expressiveness!

About the book

Nim in Action is your guide to application development in Nim. You'll learn how Nim compares to other languages in style and performance, master its structure and syntax, and discover unique features. By carefully walking through a Twitter clone and other real-world examples, you'll see just how Nim can be used every day while also learning how to tackle concurrency, package finished applications, and interface with other languages. With the best practices and rich examples in this book, you'll be able to start using Nim today.

Table of Contents detailed table of contents

Part 1: The basics of Nim

1. Why Nim?

1.1. What is Nim?

1.1.1. Use cases

1.1.2. Core features

1.1.3. How does Nim work?

1.2. Nim's benefits and shortcomings

1.2.1. Benefits

1.2.2. Areas where Nim still needs to improve

1.3. What you will learn

1.4. Who is this book for?


2. Getting started

2.1. Nim syntax

2.1.1. Keywords

2.1.2. Indentation


2.2. Nim basics

2.2.1. Basic types

2.2.2. Defining variables and other storage

2.2.3. Procedure definitions

2.3. Collection types

2.4. Control flow

2.5. Exception handling

2.6. User defined types

2.7. Summary

Part 2: Nim in practice

3. Writing a chat application

3.1. The architecture of a chat application

3.2. Starting the project

3.3. Retrieving input in the client component

3.4. Implementing the protocol

3.4.1. Modules

3.4.2. Parsing JSON

3.4.3. Generating JSON

3.5. Transferring data using sockets

3.5.1. What is a socket?

3.5.2. Asynchronous input/output

3.5.3. Transferring data asynchronously

3.6. Summary

4. A tour through the standard library

4.1. Another look at modules

4.1.1. Namespacing

4.2. Overview of the standard library

4.2.1. Pure modules

4.2.2. Impure modules

4.2.3. Wrappers

4.2.4. Online Documentation

4.3. The core modules

4.4. Data structures and algorithms

4.4.1. The tables module

4.4.2. The sets module

4.4.3. The algorithms

4.4.4. Other modules

4.5. Interfacing with the operating system

4.5.1. Working with the file system

4.5.2. Executing an external process

4.5.3. Other operating system services

4.6. Understanding and manipulating data

4.6.1. Parsing command-line arguments

4.6.2. Conclusion

4.7. Networking and the Internet

4.8. Summary

5. Package management

5.1. The Nim package manager

5.2. Installing the Nimble package manager

5.3. The nimble command-line tool

5.4. What is a Nimble package?

5.5. Installing Nimble packages

5.5.1. Using the install command

5.5.2. How does the install command work?

5.6. Creating a Nimble package

5.6.1. Choosing a name

5.6.2. A Nimble package's directory layout

5.6.3. Writing the .nimble file and sorting out dependencies

5.7. Publishing Nimble packages

5.8. Developing a Nimble package

5.8.1. Giving version numbers meaning

5.8.2. Storing different versions of a single package

5.9. Summary

6. Parallelism

6.1. Concurrency vs. Parallelism

6.2. Using threads in Nim

6.2.1. The threads module and GC safety

6.2.2. Using thread pools

6.2.3. Exceptions in threads

6.3. Parsing data

6.3.1. Understanding the Wikipedia page counts format

6.3.2. Parsing the Wikipedia page counts format

6.3.3. Processing each line of a file efficiently

6.4. Parallelising a parser

6.4.1. Measuring the execution time of sequential_counts

6.4.2. Parallelising sequential_counts

6.4.3. Type definitions and the parse procedure

6.4.4. The parseChunk procedure

6.4.5. The parallel readPageCounts procedure

6.4.6. The execution time of parallel_counts

6.5. Dealing with race conditions

6.5.1. Using guards and locks to prevent race conditions

6.5.2. Using channels so threads can send and receive messages

6.6. Summary

7. Building a Twitter clone

7.1. Architecture of a web application

7.1.1. Routing in microframeworks

7.1.2. The architecture of Tweeter

7.2. Starting the project

7.3. Storing data in a database

7.3.1. Setting up the types

7.3.2. Setting up the database

7.3.3. Storing and retrieving data

7.3.4. Testing the database

7.4. Developing the web application's view

7.4.1. Developing the user view

7.4.2. Developing the general view

7.5. The controller

7.5.1. Implementing the /login route

7.5.2. Extending the / route

7.5.3. Implementing the /createMessage route

7.5.4. Implementing the user route

7.5.5. Adding the Follow button

7.5.6. Implementing the /follow route

7.6. Deploying the web application

7.6.1. Configuring Jester

7.6.2. Setting up a reverse proxy

7.7. Summary

Part 3: Advanced concepts

8. Interfacing with other languages

8.1. Nim's Foreign Function Interface

8.1.1. Static vs. Dynamic linking

8.1.2. Wrapping C procedures

8.1.3. Type compatibility

8.1.4. Wrapping C types

8.2. Wrapping an external C library

8.2.1. Downloading the library

8.2.2. Creating a wrapper

8.2.3. Dynamic linking

8.2.4. Wrapping the types

8.2.5. Wrapping the procedures

8.2.6. Using the SDL wrapper

8.3. The JavaScript backend

8.3.1. Wrapping the Canvas element

8.3.2. Using the Canvas wrapper

8.4. Summary

9. Metaprogramming

9.1. Generics

9.1.1. Generic Procedures

9.1.2. Generics in type definitions

9.1.3. Constraining generics

9.1.4. Concepts

9.2. Templates

9.2.1. Passing a code block to a template

9.2.2. Parameter substitution in templates

9.2.3. Template hygiene

9.3. Macros

9.3.1. Compile-time Function Execution

9.3.2. Abstract Syntax Trees

9.3.3. Macro definition

9.3.4. Arguments in macros

9.4. Creating a configuration DSL

9.4.1. Starting the configurator project

9.4.2. Generating the object type

9.4.3. Generating the constructor procedure

9.4.4. The load procedure

9.4.5. Testing the configurator

9.5. Summary


Appendix A: Getting help

A.1. Real-time communication

A.2. Forum

A.3. Other communication methods

Appendix B: Installing Nim

B.1. Installing the Nim compiler

B.1.1. Installation Wizard (Windows only)

B.1.2. Archived Snapshot (All platforms)

B.2. Installing the Aporia IDE

B.3. Testing your new development environment

What's inside

  • Language features and implementation
  • Nimble package manager
  • Asynchronous I/O
  • Interfacing with C and JavaScript
  • Metaprogramming

About the reader

For developers comfortable with mainstream languages like Java, Python, C++ or C#.

About the author

Dominik Picheta is one of the principal developers of Nim and author of the Nimble package manager.

placing your order...

Don't refresh or navigate away from the page.
print book $24.99 $49.99 pBook + eBook + liveBook
Additional shipping charges may apply
Nim in Action (print book) added to cart
continue shopping
go to cart

eBook $39.99 3 formats + liveBook
Nim in Action (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book

FREE domestic shipping on three or more pBooks