March 9, 2023 3:25 PM, "Liliana Marie Prikler" <liliana.prik...@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. :(