guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practices for writing services


From: Xinglu Chen
Subject: Re: Best practices for writing services
Date: Thu, 22 Apr 2021 09:27:36 +0200

On Wed, Apr 21 2021, Maxim Cournoyer wrote:

>> One thing that I find a little annoying is that you have to specify a
>> default value for the fields.  This doesn’t make much sense in some
>> cases, e.g. there is no good default value for ‘user.name = NAME’ in the
>> Git config, the user should have to specify that themselves.
>
> There's a 'define-maybe' that can be used to declare a field that can
> take more than one type, e.g.:
>
> (define-maybe string)
>
> Will generate a definition like so:
>
> --8<---------------cut here---------------start------------->8---
> (define (maybe-string? val)
>                (or (eq? val 'disabled) (string? val)))
> --8<---------------cut here---------------end--------------->8---
>
> Which the validator of define-configuration will use if you specify a
> field with the type 'maybe-string'.
>
> 'disabled is a bit semantically broken in some cases ('unspecified'
> could be nicer), but it does the job.

But the problem here is that it doesn’t force the user to configure the
field.  In a Git config for example, the user should be forced to set
‘user.name’ and ‘user.email’, otherwise they can’t commit anything.  You
will just have to set the default value to ‘disabled’, like this:

#+begin_src scheme
(define (serialize-string field-name val) ...)
(define-maybe string)
(define-configuration test-config
  (config
    (maybe-string ’disabled))
    "docs"")
#+end_src

>> Another thing is that I don’t always want to “serialize-” the value for a
>> field, so I sometimes end up defining a bunch of dummy serializers that
>> just return an empty string.
>
> Good point!  I've tried addressing that, without success so far [0].

Cool, that would definitely be an improvement!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]