Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Breaking change: Remove getter methods on constraints and expose fields instead #154

@m1kola

Description

@m1kola

Today constraints hold important data in unexported fields and provide getters to access data.

It seems like there is not much value in these getters: Deppy itself doesn't seem to use them and on the user side they are normally not required in production code.

However this makes testing of components which generate variables with constraints harder for deppy users. Users have to use something like go-cmp with AllowUnexported & use constructors such as constraint.AtMost() to create constraints instead of simply just comparing literals.

I think we should explore exporting constraint fields and removing getter methods.

For example, AtMostConstraint which looks today like this:

type AtMostConstraint struct {
ids []deppy.Identifier
n int
}
func (constraint *AtMostConstraint) String(subject deppy.Identifier) string {
s := make([]string, len(constraint.ids))
for i, each := range constraint.ids {
s[i] = string(each)
}
return fmt.Sprintf("%s permits at most %d of %s", subject, constraint.n, strings.Join(s, ", "))
}
func (constraint *AtMostConstraint) N() int {
return constraint.n
}
func (constraint *AtMostConstraint) Ids() []deppy.Identifier {
return constraint.ids
}

will be turned into something like this:

type AtMostConstraint struct { 
 	IDs []deppy.Identifier 
 	N   int 
 } 
  
 func (constraint *AtMostConstraint) String(subject deppy.Identifier) string { 
 	s := make([]string, len(constraint.IDs)) 
 	for i, each := range constraint.IDs { 
 		s[i] = string(each) 
 	} 
 	return fmt.Sprintf("%s permits at most %d of %s", subject, constraint.N, strings.Join(s, ", ")) 
 } 

Metadata

Metadata

Assignees

Labels

kind/designCategorizes issue or PR as related to design.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions