Book Image

D Cookbook

By : Adam Ruppe
Book Image

D Cookbook

By: Adam Ruppe

Overview of this book

Table of Contents (21 chapters)
D Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

The D programming language's popularity is growing rapidly. With its seamless blending of high-level convenience with low-level power and efficiency, D is suitable for tackling almost any programming task productively. This book comes out of years of experience of using D in the real world and closely following the language and libraries' development. It will also help you get up to speed with this exciting language and burgeoning ecosystem.

What this book covers

Chapter 1, Core Tasks, will get you started with D and cover the tasks you can perform with D's core language features that differ from other popular programming languages.

Chapter 2, Phobos – The Standard Library, introduces you to the standard D library to perform common tasks, including generating random numbers, writing a network client and server, and performing type conversions.

Chapter 3, Ranges, covers the range concept, which is central to D algorithms. Ranges allow you to write and consume generators, views on various collections, and perform generic transformations of data.

Chapter 4, Integration, explores integrating D with the outside world, including creating Windows-based applications, using C libraries, and extending C++ applications with D.

Chapter 5, Resource Management, discusses how to manage memory and other resources in D, including tips on why, when, and how to use the garbage collector effectively.

Chapter 6, Wrapped Types, dives into the world of user-defined types, showing you how to extend and restrict types via cheap wrapper abstractions.

Chapter 7, Correctness Checking, shows how to use D's bug-hunting features such as testing, assertions, and documentation, and the correct way to do conditional compilation.

Chapter 8, Reflection, teaches you about the rich introspection capabilities D provides, including tips learned through years of experience which stretch the limits of the language.

Chapter 9, Code Generation, demonstrates several techniques to automate the creation of new code to write efficient, generic, and specialized code, including a primer on creating your own mini languages inside D.

Chapter 10, Multitasking, introduces you to the options D offers for concurrency and parallelism.

Chapter 11, D for Kernel Coding, will get you started with writing bare metal code in D, stripping out the runtime library to say hello directly through the PC's video hardware and then handling interrupts sent back by the keyboard with D's low-level features.

Chapter 12, Web and GUI Programming, showcases some of the libraries I've written over the years that show how to make a dynamic website and desktop graphics windows while discussing my practical experience from writing these libraries, which will give you a leg up when you write your own code.

Appendix, Addendum, briefly shows how to use D on ARM processors, including systems without an operating system, and other small topics that didn't fit elsewhere in the book.

What you need for this book

You need to have a Windows or Mac PC that is capable of running the DMD compiler, which is available at http://dlang.org/.

Who this book is for

This book is for programmers who want to continue their professional development by learning more about D. Whether you are looking at D for the first time or have used it before and want to learn more, this book has something to offer you.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Add a struct to test.d, which uses alias this to activate subtyping."

A block of code is set as follows:

import project.foo;; // disambiguate with project.foo
import bar; // you can disambiguate calls with the name bar

Any command-line input or output is written as follows:

coffimplib myfile.lib

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Running the program will print Hello, world! in green text on a red background."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.