<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Harrison</title>
    <description>The latest articles on DEV Community by David Harrison (@dbh).</description>
    <link>https://dev.to/dbh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F97879%2Ff089ee65-4cd1-4752-891d-16101e97f02a.jpeg</url>
      <title>DEV Community: David Harrison</title>
      <link>https://dev.to/dbh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dbh"/>
    <language>en</language>
    <item>
      <title>GoLang - Initial Experience</title>
      <dc:creator>David Harrison</dc:creator>
      <pubDate>Fri, 13 Sep 2019 04:41:55 +0000</pubDate>
      <link>https://dev.to/dbh/golang-initial-experience-oa6</link>
      <guid>https://dev.to/dbh/golang-initial-experience-oa6</guid>
      <description>&lt;p&gt;Recently, I decided to try out GoLang for implementing a CRUD API, in a new project. I've got lots of experience in Java, Groovy, some Python, most recently.&lt;/p&gt;

&lt;p&gt;More of my recent experience has been in Java or Groovy plus Spring Boot. I'm getting a little bored, so why not take on some learning curve and have some fun?&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Here are some of the requirements&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Design and implement Data Model for a Domain&lt;/li&gt;
&lt;li&gt;  Implement CRUD API&lt;/li&gt;
&lt;li&gt;  Mongo database backend&lt;/li&gt;
&lt;li&gt;  Must have Swagger Definition to document API and facilitate generating clients in various languages.&lt;/li&gt;
&lt;li&gt;  Run in a Docker container&lt;/li&gt;
&lt;li&gt;  Can be deployed into Kubernetes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Non-functional requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Needs to be easy to consume API, in other languages.&lt;/li&gt;
&lt;li&gt;  Need to be able to move fast (and probably break things)&lt;/li&gt;
&lt;li&gt;  Must have unit tests&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Nice-to-Have
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Conservative on memory consumption.

&lt;ul&gt;
&lt;li&gt;  This is important if I want to run things in a memory constrained environment, such as a Raspberry Pi 2B with 512 MB RAM.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  Needs to be fun and be a learning experience&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Modules &amp;amp; Libraries Used
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Functionality&lt;/th&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Database access&lt;/td&gt;
&lt;td&gt;mongo-go-driver&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Routing&lt;/td&gt;
&lt;td&gt;go-chi&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;REST API JSON Patch&lt;/td&gt;
&lt;td&gt;json-patch&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unit Tests&lt;/td&gt;
&lt;td&gt;testify&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Swagger API Definitions&lt;/td&gt;
&lt;td&gt;go-swagger&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;p&gt;The language is strikingly similar to C and Java. A background in both made it extremely easy to pick up enough proficiency in Go to achieve a starter project.&lt;/p&gt;

&lt;p&gt;I particularly like the simplicity and clarity of the code, in GoLang.&lt;/p&gt;

&lt;p&gt;To be fair, I also like highly opinionated frameworks with as little boiler-plate code as possible. A combination of Java 11+ or Groovy, Spring Boot, Spring Data, Project Lombok, and perhaps Spring Data REST, makes me happy, too. Honestly, sometimes the magic of Spring Boot Data REST is a little bit too much.&lt;/p&gt;

&lt;p&gt;Go's 'defer' keyword is perhaps one of my favorite features. Delaying some action until the function exits is a fantastic was of closing resources and also logging the exit action of a function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Just Different or Awkward
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Error handling, a little bit cumbersome&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Error handling was a bit different, coming from a Java background. I found it to require being more explicit in Go. &lt;/p&gt;

&lt;p&gt;In Java, a method could throw an exception, catch one or more exceptions, swallow them (probably a bad thing), or rethrow for the caller to handle, go requires the pattern of calling a method, evaluating whether there was an error. We can debate whether that is good or not. &lt;/p&gt;

&lt;p&gt;I found Go's error detection and passing to take a little adjustment period and a little bit tedious, but certainly workable.&lt;/p&gt;

&lt;p&gt;// I often see this pattern in the code&lt;/p&gt;

&lt;p&gt;&lt;code&gt;obj1, err := doohickey.doSomething(someArg)  &lt;br&gt;
if err !=nil {  &lt;br&gt;
   log.Println("doohickey.doSomething got error error: ", err)  &lt;br&gt;
   return  &lt;br&gt;
}  &lt;br&gt;
obj2, err2 := widget.doSomethingElse(otherArg)  &lt;br&gt;
if err2 !=nil {  &lt;br&gt;
   log.Println("Widget doSomethingElse returned error: ", err2)  &lt;br&gt;
   return  &lt;br&gt;
}  &lt;br&gt;
//...&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;JSON Response Types, to Struct Mapping&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Regarding Go, JSON, and Static Types,  I found it a little bit confusing and awkward on how to handle dynamic JSON and parse that into structs in Go.&lt;/p&gt;

