
Go, robots and refactoring - mattetti
http://matt.aimonetti.net/posts/2014/04/28/refactoring-go-code/
======
enneff
I would suggest naming the method "Device" instead of "GetDevice". The word
"Get" is almost always redundant.

~~~
mattetti
I totally agree, I found myself refactoring my own code and renaming "Get<>()"
functions. I wish I had heard someone say that earlier :)

m.FindRobot("bot name").GetDevice("laser") would read better as m.Robot("bot
name").Device("laser")

~~~
zura
Agree, but due to my mild OCD, I still keep using Get to pair with Set :)

~~~
davvid
Another reason I've heard for avoiding getFoo() is that on certain typefaces
the lower-case "g" and "s" look similar enough that folks with bad vision can
confuse them[1]. Thus foo() and setFoo() are clearer than getFoo() and
setFoo().

[1] Given enough time in front of a monitor, we all get bad vision eventually
;-)

~~~
plorkyeran
That's easily solved by just not using typefaces that you can't read in your
editor.

------
wyager
>Go aka golang is an amazing language

By what standard? I've been very underwhelmed.

The type system is very mediocre. Support for generic programming is awful.
What kind of language idiomatically involves casting to the top type? That
would be like if Java idiomatically involved casting to Object, or C++
idiomatically involved casting to void*, just to get any sort of genericism.
Look at almost any big Go project; the abundance of {}interface typed
variables is alarming

And then how about language extensibility? Go relies heavily on built-in
keywords, like range and make(). You want to range over a tree or a linked
list? Too bad. You can only use built-in types. Or maybe you can wrap your
data structure in a chan and range over that. Goodbye performance and
simplicity.

Go is not a bad language. I use it on a number of web projects, and it works
very well. But Go is not, by any metric I can think of, an "amazing" language.
At best, it is a decent language with lots of corporate support, a good
standard library, and some good tools like golint, go get, and go fmt.

~~~
PopsiclePete
I don't know what your definition of "amazing" language is, then, but a decent
language with corporate support, a good standard library and good
tools....is...well...pretty darn "amazing" in my book.

It maybe doesn't tickle me on an intellectual level, the way Haskell or
Clojure do, sure, but for getting real work done, I'd choose it any day over
those two.

Other "exciting" languages that play in the same field as Go are perhaps Rust
and D, but neither of those have the same corporate/community support, tools,
eco-system, etc.

~~~
wyager
>but a decent language with corporate support, a good standard library and
good tools....is...well...pretty darn "amazing" in my book.

This also describes Java in 1997. I wouldn't call that an amazing language
either.

>Other "exciting" languages that play in the same field as Go are perhaps Rust
and D, but neither of those have the same corporate/community support, tools,
eco-system, etc.

I don't know enough about D to speak about it, but at least Rust has a good
type system (based on hindley-milner), support for generic programming,
pattern matching, extensibility, etc. I'd personally call Rust "well-
designed".

~~~
renox
>This also describes Java in 1997. I wouldn't call that an amazing language
either.

You're joking right? I've used Java around 1998 and its standard library
wasn't good, "java can't print" was quite true back then..

------
codegangsta
Nice post Matt! I would love to see more of these eyewitness accounts of
refactoring in the go community. Maybe a refactoring video should be in the
works ;)

~~~
mattetti
Thanks Jeremy, let's book a few hours and do that together.

------
2mur
This is really helpful. I'm getting started with Go now and common idioms and
refactoring are useful when moving past the tour and introduction stage.

------
joefitzgerald
This is a really helpful article - nice work Matt.

~~~
mattetti
Thanks joe, I realized that the best way to learn is to refactor with one or
more people. Hopefully, this summary of a quick refactoring will help others
too.

------
djb_hackernews
Go looks interesting. Anyone else not a fan of the single character variable
names?

Also, Is there a better way, in terms of clarity, to do this:

<\- c

Even with the comment I would think the developer forgot to fill in the first
half of that and assume it was a bug.

~~~
mattetti
In the first version of the post I had

_ = <\- c

To show that we don't use the value read from the channel, but someone in my
team pointed that, that this isn't very idiomatic and mainly a way to explain
what the code does to someone who doesn't know Go.

------
solojavier
Thanks for sharing this Matt.. really good insight.

------
wolfeidau
Great post really enjoyed it.

Also a big fan of golang, loving the posts by people using it in anger.

Thanks

