Phobos
Phobos is the standard runtime library that comes with the D language compiler.
Philosophy
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.
No user interface windowing classes
GUI styles, philosophies, etc., are not portable from machine to machine. A GUI Windows app should look like a Windows app when running on a Windows machine. It should not look and feel like a Mac app unless it is running on a Mac. Attempts to create a common GUI class library between Windows, Mac, and other GUI operating systems have all to my knowledge failed.
Java has a successful GUI class library, but does so by creating its own GUI with its own look and feel. This approach is fine for a web language, but not for a systems language like D is.
Windowing class libraries should be separate.
Class implementations should use DBC
This will prove that DBC (Design by Contract) 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.
Imports
Each of these can be imported with the import statement. The categories are:
Core D: Available on all D implementations
compiler
Information about the D compiler implementation.
conv
Conversion of strings to integers.
ctype
Simple character classification
date
Date and time functions. Support locales.
file
Basic file operations like read, write, append.
gc
Control the garbage collector.
math
Include all the usual math functions like sin, cos, atan, etc.
object
The root class of the inheritance heirarchy
outbuffer
Assemble data into an array of bytes
path
Manipulate file names, path names, etc.
process
Create/destroy threads.
random
Random number generation.
regexp
The usual regular expression functions.
stdint
Integral types for various purposes.
stream
Stream I/O.
string
Basic string operations not covered by array ops.
system
Inquire about the CPU, operating system.
thread
One per thread. Operations to do on a thread.
zip
Manipulate zip files.
Standard C: interface to C functions
stdio
Interface to C stdio functions like printf().
Operating System and Hardware: platform specific
intrinsic
Compiler built in intrinsic functions
windows
Interface to Windows APIs
compiler
char[] name;
Vendor specific string naming the compiler, for example: "Digital Mars D".
enum Vendor
Master list of D compiler vendors.
DigitalMars
Digital Mars
Vendor vendor;
Which vendor produced this compiler.
uint version_major;
uint version_minor;
The vendor specific version number, as in version_major.version_minor.
uint D_major;
uint D_minor;
The version of the D Programming Language Specification supported by the compiler.
conv
conv provides basic building blocks for conversions from strings to integral types. They differ from the C functions atoi() and atol() by not allowing whitespace or overflows.
For conversion to signed types, the grammar recognized is:
Integer:
Sign UnsignedInteger
UnsignedInteger
Sign:
+
-
For conversion to unsigned types, the grammar recognized is:
UnsignedInteger:
DecimalDigit
DecimalDigit UnsignedInteger
Any deviation from that grammar causes a ConvError exception to be thrown. Any overflows cause a ConvOverflowError to be thrown.
byte toByte(char[] s)
ubyte toUbyte(char[] s)
short toShort(char[] s)
ushort toUshort(char[] s)
int toInt(char[] s)
uint toUint(char[] s)
long toLong(char[] s)
ulong toUlong(char[] s)
Share with your friends: |