I ThinkThereforeI Code2016-08-09T01:05:33+02:00http://there4.coJuan José AguilillaDavid vs Goliath2015-07-08T00:00:00+02:00http://there4.co/tools/projects/2015/07/08/david-vs-goliath<p>Yeah, it’s been a looong time, but I’m back on track with the blog.</p>
<p>Today, I want to prove that being big is not always an advantage, and I want to do it comparing two
Web frameworks.</p>
<p>On one side, with green shorts, a lot of features… and even more annotations is: <a href="http://projects.spring.io/spring-boot/">Spriiiiing
Booot</a>, on the other side with black pants, a funny name and a very simple approach is:
<a href="http://there4.co/sabina/">Saaaabina</a></p>
<p>Ladies and gentlemen, let the fight begin.</p>
<p>For this match, I did some tests to measure size, cpu usage, memory, etc. do not expect nothing
too fancy here anyway. If you are courious about the tests, you can check the code in this <a href="https://github.com/jaguililla/boot-vs-sabina">Github
repository</a>.</p>
<p>The project to test both frameworks was the simplest one (yes, a Hello World project). And the
tools I used to measure the performance were Bash shell scripts, <a href="http://jmeter.apache.org/">JMeter</a> and Java’s <a href="https://visualvm.java.net/">VisualVM</a>.</p>
<h1 id="system-information">System Information</h1>
<p>First of all I will describe the laptop used to run the tests:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>Architecture: x86_64
CPU(s): 8
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Model name: Intel(R) Core(TM) i7-4712MQ CPU @ 2.30GHz
CPU MHz: 1434.445
CPU max MHz: 3300.0000
CPU min MHz: 800.0000
BogoMIPS: 4589.46
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
total used free shared buffers cached
Mem: 7.7G 3.6G 4.1G 188M 36M 2.1G
-/+ buffers/cache: 1.5G 6.2G
Swap: 953M 27M 926M
Total: 8.7G 3.7G 5.0G
</code></pre>
</div>
<h1 id="code-size">Code Size</h1>
<p>The first comparison I made was about the code size. Here are the results:</p>
<h2 id="spring-boot">Spring Boot</h2>
<div class="highlighter-rouge"><pre class="highlight"><code>28 39 hello-boot/build.gradle
18 34 hello-boot/src/main/java/hello/Hello.java
46 73 total
</code></pre>
</div>
<h2 id="sabina">Sabina</h2>
<div class="highlighter-rouge"><pre class="highlight"><code>13 19 hello-sabina/build.gradle
10 24 hello-sabina/src/main/java/hello/Hello.java
23 43 total
</code></pre>
</div>
<p>The first column is the number of lines, and the second one the number of words. And as we can see
Sabina is nearly half the size of the Boot project.</p>
<h1 id="build-process">Build Process</h1>
<p>Let’s continue with the build time and binary bundle size. For this test I built both projects
three times and then I picked the best results out of the three executions. These were the results:</p>
<h2 id="spring-boot-1">Spring Boot</h2>
<div class="highlighter-rouge"><pre class="highlight"><code>Command being timed: "/opt/gradle-2.4/bin/gradle -q --no-daemon -p hello-boot clean build"
User time (seconds): 17.16
System time (seconds): 0.39
Percent of CPU this job got: 333%
-rw-r--r-- 1 jam jam 11M Jul 9 00:53 hello-boot.zip
</code></pre>
</div>
<h2 id="sabina-1">Sabina</h2>
<div class="highlighter-rouge"><pre class="highlight"><code>Command being timed: "/opt/gradle-2.4/bin/gradle -q --no-daemon -p hello-sabina clean build"
User time (seconds): 14.06
System time (seconds): 0.26
Percent of CPU this job got: 315%
-rw-r--r-- 1 jam jam 4.2M Jul 9 00:52 hello-sabina.zip
</code></pre>
</div>
<p>There is no big difference in the compile times, but the size of the Sabina’s binary bundle is less
than half than the Boot one.</p>
<h1 id="runtime">Runtime</h1>
<p>Finally, I executed 10,000 requests from 8 threads, to check the memory and CPU usage along
with the requests per second per framework.</p>
<p>Results are screenshots of <a href="http://jmeter.apache.org/">JMeter</a> and <a href="https://visualvm.java.net/">VisualVM</a>, however, if you want to see the exact numbers,
you can clone the <a href="https://github.com/jaguililla/boot-vs-sabina">repository</a> and run the test yourself.</p>
<p>Here are the results of my run:</p>
<h2 id="spring-boot-2">Spring Boot</h2>
<p><img src="https://raw.githubusercontent.com/jaguililla/boot-vs-sabina/master/results/summary-report-boot.png" alt="JMeter summary" />
<img src="https://raw.githubusercontent.com/jaguililla/boot-vs-sabina/master/results/performance-boot.png" alt="VisualVM graphs" /></p>
<h2 id="sabina-2">Sabina</h2>
<p><img src="https://raw.githubusercontent.com/jaguililla/boot-vs-sabina/master/results/summary-report-sabina.png" alt="JMeter summary" />
<img src="https://raw.githubusercontent.com/jaguililla/boot-vs-sabina/master/results/performance-sabina.png" alt="VisualVM graphs" /></p>
<p>As you can see Sabina’s times are better, but the biggest difference is in the resources’ usage. My
opinion on this is that all features Spring Boot has, impact its runtime performance.</p>
<p>So if you really need something fast and are not going to use all its features, is better if you
evaluate other options.</p>
<h1 id="disclaimer">Disclaimer</h1>
<p>Of course, these two frameworks doesn’t compete in the same league… and their feature set is
(to say it softly) not of the same size.</p>
<p>However, it was fun to compare both (though it was not a very rigorous benchmark) and the numbers
could be more precise.</p>
<p>I will repeat these tests with a more complete project. Ie: the <a href="https://github.com/jaguililla/sabina/tree/master/blog">blog used in MongoDB
courses</a>.</p>
<p>Until them, you can check real framework benchmark’s <a href="https://www.techempower.com/benchmarks/">here</a>. These two frameworks are
there, but Sabina didn’t implement all tests (another TODO in my task tracker) and I am not sure
that Spring’s version is the latest one.</p>
Bintray... The Github of Binaries2014-10-15T00:00:00+02:00http://there4.co/tools/2014/10/15/the-github-of-binaries<p>Yes, now you have plenty of places to keep your code… you can use <a href="https://github.com">Github</a> or you can go for
<a href="https://bitbucket.org">Bitbucket</a> if you want to maintain your code private.</p>
<p>Anyway, what happens if you want to actually share binaries for others to use your libraries
and/or applications?</p>
<p><a href="http://search.maven.org">Maven Central</a> is there from long time ago, but… to be honest, deploying something there is
like breaking in the Pentagon systems!</p>
<p>Sometime ago I discovered <a href="https://bintray.com">Bintray</a>, and it seemed a good place to store binary repositories
with a social touch (someone said <a href="https://github.com">Github</a>?)</p>
<p>The place seems to by sponsorized by <a href="http://www.jfrog.com">JFrog</a> makers of <a href="http://www.jfrog.com/artifactory">Artifactory</a> and… guess what, direct
competitors of <a href="http://www.sonatype.com">Sonatype</a> (Maven’s better contributors) that develops the <a href="http://www.sonatype.com/nexus">Nexus</a> repository
manager over which <a href="http://search.maven.org">Maven Central</a> runs.</p>
<p>So I decided to test it myself with two projects of my own. One is <a href="http://there4.co/sabina">Sabina</a> written in Java and
built with <a href="https://gradle.org">Gradle</a> and other (<a href="http://popapp.co">popapp.co</a>) coded in Java and built by <a href="https://maven.apache.org">Maven</a>.</p>
<p>The free version has a limit of <strong>500MB</strong>, not enough to deploy the smallest project of my
previous company, but plenty to support Open Source projects though.</p>
<p>Bintray integrates with <a href="http://search.maven.org">Maven Central</a> and <a href="https://bintray.com/bintray/jcenter">JCenter</a> which claims to be more complete than
Maven’s main repository.</p>
<p>To integrate it with your build process you need to add the following lines to your build
script (be aware that <strong>you won’t be able to deploy snapshots!</strong>):</p>
<ul>
<li>
<p>For <a href="https://gradle.org">Gradle</a>:</p>
<ul>
<li><em>build.gradle</em></li>
</ul>
</li>
</ul>
<figure class="highlight"><pre><code class="language-groovy" data-lang="groovy"> <span class="n">apply</span> <span class="nl">plugin:</span> <span class="s1">'maven-publish'</span>
<span class="c1">// ...</span>
<span class="n">configurations</span> <span class="o">{</span>
<span class="n">deployerJars</span>
<span class="o">}</span>
<span class="c1">// ...</span>
<span class="n">task</span> <span class="nf">sourceJar</span><span class="o">(</span><span class="nl">type:</span> <span class="n">Jar</span><span class="o">)</span> <span class="o">{</span>
<span class="n">from</span> <span class="n">sourceSets</span><span class="o">.</span><span class="na">main</span><span class="o">.</span><span class="na">allJava</span>
<span class="o">}</span>
<span class="n">publishing</span> <span class="o">{</span>
<span class="n">publications</span> <span class="o">{</span>
<span class="n">mavenJava</span> <span class="o">(</span><span class="n">MavenPublication</span><span class="o">)</span> <span class="o">{</span>
<span class="n">from</span> <span class="n">components</span><span class="o">.</span><span class="na">java</span>
<span class="n">artifact</span> <span class="n">sourceJar</span> <span class="o">{</span>
<span class="n">classifier</span> <span class="s2">"sources"</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="n">repositories</span> <span class="o">{</span>
<span class="n">maven</span> <span class="o">{</span>
<span class="n">url</span> <span class="s1">'https://api.bintray.com/maven/jaguililla/maven/Sabina'</span>
<span class="n">credentials</span> <span class="o">{</span>
<span class="n">username</span> <span class="s1">'jaguililla'</span>
<span class="n">password</span> <span class="nf">externalProperty</span> <span class="o">(</span><span class="s1">'.gradle/gradle.properties'</span><span class="o">,</span> <span class="s1">'bintrayPassword'</span><span class="o">)</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c1">// ...</span>
<span class="kt">def</span> <span class="n">String</span> <span class="nf">externalProperty</span> <span class="o">(</span><span class="n">String</span> <span class="n">fileName</span><span class="o">,</span> <span class="n">String</span> <span class="n">propertyName</span><span class="o">)</span> <span class="o">{</span>
<span class="n">Properties</span> <span class="n">properties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Properties</span> <span class="o">()</span>
<span class="n">properties</span><span class="o">.</span><span class="na">load</span> <span class="o">(</span><span class="n">project</span><span class="o">.</span><span class="na">rootProject</span><span class="o">.</span><span class="na">file</span> <span class="o">(</span><span class="n">fileName</span><span class="o">).</span><span class="na">newDataInputStream</span> <span class="o">())</span>
<span class="k">return</span> <span class="n">properties</span><span class="o">.</span><span class="na">getProperty</span> <span class="o">(</span><span class="n">propertyName</span><span class="o">)</span>
<span class="o">}</span></code></pre></figure>
<ul>
<li><em>.gradle/gradle.properties</em> (this file is created to avoid publishing your API key)</li>
</ul>
<figure class="highlight"><pre><code class="language-properties" data-lang="properties"><span class="py">bintrayPassword</span><span class="p">=</span><span class="s">{your Bintray api key}</span></code></pre></figure>
<p>And execute: <code class="highlighter-rouge">gradle publish</code></p>
<ul>
<li>
<p>For <a href="https://maven.apache.org">Maven</a>:</p>
<ul>
<li><em>pom.xml</em></li>
</ul>
</li>
</ul>
<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;distributionManagement&gt;</span>
<span class="nt">&lt;repository&gt;</span>
<span class="nt">&lt;id&gt;</span>{bintray repository}<span class="nt">&lt;/id&gt;</span>
<span class="nt">&lt;name&gt;</span>a meaningful name<span class="nt">&lt;/name&gt;</span>
<span class="nt">&lt;url&gt;</span>https://api.bintray.com/maven/{bintray user}/{project}<span class="nt">&lt;/url&gt;</span>
<span class="nt">&lt;/repository&gt;</span>
<span class="nt">&lt;/distributionManagement&gt;</span></code></pre></figure>
<ul>
<li><em>settings.xml</em></li>
</ul>
<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;server&gt;</span>
<span class="nt">&lt;id&gt;</span>{bintray repository}<span class="nt">&lt;/id&gt;</span>
<span class="nt">&lt;username&gt;</span>{bintray user}<span class="nt">&lt;/username&gt;</span>
<span class="nt">&lt;password&gt;</span>{your Bintray api key}<span class="nt">&lt;/password&gt;</span>
<span class="nt">&lt;/server&gt;</span></code></pre></figure>
<p>And run: <code class="highlighter-rouge">mvn source:jar deploy</code></p>
<p>To include your binaries in Maven you’ve got to request that from their site (using the Web
UI).</p>
<p>To me, this is a very good platform to support your Open Source projects, just like <a href="https://github.com">Github</a>,
<a href="https://travis-ci.org">Travis CI</a>, <a href="https://coveralls.io">Coveralls</a> and all the like. Anyway, prior to deploying to <a href="https://bintray.com/bintray/jcenter">JCenter</a> you
have to deploy the source of your project along with your binaries. To do so:</p>
<ul>
<li>For <a href="https://gradle.org">Gradle</a>:</li>
</ul>
<figure class="highlight"><pre><code class="language-groovy" data-lang="groovy"> <span class="c1">// ...</span>
<span class="n">task</span> <span class="nf">sourceJar</span><span class="o">(</span><span class="nl">type:</span> <span class="n">Jar</span><span class="o">)</span> <span class="o">{</span>
<span class="n">from</span> <span class="n">sourceSets</span><span class="o">.</span><span class="na">main</span><span class="o">.</span><span class="na">allJava</span>
<span class="o">}</span>
<span class="c1">// ...</span></code></pre></figure>
<ul>
<li>For <a href="https://maven.apache.org">Maven</a>:</li>
</ul>
<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;plugin&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.maven.plugins<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>maven-source-plugin<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>2.2.1<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;executions&gt;</span>
<span class="nt">&lt;execution&gt;</span>
<span class="nt">&lt;id&gt;</span>attach-sources<span class="nt">&lt;/id&gt;</span>
<span class="nt">&lt;phase&gt;</span>deploy<span class="nt">&lt;/phase&gt;</span>
<span class="nt">&lt;goals&gt;</span>
<span class="nt">&lt;goal&gt;</span>jar<span class="nt">&lt;/goal&gt;</span>
<span class="nt">&lt;/goals&gt;</span>
<span class="nt">&lt;/execution&gt;</span>
<span class="nt">&lt;/executions&gt;</span>
<span class="nt">&lt;/plugin&gt;</span></code></pre></figure>
<p>I hope you enjoyed and… you know, don’t make your users compile your code and deploy your
binaries!</p>
The Bali programming language2014-07-24T00:00:00+02:00http://there4.co/programming/2014/07/24/bali<p>Bali is an alternative language for the JVM that shares Java semantics but with a better
syntax. The name comes from the small island right to the east of Java.</p>
<p>Ok, Bali isn’t a programming language, at least it is not an existing programming language. It
is only a desire of a Java programmer that fell in love with Scala in his middle age crisis.</p>
<p>At the beggining Java was great, you didn’t have to take care of the memory, the API was very
complete and documented, it ran unmodified in different environments and the tools were
good… But time passes and you start seeing other languages in a different way.</p>
<p>Java is not as appealing as she was when she was young. Of course she is now more mature and
has improved over the years (generics, enums and lambdas are good proofs), but others start to
catch your eye.</p>
<p>The problem is that you shared a lot of things with Java, you planned your future with her
and you know her deep inside. You don’t want to throw all that to the thrash can and start
from scratch again!</p>
<p>Anyway, the thrill of trying new things is hard and you start flirting with other languages.
Scala, Groovy, Ruby, Python but most of them are dynamic (with its good things, and bad
things) so they don’t completely replace Java.</p>
<p>Oracle should be aware that a lot of developers consider changing language (not platform)
because it evolves slow and it is very verbose (slow to develop with). But adapting Java is
slow and should be done with care because there are a lot of code and tools to support.</p>
<p>They could avoid that situation creating a new programming language which shares the same
Java semantics but more appealing to develop with.</p>
<p>If they do, most of developers trying to find an alternative would consider their proposal
(because we trust Oracle) so they keep platform control, and it will be less fragmented.</p>
<p>It is important to note that if Oracle itself develop this language, tool vendors and
middleware developers would support it better than if it is developed by other company. Just
because they are the owners of the Java Platform and this assures the new language will be
supported properly.</p>
<p>No other JVM language has had a massive adoption yet (each of them for their own reasons)
but if Oracle itself provides an alternative, lots of programmers looking for another language
would take this option seriously.</p>
<p>These are the things I would value in this language:</p>
<hr />
<h2 id="dont-rely-on-filesystem-structure-directories-and-file-names">Don’t rely on filesystem structure (directories and file names)</h2>
<p>You end up with a lot of files and nested directories even for the smallest projects. Bali
could support a flat package layout. This way you can start coding a package in a file, and
split it in a directory <strong>only</strong> when it grows. Ie:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>org.example.pack1/ // Allow the use directories with dots instead nested ones
org.example.pack1.subpack/
org.example.pack2/
org.example.pack3.bali // Allow to use a file to hold all package classes
</code></pre>
</div>
<h2 id="more-than-one-public-class-per-file">More than one public class per file</h2>
<p>This point is related to the previous one. It will allow to start with a file and split it in
different files when needed (no more twenty line classes in their own file)… My editor is
gonna run out of tabs!</p>
<h2 id="getters-and-setters-as-fields">Getters and setters as fields</h2>
<p>Allow to define <code class="highlighter-rouge">getters</code> as <code class="highlighter-rouge">&lt;Type&gt; $name ()</code> and <code class="highlighter-rouge">setters</code> as <code class="highlighter-rouge">void $name (&lt;Type&gt; newVal)</code>
allowing methods with these patterns to be accessed as fields. This way you scale functionaly
not having to change client code (class users) if you change a field by a method or the
opposite. Ie: you can start with a final field and after that change that for a <code class="highlighter-rouge">getter/setter</code>
pair without changing all clients. For example:</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="c1">// This class...</span>
<span class="kd">class</span> <span class="nc">Person</span> <span class="o">{</span>
<span class="kd">public</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="c1">// Could evolve to this one...</span>
<span class="kd">class</span> <span class="nc">Person</span> <span class="o">{</span>
<span class="kd">private</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
<span class="kd">public</span> <span class="n">String</span> <span class="n">$name</span> <span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="n">$name</span> <span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c1">// Without needing to change the client</span>
<span class="kd">class</span> <span class="nc">Main</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span> <span class="o">(</span><span class="n">String</span> <span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span>
<span class="n">Person</span> <span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Person</span> <span class="o">();</span>
<span class="n">p</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="s">"Elmo"</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span></code></pre></figure>
<h2 id="multiline-strings">Multiline strings</h2>
<p>This feature would be very useful for writing JDBC queries or embedded XML. An example worths
one thousand words:</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="n">String</span> <span class="n">s</span> <span class="o">=</span> <span class="s">"""
select *
from persons
where age &gt; 18
"""</span><span class="o">;</span></code></pre></figure>
<h2 id="default-and-named-params">Default and named params</h2>
<p>Implementing this would save a lot of overloaded methods. It would also ease the creation of
inmutable objects. And lastly, it could improve DSLs creation.</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">class</span> <span class="nc">Car</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">brand</span><span class="o">,</span> <span class="n">model</span><span class="o">;</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">year</span><span class="o">;</span>
<span class="n">Car</span> <span class="o">(</span><span class="n">String</span> <span class="n">brand</span><span class="o">,</span> <span class="n">String</span> <span class="n">model</span><span class="o">,</span> <span class="kt">int</span> <span class="n">year</span> <span class="o">=</span> <span class="mi">2000</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">brand</span> <span class="o">=</span> <span class="n">brand</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">model</span> <span class="o">=</span> <span class="n">model</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">year</span> <span class="o">=</span> <span class="n">year</span><span class="o">;</span>
<span class="o">}</span>
<span class="kd">static</span> <span class="n">Car</span> <span class="nf">build</span> <span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">Car</span> <span class="o">(</span>
<span class="nl">brand:</span> <span class="s">"ford"</span><span class="o">,</span>
<span class="nl">model:</span> <span class="s">"focus"</span>
<span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span></code></pre></figure>
<h2 id="remove-semicolon-whenever-is-possible">Remove semicolon whenever is possible</h2>
<p>This one would improve readability and speed up editing. No need to say anymore :)</p>
<h2 id="last-lambda-outside-parenthesis">Last lambda outside parenthesis</h2>
<p>For me it seems ugly to finish a sentence with <code class="highlighter-rouge">});</code> if you could end it with just <code class="highlighter-rouge">}</code> it would
be clearer!</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="c1">// This call...</span>
<span class="n">build</span> <span class="o">(</span><span class="s">"Widget"</span><span class="o">,</span> <span class="n">evt</span> <span class="o">-&gt;</span> <span class="o">{</span>
<span class="n">evt</span><span class="o">.</span><span class="na">toString</span> <span class="o">();</span>
<span class="o">});</span>
<span class="c1">// Could be:</span>
<span class="n">build</span> <span class="o">(</span><span class="s">"Widget"</span><span class="o">)</span> <span class="o">(</span><span class="n">evt</span><span class="o">)</span> <span class="o">-&gt;</span> <span class="o">{</span>
<span class="n">evt</span><span class="o">.</span><span class="na">toString</span> <span class="o">();</span>
<span class="o">}</span></code></pre></figure>
<h2 id="add-identity-operator--and-use--as-equals">Add identity operator (<code class="highlighter-rouge">===</code>) and use <code class="highlighter-rouge">==</code> as equals</h2>
<p>Having to write <code class="highlighter-rouge">equals</code> always seemed too verbose for me. Creating another operator for
identity (<code class="highlighter-rouge">===</code>) and using <code class="highlighter-rouge">==</code> for equality would be more clear.</p>
<h2 id="null-safe-navigation-operator-">Null safe navigation operator (<code class="highlighter-rouge">?.</code>)</h2>
<p>Adopt the <a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator(?.)">null safe navigation operator</a> as it is used in <a href="http://groovy.codehaus.org">Groovy</a>. No more nested
<code class="highlighter-rouge">if (var != null)</code></p>
<h2 id="elvis--operator">Elvis <code class="highlighter-rouge">?:</code> operator</h2>
<p>The <a href="http://groovy.codehaus.org/Operators#Operators-ElvisOperator(?:)">Elvis operator</a> is also a nice addition to handle <code class="highlighter-rouge">null</code> references. Copying it
from <a href="http://groovy.codehaus.org">Groovy</a> would be a good choice!</p>
<h2 id="override-not-define-operators">Override (not define) operators</h2>
<p>Another good feature of <a href="http://groovy.codehaus.org">Groovy</a> is <a href="http://groovy.codehaus.org/Operator+Overloading">operator overloading</a>. this can enhance the
code readability. On the opposite, you have <a href="http://www.scala-lang.org/">Scala</a>’s <a href="http://docs.scala-lang.org/tutorials/tour/operators.html">operator definition</a> that can
lead to a mess if programmers are careless. Ie: you can define the <code class="highlighter-rouge">*/+-</code> operator if you want.</p>
<h2 id="markdown-in-javadoc">Markdown in Javadoc</h2>
<p>This way it would be easier to maintain the code documented ;)</p>
<hr />
<p>With these changes, the language would be compatible and would be an evolution,
not a revolution to Java. This language could be a proving ground to test new additions to
Java.</p>
<p>I was a one programming language man until now, I cheated Java with Scala and Groovy. Anyway
among all languages you have for the JVM, none of them are just a faster (to write programs)
Java.</p>
<p>And you, what improvements would you do to the Java language?</p>
The Making Of2014-06-19T00:00:00+02:00http://there4.co/projects/2014/06/19/the-making-of<h2 id="the-concept">The concept</h2>
<p>The idea of writing a blog came to my mind long time ago. I started two times, but finally the
third is the good one. First because I found a good platform to write posts and create my own
design and second because I already have a bunch of stories to write about.</p>
<p>This first post (the second really) is about the blog itself. Not only from the code point
of view, but also from the design and concept perspectives.</p>
<p>The name’s origin is pretty clear. It is <a href="http://en.wikipedia.org/wiki/Ren%C3%A9_Descartes">René Descartes</a> “<a href="http://en.wikipedia.org/wiki/Cogito_ergo_sum">Cogito</a>” with a geek twist ;)
The point is that you cannot code without thinking, but… do we always think as hard as we
should? For the favicon, I will let the reader find out what it is!</p>
<p>At the beggining I wanted to focus on the “thinking” part and <a href="http://en.wikipedia.org/wiki/Auguste_Rodin">Rodin</a>’s <a href="http://en.wikipedia.org/wiki/The_Thinker">Thinker</a> came to my
mind. Later I changed my mind to focus on the “programming side”, then I decided to use a
computer picture as the background. I considered “famous” computers as <a href="http://en.wikipedia.org/wiki/HAL_9000">HAL 9000</a> and <a href="http://en.wikipedia.org/wiki/ENIAC">Eniac</a>,
in the end I used the latter one, focusing in the old times of computing.</p>
<p>The looks are “old style” or “vintage” as modern people like to call it nowadays. I wanted to
reflect the origins of this craft and that is why the colors are dark and greenish (like my
first monitor ;)</p>
<h2 id="the-implementation">The implementation</h2>
<p>I saw some premade themes and sites done with <a href="http://jekyllrb.com">Jekyll</a>, but finally I started from scratch to
have the minimal code I needed for my blog and to customize it freely from the start.</p>
<p>In order to blog with <a href="http://jekyllrb.com">Jekyll</a>, you have to install the following software in your system:
Ruby, Gem , Jekyll (obvious), Python, Pygments (for syntax highlighting).</p>
<p>Then, to create the site structure, you have to execute the command
<code class="highlighter-rouge">jekyll new &lt;user&gt;.github.io</code>. This will generate the minimum files required by Jekyll to build
a site. The name doesn’t need to follow that naming pattern if you are going to host the site
outside <a href="http://github.com">Github</a>.</p>
<p>For the design I chose Twitter <a href="http://getbootstrap.com">Bootstrap</a>. Anyway I didn’t wanted my blog to look like the
hundreds of sites using <a href="http://getbootstrap.com">Bootstrap</a>, so I looked for a custom theme. I found very good
templates in <a href="http://startbootstrap.com">Start Bootstrap</a>. Like these two which I used for some parts of the design:</p>
<ul>
<li><a href="http://startbootstrap.com/modern-business">Modern Business</a></li>
<li><a href="http://startbootstrap.com/grayscale">Grayscale</a></li>
</ul>
<p>To generate the base (static) site I used html5 boilerplate (in a tool of my own called Webstrap).
The skeleton generated by this tool contains: <code class="highlighter-rouge">crossdomain.xml</code>, <code class="highlighter-rouge">humans.txt</code> &amp; <code class="highlighter-rouge">robots.txt</code> from
HTML5 Boilerplate.</p>
<p>The icons I use are taken from <a href="http://fontawesome.io">Font Awesome</a> however I created a custom font using <a href="http://icomoon.io">IcoMoon</a>
for the icons I could not find there.</p>
<p>To make the blog lighter and easier to update, I tried to use CDNs to avoid copying libraries
to my blog’s files. So most of the libraries (like Bootstrap, jQuery, Font Awesome and so on)
are taken from remote servers instead of being served directly from the blog.</p>
<p>After this, I had all the static structure of the blog: the styles, icons, and so on. But I
still had to code the templates to render content.</p>
<p>The most important templates are <code class="highlighter-rouge">_layouts/default.html</code>, <code class="highlighter-rouge">_layouts/post.html</code> and <code class="highlighter-rouge">posts.html</code>
to develop them I took static HTMLs from the themes I downloaded and inserted the dynamic parts
following the <a href="http://jekyllrb.com/docs/home">Jekyll reference</a> which is very useful and clear.</p>
<p>If you are deploying in Github and the pages are not updated, check the Github repository
settings (Github Pages section) to see if there is any error. Sometimes the blog builds locally
but fails to render in the server (checking this can save you a lot of time wondering what is
going wrong ;) trust me).</p>
<p>There are other templates that I picked from other Jekyll blogs, like these ones:</p>
<ul>
<li>
<p>The <code class="highlighter-rouge">atom.xml</code> and <code class="highlighter-rouge">_includes</code> files were taken from the <a href="http://github.com/caarlos0/up">UP</a> theme. Note that UP’s
includes were modified for the blog.</p>
</li>
<li>
<p><code class="highlighter-rouge">sitemap.txt</code> and <code class="highlighter-rouge">rss.xml</code> were copied from <a href="http://jekyllbootstrap.com">JekyllBootstrap</a>.</p>
</li>
</ul>
<p>To make syntax highlighting work, you need to install Pygments tool. It is very important that
you also generate the “syntax styles” for pygments. You can do this executing the following
command: <code class="highlighter-rouge">pygmentize -S monokai -f html &gt; css/syntax.css</code> After running the previous command,
do not forget to include <code class="highlighter-rouge">syntax.css</code> in the pages where you intend to use syntax highlighting!</p>
<h2 id="blog-usage">Blog usage</h2>
<p>To use the blog, I decided to use shell scripts instead a full blown build tool. In the end the
blog has to be maintained in Unix… so who cares about multiplatform.</p>
<p>The scripts are inside the <code class="highlighter-rouge">_bin</code> directory and they are used to generate the themes and the
icons.</p>
<p>To write posts and deploy them to the server, you will only need <a href="http://jekyllrb.com">Jekyll</a> and <a href="http://git-scm.com">Git</a>. These are
the most common actions:</p>
<ul>
<li>Launch blog locally: <code class="highlighter-rouge">jekyll serve --watch</code> after running that, you can see the blog in
<a href="http://localhost:4000">http://localhost:4000</a></li>
<li>Deploy changes: <code class="highlighter-rouge">git add . &amp;&amp; git commit &amp;&amp; git push</code> will upload your latest changes to the
server.</li>
</ul>
<h2 id="conclusion">Conclusion</h2>
<p>Starting a blog with <a href="http://jekyllrb.com">Jekyll</a> from scratch is way harder than using <a href="http://jekyllbootstrap.com">JekyllBootstrap</a> or other
blog engine. In exchange: you get flexibility, take advantage of your current knowledge (Git,
HTML…) and you don’t have to learn custom templates for closed products.</p>
<p>Also you will learn valuable things (about Web design and development) and have fun in the
process!</p>
<p>As a side effect, I realized that static site generation can be useful for other purposes (not
only for blogs). For example, it can be used to generate software project’s technical
documentation.</p>
<p>Regarding the last point, I found a <a href="http://jekyllrb.com">Jekyll</a> wannabe in Java called <a href="http://jbake.org">JBake</a> that looks very
promising.</p>
<h2 id="reusing-it">(Re)using it</h2>
<p>If you want to use the code for your own site, you can refer to the <a href="http://github.com/jaguililla/jaguililla.github.io/blob/master/readme.md">readme.md</a> file and check
how to change it to suit your own needs.</p>
Hello World!2014-06-19T00:00:00+02:00http://there4.co/projects/2014/06/19/hello-world<p>Everything begins with a… <em><a href="//en.wikipedia.org/wiki/Hello_world_program">Hello World!</a></em></p>
<p><img src="/assets/posts/hello-world.jpg" alt="Hello World!" /></p>