comments on the Type system and some questions

65 views
Skip to first unread message

R.I.Pienaar

unread,
Jul 30, 2015, 10:37:02 AM7/30/15
to puppet-users
hello,

I've done a few little things with the type system and really like what it achieves,
was able to find a few bad data items in my hiera data and it saves on a lot of the
super annoying validation function calls.

The syntax though is pretty difficult to use, consider:

define foo(
Enum["present", "absent"] $ensure = "present",
Optional[String] $ssh_authorized_file = undef,
Optional[String] $email = undef,
Optional[Integer] $uid = undef,
Optional[Integer] $gid = undef,
Variant[Boolean, String] $sudoer = false,
Boolean $setup_shell = false,
Boolean $setup_rbenv = false
) {

So this has a few issues for me:

Reading it, I just don't see the property names now, its become a real effort
to read this.

$ssh_authorized_file Optional[String] = undef,

seems better for this use case to me and this is probably going to be the most
often used use case.

This gets much worse when we involve more complex type definitions, I can't imagine
ever using a full on Struct definition here for example it would render it entirely
unreadable and be impossible to maintain

How would you ever fit this into a param declaration and maintain readability:

Struct[{mode => Enum[read, write, update],
path => Optional[String[1]],
NotUndef[owner] => Optional[String[1]]}]

This leads to my 2nd question, I couldn't find a way to make my own abstract
types.

Consider this hypothetical with made up syntax and all:

site.pp:
typedef MyData Struct[{mode => Enum[read, write, update],
path => Optional[String[1]],
NotUndef[owner] => Optional[String[1]]}]

foo.pp:
define foo(Mydata $data) {

this would improve matters a whole lot. Does a typedef like feature exist? I couldn't
find anything and tried a few things but failed


---
R.I.Pienaar

Henrik Lindberg

unread,
Jul 31, 2015, 9:43:13 AM7/31/15
to puppet...@googlegroups.com
The intent is to add typedef like this:

type MyData = Struct[{ .... }]

Don't think we will change the order of type / param - too late to make
that change, and would be different from most other languages where type
declaration comes first.

- henrik


>
> ---
> R.I.Pienaar
>


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Trevor Vaughan

unread,
Aug 1, 2015, 5:29:04 PM8/1/15
to puppet...@googlegroups.com
This seems a bit better:

define foo(
     Enum["present", "absent"] $ensure                     = "present",
     Optional[String]                $ssh_authorized_file   = undef,
     Optional[String]                $email                       = undef,
     Optional[Integer]               $uid                          = undef,
     Optional[Integer]               $gid                          = undef,
     Variant[Boolean, String]    $sudoer                     = false,
     Boolean                           $setup_shell              = false,
     Boolean                           $setup_rbenv              = false
   ) {

It's relatively easy to achieve with Tabular but I do agree on the advanced structs, that's some crazy.

This is the best that I could do:

Struct[
  {
    mode                => Enum[read, write, update],
    path                  => Optional[String[1]],
    NotUndef[owner] => Optional[String[1]]
 }
]

I honestly have no idea if that will process correctly though, it's massively tedious, and it would probably need a lot of commenting.

Trevor


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/143546306.116227.1438266987939.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.



--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699

-- This account not approved for unencrypted proprietary information --
Reply all
Reply to author
Forward
0 new messages