• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Request for comments / critique on Go code

 
Sheriff
Posts: 13713
227
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anyone is interested, I have posted my modifications/enhancements to the example life.go program on GitHub.

(All links below go to my github repo at https://github.com/jlacar/golang-learn/tree/master/life)

A summary of what I have added on top of the original example:

1. A number of command line options. Build the project and then type "life -help" on the command line to see what those options are.

2. Most of the enhancements are in the main/life.go program. This includes the setup for the command line options enhancements as well as a lot of refactoring of the original example.

3. Added the ability to specify a file from which to read an initial field configuration.  The field-defs/README.md describes the field definition file format. The code that reads the field definition file and provides FieldLocations for the life.go program can be found in main/fileseeder.go  There are a number of sample field definition files in the field-defs directory.

Any and all comments on my implementation and enhancements are welcome. Thanks!
 
Sheriff
Posts: 21788
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you're asking for critique on your Go code... And here I was thinking I finally got to rant on Go!
 
Junilu Lacar
Sheriff
Posts: 13713
227
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be interested to know what your rants are. I don't imagine it's something that most seasoned Java programmers would immediately fall in love with but the language does have its own little charms. I've actually warmed up to it after spending a couple of weeks wrangling this little Game of Life program.

The object-orientation is definitely weird and takes a little getting used to. I haven't gotten to a point where I know if inheritance is even something that can be done in Go, seems like the creators made a conscious choice to prefer composition and duck typing instead.
 
Junilu Lacar
Sheriff
Posts: 13713
227
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My biggest motivation for learning Go is the fact that the Docker engine was written in Go.  I'd like to understand the code for the Docker engine, therefore, I need to understand Go.
 
Rob Spoor
Sheriff
Posts: 21788
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've only been an adviser in a Go project, but so far what I hate:
* No inheritance. Sure, you can get around it with composition, but in some cases inheritance simply is better.
* Pointer assignments. I've actually been struggling with this one for a while, because it's not possible in Go to assign a literal value to a pointer. (Granted, this is also not possible in language like C, but still.) I ended up creating a little function per type that looks like this:

So yeah, give me languages like Java and C# any day of the week. I even prefer PHP, Python and Ruby over Go to be honest.
 
Junilu Lacar
Sheriff
Posts: 13713
227
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:I've only been an adviser in a Go project, but so far what I hate:
* Pointer assignments... I ended up creating a little function per type that looks like this:


I'm curious, what do you get from that function over code like this:

You can try it in the playground: https://play.golang.org/p/-dT4EgRj2Z
 
Junilu Lacar
Sheriff
Posts: 13713
227
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:... so far what I hate:
* No inheritance. Sure, you can get around it with composition, but in some cases inheritance simply is better.

... I even prefer PHP, Python and Ruby over Go to be honest.


When I first started out in programming, I learned BASIC and Pascal at the same time. Right now, I'm trying to learn Go and Kotlin at the same time. I haven't gotten to a point in my learning Go where I really miss not having inheritance. I'll have to try to find a non-trivial problem in Java where inheritance is a natural fit and try to translate it to Go.

I like Python and Ruby; I'm ambivalent about Scala but mostly because the programs that I have had to work with that were written by programmers other than Martin Odersky have generally sucked b*lls. I haven't dabbled in PHP though.

 
Rob Spoor
Sheriff
Posts: 21788
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Rob Spoor wrote:I've only been an adviser in a Go project, but so far what I hate:
* Pointer assignments... I ended up creating a little function per type that looks like this:


I'm curious, what do you get from that function over code like this:

You can try it in the playground: https://play.golang.org/p/-dT4EgRj2Z


I know it's possible to use temporary variables instead, but these add extra clutter - more variables to remember. When I searched for a solution I found this, and we decided to go for option 4 instead of option 2 (ugly and verbose) or 3.

So your example becomes this, which is just as easy to read, and the function name* make its intention clear:

* The project we use has 4 versions, for string, int32, int64 and bool. We have to use pointers for these fields because they are all optional, and nil is the only way to achieve that.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!