From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 7jd8KJIlgWAMdQAAgWs5BA (envelope-from ) for ; Thu, 22 Apr 2021 09:28:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id OGzPIpIlgWAoIwAAbx9fmQ (envelope-from ) for ; Thu, 22 Apr 2021 07:28:18 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3D98F103CE for ; Thu, 22 Apr 2021 09:28:18 +0200 (CEST) Received: from localhost ([::1]:48924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZTl3-0003j7-7A for larch@yhetil.org; Thu, 22 Apr 2021 03:28:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZTkT-0003Qo-59 for guix-devel@gnu.org; Thu, 22 Apr 2021 03:27:41 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:43440 helo=mail.yoctocell.xyz) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZTkQ-0002DO-T3 for guix-devel@gnu.org; Thu, 22 Apr 2021 03:27:40 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1619076456; bh=LVRzTiAMWOyzh9U38TvVfpvdJp39V+sa22Xd9W9LbNY=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=cLvLcLK1QBuoXjGfU9glHpts20g652joad7bhyJJ/uCFJP8hbovv7dVoQAi/OZeTd 2p3MkfUOxc6lXanOhA2086Y3+WiZDbCBonyH4mkwB9wzTxlZ1ljp120oLnd/wGirWc VK6J4u3f+U0EVdjyttbeqSUGWNQKv66L0rmelFBc= To: Maxim Cournoyer Subject: Re: Best practices for writing services In-Reply-To: <8735vjcy43.fsf@gmail.com> References: <878s6kqydj.fsf@yoctocell.xyz> <87wnswcmxi.fsf@gmail.com> <87k0ov7w72.fsf@yoctocell.xyz> <8735vjcy43.fsf@gmail.com> Date: Thu, 22 Apr 2021 09:27:36 +0200 Message-ID: <87y2da6aon.fsf@yoctocell.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=87.96.130.155; envelope-from=public@yoctocell.xyz; helo=mail.yoctocell.xyz X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.224, PDS_OTHER_BAD_TLD=2, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619076498; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=uR/9EXGEpMVR7QUxLYjHrkMGtVWnrK2sUeowOV9KYP0=; b=UU+OYzFtX0ssTxTCeeZ8XJ2ggTXEisyTy8jzCIrH/nn0suFTIlBvtaMbCWFNKda34C3SP8 +vtp/hHCGNkN73C9IcPXAzLr5SmHLlm7Na5AlS0JTHMH0q/1zVrszXqCcMdKcdyPVJAOAI ioGBxNEhDFADyIyFcCXDyjtUh7ArKvJDsIfdzNtmQOYQhHLvQTG0PIYTB6I/YNMMAMCuII 6vvFa7xcnD+ce0dfudzJw5l+99mZVKGu2/5eFXlyDyywU0KB/y22t4nYprzfC8Vb90rXpq ZKOsFR7pGmJJJC67AEW3FLEmyari1k5el6/OHYwG+8YW4WOmsuIKIco52Hix4Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619076498; a=rsa-sha256; cv=none; b=e1cTuD61WuZgaxyLZAYAZXWt0LMk0QMBx2gRoOjboHWSZjO2YbYDsa1aTD3SHPswldIPcY Q0N5BSg7d1rumY1bIfNqQmNXUFvBtgcqKZA7JTs/5Cu0rrkGUPwHBdc/bXolBnWz4p8gdn +uHeibLpdn4vHWyZVgCqxNNp1dz7uHsSAy/AfffUKzRvOnyYL6n5lTnIGzD18VMzlJjhsC QHo87jsJneF2i0goRyRLOO0Ej0iaS9m09n+St6mqm/0JBPaRuvY/SElNAPDSTRF448KlkE T7dUDchcBNbeVxg2Pdt0DZ0HpXQN5owNRkggmuah7S8iKB+lcWzikT9NiiZJ4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=yoctocell.xyz header.s=mail header.b=cLvLcLK1; dmarc=pass (policy=none) header.from=yoctocell.xyz; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Spam-Score: -3.14 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=yoctocell.xyz header.s=mail header.b=cLvLcLK1; dmarc=pass (policy=none) header.from=yoctocell.xyz; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: 3D98F103CE X-Spam-Score: -3.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: MRsgLJXBI6DI 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=E2=80=99t make much sense in s= ome >> cases, e.g. there is no good default value for =E2=80=98user.name =3D NA= ME=E2=80=99 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=E2=80=99t force the user to configure= the field. In a Git config for example, the user should be forced to set =E2=80=98user.name=E2=80=99 and =E2=80=98user.email=E2=80=99, otherwise the= y can=E2=80=99t commit anything. You will just have to set the default value to =E2=80=98disabled=E2=80=99, like= this: #+begin_src scheme (define (serialize-string field-name val) ...) (define-maybe string) (define-configuration test-config (config (maybe-string =E2=80=99disabled)) "docs"") #+end_src >> Another thing is that I don=E2=80=99t always want to =E2=80=9Cserialize-= =E2=80=9D 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!