unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: jbranso@dismail.de
To: "Liliana Marie Prikler" <liliana.prikler@gmail.com>,
	"Bruno Victal" <mirai@makinata.eu>,
	"guix-devel" <guix-devel@gnu.org>
Cc: "Felix Lechner" <felix.lechner@lease-up.com>,
	"Maxim Cournoyer" <maxim.cournoyer@gmail.com>,
	"Ludovic Courtès" <ludo@gnu.org>
Subject: Re: Brainstorming ideas for define-configuration
Date: Fri, 10 Mar 2023 20:15:52 +0000	[thread overview]
Message-ID: <564d5fb289ca2f547ba89fa8f39b7b72@dismail.de> (raw)
In-Reply-To: <d594dc9615940adefd66b461e272e045e08dd888.camel@gmail.com>

March 9, 2023 3:25 PM, "Liliana Marie Prikler" <liliana.prikler@gmail.com> wrote:

> Hi,
> 
> Am Donnerstag, dem 09.03.2023 um 02:28 +0000 schrieb Bruno Victal:
> 
> I smell bad code ahead.
> 
>> We could provide procedures that validate each record type within
>> define-configuration itself instead of validating the value at
>> runtime (i.e. within the body of the service-type).
>> 
>> --8<---------------cut here---------------start------------->8---
>> ;; the common case
>> (define-configuration foo-configuration
>> (name
>> string
>> "Lorem ipsum...")
>> 
>> ;; ...
>> 
>> (validator procname))
>> 
>> ;; [bonus] Simpler configurations that only care for mutually-
>> exclusive fields
>> (define-configuration foo-configuration
>> (name
>> string
>> "Lorem ipsum...")
>> 
>> (title
>> string
>> "Lorem ipsum..."
>> (conflicts 'name)))
>> --8<---------------cut here---------------end--------------->8---
> 
> Instead of providing both a name field and a title field, you might
> provide a field that can either be a name or a title or allow an even
> more powerful value type as long as it makes sense.

While I would agree that a guix service writer should avoid mutually
exclusive fieldnames and instead prefer mutually exclusive records
(and 95% of that time that will work), but may we examine it from a
user's perspective? How does the service writer differentiate from
a string title or string name?

Suppose that you want to respond to a king's rudeness. You can
secretly insult him or obviously insult him:

===Mutually exclusive records===, which are better from a maintainer's
perspective, but perhaps cause the user to write more scheme:

"..your traitor brother. Maybe I’ll feed him to wolves after I’ve
caught him. Did I tell you, I intend to challenge him to single
combat?"

(insult-configuration
  (response
    (secret-insult-configuration
      (secret-insult “I should like to see that, Your Grace.”))))

OR

"You can't insult me."

(insult-configuration
  (response
    (obvious-insult-configuration
      (obvious-insult "We've had vicious kings and we've had idiot kings,
but I don't know if we've ever been cursed with a vicious idiot for
a king!"))))

===Mutually exclusive fieldnames===

"I am the KING!"

(insult-configuration
  (secret-insult "Any man who must say, 'I am the king' is no
true king. I'll show you that after I've won your war.")))

OR

"You are Kingsguard!"

(insult-configuration
  (obvious-insult "...F*ck the King."))))

These examples are pretty wonky I will admit, but I really like
an option of having mutually exclusive fieldnames.  Having said all of this,
I will agree that that mutually exclusive fieldnames are a bit like "goto"
in C.  You really should never use them, unless you absolutely have to.

Thanks,

Joshua

P.S.  I thought about not sending this email, then realized that someone
might find it funny.  Sorry if it wastes your time.  :(


  parent reply	other threads:[~2023-03-10 20:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  2:28 Brainstorming ideas for define-configuration Bruno Victal
2023-03-09  8:13 ` Attila Lendvai
2023-03-09 21:05   ` Josselin Poiret
2023-03-09 14:40 ` Joshua Branson
2023-03-09 20:23 ` Liliana Marie Prikler
2023-03-10 14:10 ` Maxim Cournoyer
2023-03-10 20:15 ` jbranso [this message]
2023-03-10 22:37   ` Liliana Marie Prikler
2023-03-15 16:27 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564d5fb289ca2f547ba89fa8f39b7b72@dismail.de \
    --to=jbranso@dismail.de \
    --cc=felix.lechner@lease-up.com \
    --cc=guix-devel@gnu.org \
    --cc=liliana.prikler@gmail.com \
    --cc=ludo@gnu.org \
    --cc=maxim.cournoyer@gmail.com \
    --cc=mirai@makinata.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).