Am Mon, 17 Mar 2014 03:49:24 -0700
schrieb Walter Bright <newshou...@digitalmars.com>:

> On 3/17/2014 2:32 AM, Iain Buclaw wrote:
> > On 17 March 2014 08:55, Walter Bright <newshou...@digitalmars.com>
> > wrote:
> >> On 3/17/2014 1:35 AM, Iain Buclaw wrote:
> >>>
> >>> Right,
> >>
> >>
> >> If so, why do all modules need the version statement?
> >
> > That is a question to ask the historical maintainers of cairoD.
> > Having a look at it now.
> > It has a single config.d with enum bools to
> > turn on/off features.
> 
> If those enums are controlled by a version statement, then the
> version will have to be set for every source file that imports it.
> This is not the best design - the abstractions are way too leaky.

It's meant to be set at configure time, when the library
is being built, by a configure script or similar. They're not controlled
by version statements at all.

That's nothing special, it's config.h for D.


The reason all modules needed the version statement was that I didn't
use the stub-function trick. Cairo also has classes which can be
available or unavailable. Stubbing all these classes doesn't seem to be
a good solution. I also think it's bad API design if a user can call a
stub 'savePNG' function which just does nothing.

A perfect solution for cairoD needs to handle all these cases:
cairo has PNG support:             true                    false
user wants to use PNG:   optional, true, false    optional, true, false
                         ok         ok    ok       ok       error  ok


with config.d and static if:
-----------------------
enum bool CAIRO_HAS_PNG_SUPPORT = true; //true/false is inserted by
                                        //configure script
static if(CAIRO_HAS_PNG_SUPPORT)
    void savePNG();
-----------------------


library users can do this:
-----------------------
import cairo.config;
static if(!CAIRO_HAS_PNG_SUPPORT)
   assert(false, "Need PNG support");

static if(CAIRO_HAS_PNG_SUPPORT)
   //Offer option to optionally save file as PNG as well
-----------------------

if they don't check for CAIRO_HAS_PNG_SUPPORT and just use
savePNG then
(1) it'll work if PNG support is available
(2) the function is not defined if png support is not available

With versions the user has no way to know if the library actually
supports PNG or not. He can only guess and the optional case can't be
implemented at all.

Reply via email to