D Cookbook


D Cookbook
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Leverage D to write efficient and correct programs with minimum code
  • Learn advanced code generation techniques to automate programming tasks
  • See how to apply D idioms to real-world problems and understand how it can benefit you

Book Details

Language : English
Paperback : 362 pages [ 235mm x 191mm ]
Release Date : May 2014
ISBN : 1783287217
ISBN 13 : 9781783287215
Author(s) : Adam D. Ruppe
Topics and Technologies : All Books, Application Development, Cookbooks, Open Source


Table of Contents

Preface
Chapter 1: Core Tasks
Chapter 2: Phobos – The Standard Library
Chapter 3: Ranges
Chapter 4: Integration
Chapter 5: Resource Management
Chapter 6: Wrapped Types
Chapter 7: Correctness Checking
Chapter 8: Reflection
Chapter 9: Code Generation
Chapter 10: Multitasking
Chapter 11: D for Kernel Coding
Chapter 12: Web and GUI Programming
Appendix: Addendum
Index
  • Chapter 1: Core Tasks
    • Introduction
    • Installing the compiler and writing a "Hello World" program
    • Adding additional modules (files) to your program
    • Using external libraries
    • Building and processing arrays
    • Using associative arrays to translate input
    • Creating a user-defined vector type
    • Using a custom exception type
    • Understanding immutability
    • Slicing a string to get a substring
    • Creating a tree of classes
  • Chapter 2: Phobos – The Standard Library
    • Introduction
    • Performing type conversions
    • Finding the largest files in a directory
    • Creating a network client and server
    • Using Base64 to create a data URI
    • Generating random numbers
    • Normalizing a string and performing Unicode comparisons
    • Searching with regular expressions
    • Writing a digest utility
    • Using the std.zlib compression
    • Using the std.json module
  • Chapter 3: Ranges
    • Introduction
    • Using ranges when implementing an algorithm
    • Creating an input range
    • Creating an output range
    • Creating a higher-order range
    • Putting a range interface on a collection
    • Creating an input range over a tree structure
    • Using runtime polymorphic (class) ranges
    • Storing a range as a data member
    • Sorting ranges efficiently
    • Searching ranges
    • Using functional tools to query data
  • Chapter 4: Integration
    • Introduction
    • Calling the Windows API functions
    • Removing the Windows console
    • Making Linux system calls
    • Writing part of a C program in D
    • Interfacing with C++
    • Using structs to mimic the C++ object structure
    • Communicating with external processes
    • Communicating with a dynamic scripting language
    • Using Windows' COM
  • Chapter 5: Resource Management
    • Introduction
    • Avoiding the garbage collector
    • Making a reference-counted object
    • Manually managing class memory
    • Using scope guards to manage transactions
    • Creating an array replacement
    • Managing lent resources
    • Creating a NotNull struct
    • Using unique pointers
    • Using RAII and handling the limitations of class destructors
  • Chapter 6: Wrapped Types
    • Introduction
    • Creating a struct with reference semantics
    • Simulating inheritance with structs
    • Creating a ranged integer
    • Creating an opaque handle type
    • Creating a subtyped string for i18n
    • Forwarding methods with opDispatch
    • Creating a tagged dynamic type
    • Creating a structure with two views into the same data
    • Simulating multiple inheritance with mixin templates
  • Chapter 7: Correctness Checking
    • Introduction
    • Using assertions and exceptions
    • Using static asserts
    • Using template constraints and static if
    • Preventing memory corruption bugs with @safe
    • Leveraging const-correctness
    • Avoiding side effects of pure functions
    • Verifying object invariants and pre- and post-conditions
    • Unit testing your code
    • Documenting your code with Ddoc
    • Writing platform-specific code (versions) and per-client configuration modules
  • Chapter 8: Reflection
    • Introduction
    • Getting dynamic runtime type information
    • Getting a list of child classes
    • Determining whether a module is available
    • Getting a list of all methods or fields in a module or an object
    • Inspecting function overloads
    • Determining names, types, and default values of function parameters
    • Getting components of complex types
    • Using user-defined attributes
    • Implementing a custom lint-style check for virtual functions
    • Extending the runtime type information
    • Creating a command-line function caller
  • Chapter 9: Code Generation
    • Introduction
    • Creating user-defined literals
    • Parsing a domain-specific language
    • Generating data structures from text diagrams
    • Automating dynamic calls with multiple dispatch
    • Building a lookup table
    • Using string parameters to change functions
    • Wrapping instance methods
    • Using opDispatch to generate properties
    • Duck typing to a statically-defined interface
  • Chapter 10: Multitasking
    • Introduction
    • Using threads
    • Passing messages with std.concurrency
    • Processing parallel data with std.parallelism
    • Using fibers
    • Creating new processes
    • Exploring thread-safe, single-locking singletons
    • Using asynchronous I/O
  • Chapter 12: Web and GUI Programming
    • Introduction
    • Creating a dynamic website with cgi.d
    • Creating a web API with web.d
    • Parsing and modifying an HTML page with dom.d
    • Accessing a SQL database
    • Sending an e-mail
    • Writing colored output to the console
    • Getting real-time input from the terminal
    • Working with image files
    • Creating a graphics window to show a TV static demo
    • Creating an OpenGL window
  • Appendix: Addendum
    • Compiling D for ARM/Linux Raspberry Pi
    • Running D on bare metal ARM
    • Using the exponentiation operator
    • Getting a stack trace without throwing an exception
    • Finding more information about D

