Skip to content

Instantly share code, notes, and snippets.

@cwestin
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwestin/07992139772df8f7ba0e to your computer and use it in GitHub Desktop.
Save cwestin/07992139772df8f7ba0e to your computer and use it in GitHub Desktop.
Problems with Go
================
General
=======
Public export based on the case of a letter
- change of visibility requires renaming
Package definitions
- can add more things to a package (within the same directory) just by declaring them so
- can't be sure what belongs to a package without inspecting all files in a directory
defer is not block scoped
declaration and usage of a variable do not match; confusing (unlike C/C++)
for a statically typed language, no parametric polymorphism
- interface{} is really (void *)
- only magic built-in types get to use parametric polymorphism
Can't initialize string-valued slices:
foo := "foo"
bar := "bar"
b := []*string{ &foo, &bar }
Is there a way I can get this into one line? I don't care about foo or
bar variables, I only need to define some complex test data.
For complex types that works well, e.g.
somearray := []*arraytype{
&arraytype{ foo: 1, bar: "test" },
&arraytype{ foo: 5, bar: "buz" },
}
...
But how can I define complex data that includes pointers to simple
types? &string{"test"} etc. won't work like complex types.
There's no const/final
No inheritance, but no composition mechanisms (mixins, delegation) either.
map and slice reference/value mechanics:
https://groups.google.com/d/msg/golang-nuts/xzdPCjKORNA/c0irW-PVjEwJ
Pointer inconsistencies:
You can have a pointer to a struct, but not to an interface at the same level
- consequence: a change of declaration for an argument from a struct ptr to an interface requires removing the stars
- if you have a pointer and try to pass it to something that takes a value, the compiler will dereference automatically
- but not for map[] arguments
- can save the address of a local variable without problems!
Maintenance Issues (or, "Dealing with Pre-Existing Code")
=========================================================
Documentation/godoc: without explicit parameter demarcations (e.g. "@param") in
block comments, there's no way to tell if the parameters changed; had a case
with function where parameters changed but comments were never updated was not
detected.
Can't tell the difference between package.Name and class.Method references.
Can't find concrete implementations of abstract classes -- names of interfaces
don't appear anywhere (e.g. "class Foo implements SomeInterface").
- can't find implementations in order to examine them before making changes to
an interface; only solution is make the change and compile the world to see
what breaks
Multiple ways to do assignments:
x := ... to create a new variable with inferred type
var x = ... to create a new top-level variable with inferred type
x: ... to initialize a structure member
x = ... to mutate a pre-existing variable
x, y, z = a, b, c ... multiple assignment
- these make it hard to track down mutations to a variable with editor searches
such as "variableName = "
Comparisons with Scala
======================
After Odersky Scala style talk: other: pattern matching vs function overloading
Pattern matching for multiple type combinations is function overloading, but
without the need for name mangling. Does this handle double dispatch well?
Other
=====
for x:= range foo
iterates elements if foo is a channel, but not if it's a slice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment