Similar blocks of code found in 2 locations. Consider refactoring. Open
func (a *Array) Inspect() string {
var out bytes.Buffer
elements := []string{}
for _, e := range a.Elements {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 129.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
exported const ERROR_OBJ should have comment (or a comment on this block) or be unexported Open
ERROR_OBJ = "ERROR"
- Exclude checks
exported method Boolean.Inspect should have comment or be unexported Open
func (b *Boolean) Inspect() string { return fmt.Sprintf("%t", b.Value) }
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
BOOLEAN_OBJ = "BOOLEAN"
- Exclude checks
comment on exported type Integer should be of the form "Integer ..." (with optional leading article) Open
// === Integer ===
- Exclude checks
exported method ReturnValue.Inspect should have comment or be unexported Open
func (rv *ReturnValue) Inspect() string { return rv.Value.Inspect() }
- Exclude checks
comment on exported type Exit should be of the form "Exit ..." (with optional leading article) Open
// === Exit ===
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
INTEGER_OBJ = "INTEGER"
- Exclude checks
exported method Exit.Inspect should have comment or be unexported Open
func (e *Exit) Inspect() string {
- Exclude checks
exported method Error.Type should have comment or be unexported Open
func (e *Error) Type() ObjectType { return ERROR_OBJ }
- Exclude checks
exported method String.Type should have comment or be unexported Open
func (s *String) Type() ObjectType { return STRING_OBJ }
- Exclude checks
exported method Null.Inspect should have comment or be unexported Open
func (n *Null) Inspect() string { return "null" }
- Exclude checks
type name will be used as object.ObjectType by other packages, and that stutters; consider calling this Type Open
type ObjectType string
- Exclude checks
comment on exported type String should be of the form "String ..." (with optional leading article) Open
// === String ===
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
BUILTIN_OBJ = "BUILTIN"
- Exclude checks
exported method Error.Inspect should have comment or be unexported Open
func (e *Error) Inspect() string {
- Exclude checks
comment on exported type Null should be of the form "Null ..." (with optional leading article) Open
// === Null ===
- Exclude checks
comment on exported type ReturnValue should be of the form "ReturnValue ..." (with optional leading article) Open
// === Return ===
- Exclude checks
exported method Builtin.Inspect should have comment or be unexported Open
func (b *Builtin) Inspect() string { return "builtin function" }
- Exclude checks
comment on exported type Error should be of the form "Error ..." (with optional leading article) Open
// === Errors ===
- Exclude checks
exported method Integer.Inspect should have comment or be unexported Open
func (i *Integer) Inspect() string { return fmt.Sprintf("%d", i.Value) }
- Exclude checks
exported method Boolean.Type should have comment or be unexported Open
func (b *Boolean) Type() ObjectType { return BOOLEAN_OBJ }
- Exclude checks
exported method Function.Inspect should have comment or be unexported Open
func (f *Function) Inspect() string {
- Exclude checks
comment on exported type BuiltinFunction should be of the form "BuiltinFunction ..." (with optional leading article) Open
// === Builtin ===
- Exclude checks
exported method Exit.Type should have comment or be unexported Open
func (e *Exit) Type() ObjectType { return EXIT_OBJ }
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
ERROR_OBJ = "ERROR"
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
NULL_OBJ = "NULL"
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
RETURN_VALUE_OBJ = "RETURN_VALUE"
- Exclude checks
exported method Builtin.Type should have comment or be unexported Open
func (b *Builtin) Type() ObjectType { return BUILTIN_OBJ }
- Exclude checks
exported method Null.Type should have comment or be unexported Open
func (n *Null) Type() ObjectType { return NULL_OBJ }
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
ARRAY_OBJ = "ARRAY"
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
EXIT_OBJ = "EXIT"
- Exclude checks
exported type Object should have comment or be unexported Open
type Object interface {
- Exclude checks
exported method String.Inspect should have comment or be unexported Open
func (s *String) Inspect() string { return s.Value }
- Exclude checks
exported method Function.Type should have comment or be unexported Open
func (f *Function) Type() ObjectType { return FUNCTION_OBJ }
- Exclude checks
comment on exported type Array should be of the form "Array ..." (with optional leading article) Open
// === Array ===
- Exclude checks
exported method Array.Inspect should have comment or be unexported Open
func (a *Array) Inspect() string {
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
FUNCTION_OBJ = "FUNCTION"
- Exclude checks
comment on exported type Boolean should be of the form "Boolean ..." (with optional leading article) Open
// === Boolean ===
- Exclude checks
exported method Array.Type should have comment or be unexported Open
func (a *Array) Type() ObjectType { return ARRAY_OBJ }
- Exclude checks
exported method Integer.Type should have comment or be unexported Open
func (i *Integer) Type() ObjectType { return INTEGER_OBJ }
- Exclude checks
exported type ObjectType should have comment or be unexported Open
type ObjectType string
- Exclude checks
exported method ReturnValue.Type should have comment or be unexported Open
func (rv *ReturnValue) Type() ObjectType { return RETURN_VALUE_OBJ }
- Exclude checks
exported type Builtin should have comment or be unexported Open
type Builtin struct {
- Exclude checks
don't use ALL_CAPS in Go names; use CamelCase Open
STRING_OBJ = "STRING"
- Exclude checks
comment on exported type Function should be of the form "Function ..." (with optional leading article) Open
// === Function ===
- Exclude checks