N.-Y.: Packt Publishing, 2014. — 362 p. — ISBN13: 978-1783287215.
Discover the advantages of programming in D with over 100 incredibly effective recipes with this book and ebook.
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.
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.
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 efficient 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
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 written 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.
Core TasksInstalling 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.
Phobos – The Standard LibraryPerforming type conversions.
Finding the largest files in a directory.
Creating a network client and server.
Using Base to create a data URI.
Generating random numbers.
Normalizing a string and performing Unicode comparisons.
Searching with regular expressions.
Writing a digest utility.
Using std.zlib compression.
Using the std.json module.
RangesUsing 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.
IntegrationCalling 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.
Resource ManagementAvoiding 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.
Wrapped TypesCreating 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.
Correctness CheckingUsing 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.
ReflectionGetting 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.
Code GenerationCreating 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.
MultitaskingUsing 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.
D for Kernel CodingRunning D on bare metal x86 with a stripped runtime.
Adding interrupt handling to the bare metal x86 code.
Web and GUI ProgrammingCreating 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: AddendumCompiling D for an 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.