Adam D. Ruppe

Adam D. Ruppe is a professional software developer living in Watertown, New York. He started programming PCs in high school, writing assembly language, and later C and C++, using the Digital Mars compiler to build programs based on MS DOS on a hand-me-down computer. Programming in the DOS environment with the slow computer gave him early practical experience in low-level and effi cient code—skills he carries on developing today. After finishing school, he started doing web programming—initially with PHP. While he'd make it work, he often found himself longing for the good old days. One day, he decided to check back with the vendor of his old compiler and discovered the D programming language (well before it reached 1.0!). He was enamored with it and used it to write some games, and then started writing web libraries to use it for work too, to replace PHP. He found success in this endeavor in early 2009. Combining his pioneering spirit with his blend of low-level and high-level programming experience, he was able to forge ahead with D, taking it to places many people didn't believe possible
Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 5 submitted: last submission 17 Jun 2014

Errata type: Code related Page Number: 22  Chapter Number: 1

 

It is: import core.sys.posix.fnctl

 

It should be: import core.sys.posix.fnctl;

Errata type: Grammar Page Number: 16 Chapter Number:1

 

It is: which contain the I/O and whitespace stripping functions that you used later

 

It should be: which contain the I/O and whitespace-stripping functions that you used later

Errata type: Technical Page Number: 14 Chapter Number: 1

 

It is: [][][] gets a slice into the whole thing..

 

It should be:  [] gets a slice into the whole thing..

Errata typeCode Page Number19 Chapter Number1

 

It is: return v;

}}}

/// converts to an (x,y) point. returns in an array.

float[2] toPoint() const {

import std.math;

float x = cos(direction) * magnitude;

float y = sin(direction) * magnitude;

return [x, y];

}

/// the addition operator

Vector opBinary(string op : "+")(Vector rhs) const {

auto point = toPoint(), point2 = rhs.toPoint();

point[0] += point2[0];

point[1] += point2[1];];];

return Vector.fromPoint(point););

 

It should be:  return v;

    }

    /// converts to an (x,y) point. returns in an array.

    float[2] toPoint() const {

         import std.math;

         float x = cos(direction) * magnitude;

         float y = sin(direction) * magnitude;

         return [x, y];

    }

    /// the addition operator

    Vector opBinary(string op : "+")(Vector rhs) const {

         auto point = toPoint(), point2 = rhs.toPoint();

         point[0] += point2[0];

         point[1] += point2[1];

 

         return Vector.fromPoint(point);

Errata type: Grammar Page Number: 31 Chapter Number: 1

 

It is: you can also achieve something subtyping and data extension,

It should be: you can also achieve subtyping and data extension,

 


Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

D Cookbook +    PhoneGap 3.x Mobile Application Development Hotshot =
50% Off
the second eBook
Price for both: $43.05

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Use the D programming language from "Hello World" to bare metal code
  • Gain an insight into avoiding the garbage collector and understand its pros and cons in real-world code examples
  • Discover how to use D's abstraction abilities to make the most of its effi cient and easy resource management capabilities
  • Implement and use ranges, a D idiom for lazy sequence implementation with decoupled generic algorithms
  • Explore a variety of third-party libraries available to get your work done faster
  • Integrate D into existing C, C++, and other environments
  • Prove program correctness with static analysis and test-driven development

In Detail

D is a modern programming language that uses the familiar C family syntax while offering advanced modeling capabilities, safety guarantees, programmer productivity, and high efficiency. It helps you to get the most out of your hardware and your programmers simultaneously, saving both development and deployment costs.

This practical guide will walk you through getting the work done with D, from writing your first program to writing advanced autogenerated objects, with notes based on real-world experiences telling you about potential pitfalls and how to avoid them. You'll use some of the third-party libraries available for D to get code working fast, including access to database engines, image processing, and more.

Approach

A recipe-packed reference guide filled with practical tasks that are concisely explained to develop and broaden the user's abilities with the D programming language.

Who this book is for

If you are an experienced programmer who is looking to explore a language that offers plenty of advantages over more established programming languages, this is the book for you. We assume that you are already familiar with general programming language basics, but you do not need to be a proficient user of D.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software