Learning D: Leverage the modern convenience and modelling power of the D programming language to develop software with native efficiency

Learning D: Leverage the modern convenience and modelling power of the D programming language to develop software with native efficiency

Learning D: Leverage the modern convenience and modelling power of the D programming language to develop software with native efficiency

Автор: Mike Parker
Дата выхода: 2015
Издательство: Packt Publishing Limited
Количество страниц: 465
Размер файла: 6,4 МБ
Тип файла: PDF
Добавил: zedchi
 Проверить на вирусы

Preface xi
Chapter 1: How to Get a D in Programming - 1
Say hello to D - 2
An introductory program - 3
Getting help - 7
The Digital Mars D compiler - 9
Frontends, backends, and linkers - 9
Installing DMD - 11
The Windows installer - 11
Installing from the ZIP - 12
Compiling the example - 13
Documentation and source code - 14
The documentation - 14
The source - 16
Say hello to MovieMan - 16
The problem - 17
The features - 17
DUB – the D build tool and package manager - 18
Getting started - 19
Configuring the MovieMan project - 20
Understanding dub.sdl - 21
Building and running MovieMan - 22
Changing the output directory - 24
Summary - 24
Chapter 2: Building a Foundation with D Fundamentals - 25
The very basics - 26
Identifiers - 26
A note about scope - 26
More on modules - 28

 

[ ii ]

Module declarations - 28
More about import declarations - 30
The special package module - 32
Comments - 33
Variable declaration and initialization - 34
Basic types - 35
The types - 36
Literals - 37
Integer literals - 37
Floating-point literals - 38
Character literals - 39
Conversions - 39
Alias declarations - 41
Properties - 41
Basic operators - 43
Arithmetic operators - 43
Bitwise operators - 44
Relational and logical operators - 45
The cast operator - 46
Derived data types - 46
Pointers - 46
Arrays - 48
Array basics - 48
Rectangular arrays - 51
Slices - 53
Array literals - 56
Arrays and void - 57
Array operations - 57
Strings - 60
String essentials - 60
Alternative string literals - 62
Associative arrays - 64
Control flow statements - 65
Traditional loops - 66
The foreach loop - 67
Traditional conditionals - 68
The goto statement - 71
Type qualifiers – const and immutable - 72
The contracts - 72
With the basic types - 72
With pointers - 73
With arrays - 75

 

[ iii ]

Conversions - 76
Functions - 76
Overloaded functions - 78
ref and out - 78
inout parameters - 81
lazy parameters - 82
Function attributes - 83
Return statements and memory - 83
Function pointers and delegates - 85
MovieMan – first steps - 87
The io module - 87
The app module - 91
Summary - 92
Chapter 3: Programming Objects the D Way - 93
User-defined types - 93
Enumerations - 93
Unions - 95
Structs and classes - 95
Working with objects - 98
Encapsulation with protection attributes - 98
Public - 98
Private - 99
Package - 100
Voldemort types - 101
Constructors and destructors - 102
Class constructors and destructors - 102
Struct constructors and destructors - 105
Static constructors and destructors - 108
Inheritance and polymorphism - 110
Interfaces - 113
Fake inheritance - 114
Nested classes - 115
Objects with const and immutable - 116
const as a storage class - 118
Error handling - 118
Scope guards - 118
Exception handling - 119
Contract programming and unit tests - 122
Assert contracts - 122
Function contracts - 123
Invariants - 123
Unit tests - 125

 

[ iv ]

MovieMan – adding menus - 126
The Menu base class - 126
The MainMenu class - 128
The DisplayMenu class - 130
Summary - 130
Chapter 4: Running Code at Compile Time - 131
Pragmas - 132
The lib pragma - 132
The msg pragma - 133
The inline pragma - 134
Conditional compilation - 134
The version condition - 134
The debug condition - 137
The static if condition - 138
Compile-time strings - 139
The import expression - 139
String mixins - 140
Compile-time function execution - 141
Odds and ends - 145
static assert - 145
The is expression - 146
Alignment - 147
Compile-time reflection - 153
User-defined attributes - 154
Summary - 157
Chapter 5: Generic Programming Made Easy - 159
Template basics - 160
Templates as code blocks - 160
Struct and class templates - 163
Enum templates - 166
Function templates - 166
Special features - 168
More template parameters - 169
Value parameters - 169
Alias parameters - 170
This parameters - 172
Beyond the basics - 173
Template specializations - 173
Specialization on pointers and arrays - 175
Template constraints - 177
Template mixins - 178

 

[ v ]

Variadic templates - 180
Terminology - 182
More on usage - 184
Operator overloading - 186
Non-templated operator overloads - 186
Comparison overloads – opEquals and opCmp - 186
Function call overloads - 189
Assignment overloads - 190
Index overloads - 191
Templated operator overloads - 192
Unary overloads - 192
Binary overloads - 193
Cast overloads - 195
Operator assignment overloads - 195
Slice operator overloads - 196
Other overloads - 198
opDispatch - 198
opApply - 200
toHash - 201
MovieMan – the database - 202
db.d - 202
Back to the menus - 204
Summary - 206
Chapter 6: Understanding Ranges - 207
Ranges defined - 207
The problem - 208
The solution - 210
The interface - 210
A range for arrays - 212
The implementation of filter - 213
The test - 215
The real ranges - 216
Input ranges - 216
Forward ranges - 218
Bidirectional ranges - 219
Random-access ranges - 219
Output ranges - 220
Optional range primitives - 221
Ranges in use - 223
Custom ranges - 224
Getting a range from a stack - 224
A name generator range - 226
Other considerations - 228
Custom algorithms - 229
Summary - 230

 

[ vi ]

Chapter 7: Composing Functional Pipelines with Algorithms and Ranges - 231
Functional programming and composable pipelines - 232
A simple example - 233
A more complex example - 236
Sometimes we can't - 238
Navigating Phobos - 239
std.range - 239
Generative ranges - 240
Selective ranges - 242
Compositional ranges - 244
std.algorithm - 247
Comparison - 247
Iteration - 249
Mutation - 251
Searching - 253
Set operations - 254
Sorting - 255
std.array - 257
Appender - 257
assocArray - 258
join - 258
Where to look for more - 259
MovieMan – wrapping up - 259
The db module - 259
The display menu - 263
Making it better - 268
Summary - 268
Chapter 8: Exploring the Wide World of D - 269
Online resources - 270
DWiki - 270
Planet D - 270
reddit and StackOverflow - 270
This Week in D - 271
DConf - 272
DSource - 273
Editors and IDEs - 274
Text editors - 274
Vim and Emacs - 274
Textadept - 274
Sublime Text - 275
IDEs - 276
Visual D - 276

 

[ vii ]

Mono-D - 276
DDT - 276
Code::Blocks - 277
Tools and utilities - 277
DMD - 277
Optimized and debug builds - 277
Changing the default output - 278
Compiling libraries - 278
Using libraries - 279
Warnings - 281
Profiling - 281
Code coverage analysis - 283
Compile and run - 285
GDC and LDC - 285
GDC - 285
LDC - 286
RDMD - 286
DustMite - 287
DCD - 289
DVM - 289
Libraries - 290
code.dlang.org - 290
Using libraries from the DUB registry - 290
Registering libraries with the DUB registry - 293
Browsing the DUB registry - 296
Deimos and DerelictOrg - 296
Summary - 297
Chapter 9: Connecting D with C - 299
Preliminaries - 300
Terminology - 300
Bindings, wrappers, and ports - 300
Dynamic and static – context matters - 302
Object file formats - 305
Linkage attributes - 307
Name mangling - 307
Calling conventions - 308
Putting it together - 309
Binding D to C - 311
Function prototypes - 312
Manually loading shared libraries - 314
Trying it out - 316
C types to D types - 319
Strings and characters - 320
Special types - 320
Enumerations - 321

 

[ viii ]

Structures - 322
Pointers - 325
Type aliases - 326
Function pointers - 327
Defined constants - 329
Function parameters and return types - 329
Symbols - 331
Global variables - 332
Macros - 333
Conditional compilation - 337
Calling C from D - 339
D arrays and C arrays - 339
Basic arrays - 339
Arrays of arrays - 342
Strings - 344
Memory - 346
C callbacks and exceptions - 347
Calling D from C - 349
Summary - 351
Chapter 10: Taking D Online - 353
The software - 354
vibe.d - 354
Package overview - 354
The anatomy of a vibe.d web app - 355
The database library - 357
MovieManWeb - 359
Getting started - 360
The basics of diet templates - 363
Tags and indentation - 364
Including and extending templates - 366
The MovieManWeb layout - 368
Setting up the database - 370
Fleshing out the index page - 374
Mapping web interface functions to URLs - 374
Rendering diet templates - 375
Rewriting index.dt - 376
Adding movies - 377
Implementing the addMovie function - 378
Implementing the postAdd function - 380
Implementing add.dt - 382
Modifying index.dt - 383
Modifying app.d - 385
Modifying layout.dt - 385

 

[ ix ]

Listing movies - 386
Implementing the listMovies function - 386
Modifying the index function - 388
Modifying index.dt - 389
Finding movies - 391
Implementing the postFind function - 391
Implementing find.dt - 392
Modifying index.dt - 393
Modifying app.d and layout.dt - 394
Implementing the findMovie functions - 394
Editing and deleting movies - 397
Expanding on MovieManWeb - 399
Summary - 400
Chapter 11: Taking D to the Next Level - 401
Concurrency - 402
Threads and fibers - 402
Threads - 402
Fibers - 403
Data sharing - 404
__gshared - 405
Shared - 405
Synchronization and atomics - 406
Automatic synchronization - 406
Manual synchronization - 408
Atomics - 408
Message passing - 408
Parallelism - 409
More information - 411
SafeD - 411
Functional purity - 413
The garbage collector - 414
Connecting with C++ - 415
More on Phobos - 416
std.container - 416
std.datetime - 417
std.digest - 417
std.experimental - 417
std.getopt - 418
std.process - 419
std.socket - 419
Modules for Unicode and other encodings - 419
System bindings - 420

 

[ x ]

Game development with D - 420
The future of D - 421
Summary - 422
Index - 423

 About This BookAcquire the skills to understand the fundamentals of D through its support for imperative and object-oriented programmingTake advantage of D's powerful compile-time features, templates and ranges to apply generative, generic, and functional styleA systematic guide that will help you become familiar with the concepts in D with the help of simple and easy-to-understand examplesWho This Book Is For

 This book is intended for those with some background in a C-family language who want to learn how to apply their knowledge to D. Perhaps you're a college student looking to use D for hobby projects, or a career programmer interested in expanding your skillset. This book will help you get up to speed with D and avoid common pitfalls that arise when translating C-family experience to D.What You Will LearnCompile programs with DMD and manage projects with DUBWork efficiently by binding your D programs to new and existing C librariesGenerate code at compile-time to enhance runtime performanceImplement complex templates for more powerful generic codeWrite idiomatic D with range-based functional pipelinesUse the DUB repository to link with a variety of D librariesImplement a web-app in D from the ground upIn Detail

 This book familiarizes you with D from the ground up, with a heavy focus on helping you to avoid surprises so that you can take your D knowledge to the next level.

 Your journey begins with a taste of the language and the basics of compiling D programs. You then set out on an exploration of D's major features. This begins with the fundamentals of D, followed by an examination of D's object-oriented programming support. Next up are D's compile-time features, including templates. After that, you'll learn the more advanced features of ranges and functional pipeline programming. Finally, you get a peek at D web development using the vibe.d project. The book closes with some handy advice on where to go next.


Похожее:

Список отзывов:

Нет отзывов к книге.