8. DSL in Ruby
validates :name, presence: true
validate :name, presence: true
validates :name, presense: true
Which is correct?
9. DSL in Ruby
validates :points, numericality: true
validates :points, numericality: { only: “integer” }
validates :points, numericality: { only_integer: true }
Which is correct?
10. DSL in Ruby
• String/symbol + Hash everywhere
• lack of “Syntax Error”
• everything is void*
• anything is ok for ruby interpreter
• Need a lot of GOOD documentation
11. DSL in Ruby
• String/symbol + Hash everywhere
• lack of “Syntax Error”
• everything is void*
• anything is ok for ruby interpreter
• Need a lot of GOOD documentation
• and memorization
18. Configuration
• Self-referential Function
type option func(*Service)
func (s *Service) Config(opts ...option) {
for _, opt := range opts {
opt(s)
}
}
func LogLevel(level int) option {
return func(s *Service) {
s.ErrorLevel = level
}
}
http://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html
19. Struct Tag
type Person struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
MiddleName string `json:"middle_name,omitempty"`
}
20. Struct Tag
• Anti-Pattern
• String-typing
• No compile time checking
• 6 month old bug in KKTIX production, no one noticed
• based on reflect
• slow
• Don’t use it as DSL
23. Error Handling in Go
• Extremely Verbose
• We already have 3 official error handling patterns
• https://blog.golang.org/errors-are-values
• checking error is fine. But I’m lazy to type
• Messy control flow