Phobos Runtime Library
Phobos is the standard runtime library that comes with the
D language compiler. Also, check out the
wiki for Phobos
Each module in Phobos conforms as much as possible to the
following design goals. These are goals
rather than requirements because D is not a religion,
it's a programming language, and it recognizes that
sometimes the goals are contradictory and counterproductive
in certain situations, and programmers have
jobs that need to get done.
- Machine and Operating System Independent Interfaces
- It's pretty well accepted that gratuitous non-portability
should be avoided. This should not be
construed, however, as meaning that access to unusual
features of an operating system should be prevented.
- Simple Operations should be Simple
- A common and simple operation, like writing an array of
bytes to a file, should be simple to
code. I haven't seen a class library yet that simply and efficiently
implemented common, basic file I/O operations.
- Classes should strive to be independent of one another
- It's discouraging to pull in a megabyte of code bloat
by just trying to read a file into an array of
bytes. Class independence also means that classes that turn
out to be mistakes can be deprecated and redesigned without
forcing a rewrite of the rest of the class library.
- No pointless wrappers around C runtime library functions or OS API functions
- D provides direct access to C runtime library functions
and operating system API functions.
Pointless D wrappers around those functions just adds blather,
bloat, baggage and bugs.
- Class implementations should use DBC
- This will prove that DBC (Contract Programming) is worthwhile.
Not only will it aid in debugging the class, but
it will help every class user use the class correctly.
DBC in the class library will have great leverage.
- Use Exceptions for Error Handling
- See Error Handling in D.
Runtime library modules can be imported with the
statement. Each module falls into one of several
- These are the core modules.
- Modules specific to the Windows operating system.
- Modules specific to the Linux operating system.
- Modules that are simply interfaces to C functions.
For example, interfaces to standard C library functions
will be in std.c, such as std.c.stdio would be the interface
to C's stdio.h.
- Modules corresponding to the C Windows API functions.
- Modules corresponding to the C Linux API functions.
- This is the root of a hierarchy of modules mirroring the std
hierarchy. Modules in etc are not standard D modules. They are
here because they are experimental, or for some other reason are
not quite suitable for std, although they are still useful.
std: Core library modules
- Encode/decode base64 format.
- Arbitrary-precision ('bignum') arithmetic
- Bind function arguments.
- Arrays of bits.
- Box/unbox types.
- Information about the D compiler implementation.
- Conversion of strings to integers.
- Simple character classification
- Date and time functions. Support locales.
- Date and time-related types and functions.
- Basic file operations like read, write, append.
- Formatted conversions of values to strings.
- Control the garbage collector.
- Compiler built in intrinsic functions
- Include all the usual math functions like sin, cos, atan, etc.
- Compute MD5 digests.
- Memory mapped files.
- The root class of the inheritance hierarchy
- Assemble data into an array of bytes
- Manipulate file names, path names, etc.
- Create/destroy threads.
- Random number generation.
- Recursively search file system and (currently Windows
only) FTP sites.
- The usual regular expression functions.
- Stream for a blocking, connected Socket.
- Integral types for various purposes.
- Standard I/O.
- Stream I/O.
- Stream I/O.
- Basic string operations not covered by array ops.
- Inquire about the CPU, operating system.
- One per thread. Operations to do on a thread.
- Encode and decode Uniform Resource Identifiers (URIs).
- Encode and decode utf character encodings.
- Read/write zip archives.
- Compression / Decompression of data.
std.windows: Modules specific to the Windows operating system
- Convert Windows error codes to strings.
std.linux: Modules specific to the Linux operating system
std.c: Interface to C functions
- Interface to C stdio functions like printf().
std.c.windows: Interface to C Windows functions
- Interface to Windows APIs
std.c.linux: Interface to C Linux functions
- Interface to Linux APIs
- int printf(char* format, ...)
- C printf() function.