Nim in Action
Dominik Picheta
  • MEAP began January 2016
  • Publication in July 2017 (estimated)
  • ISBN 9781617293436
  • 400 pages (estimated)
  • printed in black & white

Nim is a new programming language designed to be efficient, expressive, and elegant. This general-purpose language offers support for systems programming, object oriented programming, procedural programming, functional programming, and more. Nim combines the speed of C with the expressiveness of Python and the flexibility of Lisp and it compiles to C as well as C++, Objective C, and even JavaScript. When compiling to C, you can use the C compiler of your choice to generate a highly-optimized and portable program. Nim's features make it perfect for developing anything from web applications to operating systems.

"I really appreciate the care and thoroughness displayed by the author to ensure the reader can set up Nim and follow along with the book."

"The author covers a huge range of topics, and these new chapters flow from large ideas that touch programming and computer science in general while also focusing on specific parts of Nim."

~ James Anaipakos

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?

===Summary

2. Getting started

2.1. Nim syntax

2.1.1. Keywords

2.1.2. Indentation

2.1.3. Comments

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

Appendixes

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

About the book

Nim in Action introduces the Nim programming language and teaches you to write native software applications and libraries, web applications, embedded device software, and programs that communicate over the internet. This book is full of hands-on examples that help you learn how to test, debug, document, and package your Nim applications. You'll also discover how to interface with foreign languages such as C and C++ and how to use metaprogramming features to write domain specific languages. Throughout this book you will implement a fully-functioning chat server, a Twitter clone, and many other software projects. By the time you finish reading, you'll have a solid knowledge of Nim and will be able to use it to write powerful, portable and efficient applications.

What's inside

  • Nim's standard library
  • Concurrency and parallelism in Nim
  • Using asynchronous IO for internet communication
  • Metaprogramming and compile-time transformations
  • Interfacing with other languages
  • The Nimble package manager
  • Creating web applications with Nim
  • Direct hardware control using Nim

About the reader

This book assumes you're a working developer proficient with another language like Java, Ruby, Python, C#, or C++.

About the author

Dominik Picheta is one of the main developers of the Nim programming language, he is also the author of the Nimble package manager as well as many other Nim tools.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks