{"id":2987,"date":"2018-08-13T22:01:06","date_gmt":"2018-08-13T22:01:06","guid":{"rendered":"https:\/\/blog.paranoidprofessor.com\/?p=2987"},"modified":"2018-08-13T22:01:06","modified_gmt":"2018-08-13T22:01:06","slug":"simplicity-in-development-or-syntactic-sugar","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2018\/08\/13\/simplicity-in-development-or-syntactic-sugar\/","title":{"rendered":"Simplicity in development or syntactic sugar"},"content":{"rendered":"<p>Computing is a pretty big field so it is not always possible to stay on top of every little (or big) framework or enhancement that comes down the line.\u00a0 I am happy to be involved in software development so I can get a quick heads up when something really cool comes down the line.<\/p>\n<p>Unfortunately I found out about a new thing (for me) in the worst possible way.\u00a0 I had just joined a new project and was coming up to speed on some of the technologies that was different from my last project.<\/p>\n<ul>\n<li>Java (that isn&#8217;t end of life)<\/li>\n<li>Git<\/li>\n<li>Spring Toolset<\/li>\n<li>Hibernate<\/li>\n<li>New data model<\/li>\n<li>Different business area<\/li>\n<\/ul>\n<p>In short there were no limit to things that I needed to spend my time coming up to speed on when I did the fateful command.<\/p>\n<blockquote>\n<h4>git pull<\/h4>\n<\/blockquote>\n<p>Yup, all I did was to refresh my workspace with the most recent code from our server.<\/p>\n<p>Oh, sure, the code compiled once I installed the tool <a href=\"https:\/\/projectlombok.org\/\" target=\"_blank\" rel=\"noopener\">Lombok <\/a>into my IDE and added it to my classpath.\u00a0\u00a0The surprise was that the code that compiled no longer ran.<\/p>\n<h2>The culprit<\/h2>\n<p>What does Lombok do?\u00a0 It is actually a really interesting use of the annotations that were added all those years ago in java 1.5. The purpose of Lombok it to reduce the amount of boilerplate code that needs to be manually entered that is added to all (well a lot) of projects by virtually everyone.\u00a0 Not only that, it is possible to use the methods that Lombok creates even though they are not physically stored in the source code file.<\/p>\n<p>Basically, this allows you to see and focus on the really interesting parts of your code that add value and not be distracted by some of the less interesting boilerplate code that you also added.<\/p>\n<p>I am not going to cover everything that Lombok supports as that is all <a href=\"http:\/\/jnb.ociweb.com\/jnb\/jnbJan2010.html#intro\" target=\"_blank\" rel=\"noopener\">nicely documented<\/a>.\u00a0 I will just focus on a few of the annotations.<\/p>\n<ul>\n<li>@Getter<\/li>\n<li>@Setter<\/li>\n<li>@Data<\/li>\n<\/ul>\n<p>The first two actually do pretty much what they sound like.\u00a0 If you add this annotation before your variable then Lombok will automatically generate the getter and setter for you.\u00a0 Not only that but it will add these methods to the outline tab in your editor.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2992\" src=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok3.png\" alt=\"\" width=\"803\" height=\"641\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok3.png 803w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok3-300x239.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok3-768x613.png 768w\" sizes=\"(max-width: 803px) 100vw, 803px\" \/><\/p>\n<p>On the left is my own code and on the right is the outline showing the methods and variables for that class.\u00a0 If you look closely enough you can see that no &#8220;get&#8221; method has been created for the iq or age variables and no &#8220;get&#8221; or &#8220;set&#8221; have been created for the internalvalue variable.<\/p>\n<p>This code is obviously much smaller and would allow the programmer to be more focused on the real logic.\u00a0 \u00a0So this new project actually does add value.<\/p>\n<p>If the Java object is really just an abstract object then there is an easier way than adding all of these &#8220;@Setter&#8221; and &#8220;@Getter&#8221; annotations it is possible to add a single @Data annotation.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@NoArgsConstructor\r\npublic &lt;strong&gt;@Data&lt;\/strong&gt; class ComplicatedObject \r\n{\r\n\tprivate String First;\r\n\tprivate String Last;\r\n\tprivate int age;\r\n\tprivate String Address;\r\n\tprivate String City;\r\n\tprivate String State;\r\n\tprivate int zipcode;\r\n\tprivate int iq;\r\n\tprivate int internalvalue;\r\n\r\n\tpublic static void main(String[] args) \r\n\t{\r\n\t\tComplicatedObject person = new ComplicatedObject();\r\n\t\t\r\n\t\tperson.setFirst(&quot;Max&quot;);\r\n\t\tperson.setLast(&quot;Musterman&quot;);\r\n\t\tperson.setAddress(&quot;123 Main street&quot;);\r\n\t\tperson.setCity(&quot;Smalltown&quot;);\r\n\t\tperson.setState(&quot;IA&quot;);\r\n\t\tperson.setZipcode(12345);\r\n\t\tperson.setIq(125);\r\n\t\t\r\n\t\tSystem.out.println(person.toString());\r\n\t}\r\n}\r\n<\/pre>\n<h2><\/h2>\n<h2>Installation<\/h2>\n<p>The installation process is actually super simple.\u00a0 Simply run the lombok.jar file and it will open up a small installer.\u00a0 First it searches for all installed IDE&#8217;s and presents them as a list of locations to install lombok.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-2994 size-full\" src=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok4.png\" alt=\"\" width=\"854\" height=\"498\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok4.png 854w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok4-300x175.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok4-768x448.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/p>\n<p>Once the IDE has been selected it takes hardly a second to finish the setup of lombok.\u00a0 In order to use it you simply need to restart the IDE and add the lombok.jar file to any projects that you wish to use this new functionality.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-2995 size-full\" src=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok5.png\" alt=\"\" width=\"854\" height=\"498\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok5.png 854w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok5-300x175.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/08\/lombok5-768x448.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>The good<\/h2>\n<p>The software both installs very simply and is limited to a single jar file. This makes it really easy to add to a project and to later remove if necessary.<\/p>\n<p>&nbsp;<\/p>\n<h2>The bad<\/h2>\n<p>I don&#8217;t really have any &#8220;hard proof&#8221; that Lombok itself was problematic to my work project.\u00a0 I downloaded lombok and did a small test at home.\u00a0 I didn&#8217;t have any difficulties and the functionality is pretty neat.<\/p>\n<p>Thus there is nothing bad to report but this functionality is mainly to simplify the definitions of getters and setters for some plain old java class that is just an abstract data type.<\/p>\n<p>If this is the extent of what is necessary you could go back to the olden days and just have an object and address each field directly.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage com.company.de;\r\n\r\npublic class ComplicatedObject2 \r\n{\r\n\tString First;\r\n\tString Last;\r\n\tint age;\r\n\tString Address;\r\n\tString City;\r\n\tString State;\r\n\tint zipcode;\r\n\tint iq;\r\n\r\n\tpublic String toString()\r\n\t{\r\n\t\treturn First + &quot; &quot; + Last + &quot; &quot; + Address + &quot; &quot; + City + &quot; &quot; + State + &quot; &quot; + zipcode + &quot; &quot; + iq;\r\n\t}\r\n\tpublic static void main(String[] args) \r\n\t{\r\n\t\tComplicatedObject2 person = new ComplicatedObject2();\r\n\r\n\t\tperson.First = &quot;Max&quot;;\r\n\t\tperson.Last = &quot;Musterman&quot;;\r\n\t\tperson.Address = &quot;123 Main street&quot;;\r\n\t\tperson.City = &quot;Smalltown&quot;;\r\n\t\tperson.State = &quot;IA&quot;;\r\n\t\tperson.zipcode = 12345;\r\n\t\tperson.iq = 125;\r\n\r\n\t\tSystem.out.println(person.toString());\r\n\t}\r\n}\r\n<\/pre>\n<p>I am not saying you should do this but this is essentially what adding all getters and setters to a simple java class does.<\/p>\n<h2>The ugly<\/h2>\n<p>We did have a few problems with Lombok in our project but I think that this might have been due to a misconfiguration.\u00a0 We are still looking into that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Computing is a pretty big field so it is not always possible to stay on top of every little (or big) framework or enhancement that comes down the line.\u00a0 I am happy to be involved in software development so I &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2018\/08\/13\/simplicity-in-development-or-syntactic-sugar\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[12],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2987"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=2987"}],"version-history":[{"count":7,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2987\/revisions"}],"predecessor-version":[{"id":3003,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2987\/revisions\/3003"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=2987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=2987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=2987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}