&lt;p&gt;This was much easier in Groovy and Python, as they're totally fine with dynamically converting JSON into a map of other things.&lt;/p&gt;

&lt;p&gt;In Go, Deserializing JSON into a Struct and Serializing it back was not substantially different than in other languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Catching-Up in Maturity
&lt;/h3&gt;

&lt;p&gt;Actually, I didn't find anything "bad" about it.  Rather, I did find what would normally be expected.  Since Go is a relatively new language, it is still playing catch-up in some areas. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Go&lt;/strong&gt; &lt;strong&gt;Dependencies and Versioned Module Repositories&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Having come from using dependency management and build tools such as Java's  Gradle and Maven, I naturally wanted the same level of dependency management within Go.&lt;/p&gt;

&lt;p&gt;While I was writing this,  &lt;a href="https://golang.org/doc/go1.13"&gt;Go Lang 1.13&lt;/a&gt; came out with support for Google's Module Proxy, having this to say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As of Go 1.13, the go command by default downloads and authenticates modules using the Go module mirror and Go checksum database run by Google. See &lt;a href="https://proxy.golang.org/privacy"&gt;https://proxy.golang.org/privacy&lt;/a&gt; for privacy information about these services and the &lt;a href="https://golang.org/cmd/go/#hdr-Module_downloading_and_verification"&gt;go command documentation&lt;/a&gt; for configuration details including how to disable the use of these servers or use different ones. If you depend on non-public modules, see the &lt;a href="https://golang.org/cmd/go/#hdr-Module_configuration_for_non_public_modules"&gt;documentation for configuring your environment&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Concluding Thoughts
&lt;/h2&gt;

&lt;p&gt;It was surprisingly easy to pick up Go Lang well enough to be productive.  I found it pleasant and fun.  Enhancing the REST API, refining the data model, generating the swagger doc, and creating unit tests were snappy and good experiences.&lt;/p&gt;

&lt;p&gt;I will definitely learn more GoLang based on this experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  GoLang 1.11 Modules &lt;a href="https://github.com/golang/go/wiki/Modules"&gt;https://github.com/golang/go/wiki/Modules&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Error Handling in Go, &lt;a href="https://github.com/golang/go/wiki/Modules"&gt;https://github.com/golang/go/wiki/Modules&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>rest</category>
      <category>api</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>Java 11: Making RMI calls and EJBs work again</title>
      <dc:creator>David Harrison</dc:creator>
      <pubDate>Thu, 21 Feb 2019 00:36:10 +0000</pubDate>
      <link>https://dev.to/dbh/java-11-making-rmi-calls-and-ejbs-work-again-1l5b</link>
      <guid>https://dev.to/dbh/java-11-making-rmi-calls-and-ejbs-work-again-1l5b</guid>
      <description>&lt;p&gt;As part of a new project, I explored the possibly of re-using an EJB. This is to leverage existing business logic rather than cloning, which would then need to also be maintained separately. &lt;/p&gt;

&lt;p&gt;Attempting to Compile the EJB calling code in Java 11 served up a quick reminder.   As part of JEP 320,  the following are removed from Java.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;java.corba module&lt;/li&gt;
&lt;li&gt;javax.rmi.CORBA&lt;/li&gt;
&lt;li&gt;javax.rmi (RMI-IIOP packages)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example section of code which would not compile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Context context = new InitialContext();
Object raw = context.lookup(jndiName);
ARemoteType type = (ARemoteType )PortableRemoteObject.narrow(raw, ARemoteType .class);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Luckily, under the Eclipse Foundation's Java EE, the Glassfish implementation of CORBA and RMI-IIOP is available! Including the Gradle snippet below allowed the code to compile and work without any change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;implementation group: 'org.glassfish.corba', name: 'glassfish-corba-orb', version: '4.2.0'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;References&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.davidbharrison.com/java-11-rmi-corba-and-ejbs/"&gt;Same short article on my blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://openjdk.java.net/jeps/320#CORBA-and-JTA-modules"&gt;JEP 320: Remove the Java EE and CORBA Modules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javaee.github.io/glassfish-corba/"&gt;GlassFish CORBA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mvnrepository.com/artifact/org.glassfish.corba/glassfish-corba-orb"&gt;Maven Repository&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>rmi</category>
      <category>corba</category>
      <category>ejb</category>
    </item>
  </channel>
</rss>
