Skip to content

Package Coding Style #1360

Closed
Closed

Description

@aluzzardi

We should have a README file somewhere encoding package coding style.

Right now there's a few proposals around:

Activity

  1. added this to the next milestone on Jan 7, 2022
  2. aluzzardi commented on Jan 7, 2022

    @aluzzardi
    ContributorAuthor

    @shykes Assigning to you for a first draft since you have the implicit policies in mind with the Europa rewrite

  3. shykes commented on Jan 10, 2022

    @shykes
    Contributor

    I will write a first draft of this. It will be incomplete but you have to start somewhere.

    Everyone: please share in the comments suggestions for areas of CUE coding style to cover. If you have an opinion, please share it - if you don’t, that’s OK.

  4. talentedmrjones commented on Jan 12, 2022

    @talentedmrjones

    I suggest taking a cue from Go (sorry couldn't resist):

    • uppercase names for "public" definitions used outside the package (engine.#Build)
    • lowercase for "private" fields used only inside the package (_#inputSecret)
    • definitions # for schemas (may include concrete defaults)
    • fields (hidden or visible) for concrete implementation of schemas
    • aliases (let x) for immediate block scope
  5. TomChv commented on Jan 13, 2022

    @TomChv
    Member

    Duplicate from 1359 comment

    I think it would be relevant to create definition or component to force the coding style for further europa & user definition.

    Below an example, this is not what we want but it's useful to illustrate my proposal.

    #FS: {
    	$dagger: fs: _id: string
    }
    
    Component: {
        input: #FS
        
        command: _ //... I don't know if it's relevant
        
        output: #FS
    }
    
    // A universe pkg
    #Deploy: {
        args: [...string]
    
        command: // ... do stuff
    } & Component

    This is also something we did on europa docker package, with #Step.

    Indeed, I also agree with @talentedmrjones suggestion, and I think we should find a way to verify that our package follow a pattern.

    I'm not sure it' possible because how can a program know if a file should be public or no, but it's important.

  6. TomChv commented on Jan 13, 2022

    @TomChv
    Member

    I'm also adding other suggestions :

    Style

    • Action definition should be define by a verb (#Build, #Push...), otherwise it should be nouns
    • Inlined scripts (see kubernetes for example) should be in his own file with the extension .sh.cue and in a field _<Prefix_Name>Script
    • We should use bash.#Run for all call to bash script (and not use raw engine.#Exec)

    Architecture

    • We must write test in tests directory located in the directory of the package
    • Action definition must be split in their own file, we shouldn't have one file that export 2 actions. We can keep a clean architecture. Indeed, other definition utils to the action but be in the action's file (#Build is a good example IMO)

    Policy

    • All public fields must be documented with explanation & example of value
    • At least, all basic usage of a package must be tested before being merged
  7. modified the milestones: v0.2.0-alpha.3, next on Jan 31, 2022
  8. aluzzardi commented on Jan 31, 2022

    @aluzzardi
    ContributorAuthor

    Rolled over into the next milestone

  9. talentedmrjones commented on Feb 11, 2022

    @talentedmrjones

    I propose that packages be written so that definitions and fields are in alphabetical order. This seem to help find them fast especially when definitions have many fields, or a file has many definitions. Thoughts?

  10. shykes commented on Feb 23, 2022

    @shykes
    Contributor

    @aluzzardi I think you should own this... I have opinions as you know, but I know you will take them into account, and I am becoming a bottleneck.

  11. modified the milestones: v0.2.0-beta.1, on Mar 24, 2022
  12. assigned and unassigned on Mar 27, 2022
  13. shykes commented on Mar 27, 2022

    @shykes
    Contributor

    @helderco since you're currently working on CUE API improvements, can I add this to your list? It doesn't have to be a complete list. Just a starting point that we can add to over time. You have most of the context anyway, if you're not sure about certain conventions, just ask and we can bikeshed over it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions