In Search of Concise Software

A journey to find those pieces of software or technology that facilitate productive and maintainable software development

Wednesday, May 4, 2011

Java to Scala in the pursuit of Intention

This is a response to Cedric Beust's From Scala back to Java

Cedric linked to a very interesting discussion of the migration challenge from Java to Scala and the hurdles that are holding people back or pushing them away. This is an essential discussion to be having as migration is the reality for most companies and developers considering Scala. Very few of us have the luxury of starting fresh.

"This situation is pretty shameful, to be honest. Scala is about seven years old and the absence of decent IDE support after such a period of time is absolutely unforgiveable, especially given the ambitions of the Scala team." -Cedric Beust From Scala back to Java

That statement concerns me deeply. It is contradicted by my experience with IntelliJ IDEA's Scala Plug-in. I use this plugin every day for my work and I find it covers the subset of Scala that supports direct class-based object-oriented (Java-style) programming nearly as well as IntelliJ does Java. The support goes deep as well as it supports most of the refactoring and static analysis work flows IntelliJ provides for Java. JetBrains' Scala plug-in also gets very close to fully supporting the very complex combinations of Scala features that give rise to internal DSLs.

"First, I’m not sure that the envelope needs to be pushed any further in Scala. A lot of potential users are routinely turned off by its excessive functional and academic aspects and its complex type system. The interaction between functional and object oriented features already feels pretty complex to handle, so I certainly don’t want the language to evolve any further. I hope that future efforts will be oriented more toward the libraries and the tools than the language" -Cedric Beust From Scala back to Java

I see this as another deeply troubling misconception about Scala and abstraction complexity in general. I am ashamed to admit that I shared this concern and even posted to that effect on this blog historically. Object-orientation was a huge mind-shift and jump in abstraction power over structured programming. Early criticisms labeled it as overly complex and unmanageable for teams. It is undeniable now that OOP has paid massive dividends to its adopters. The size of the OOP community is a testament to how accessible it has proven to be. I think the same is true of a fusion of OOP and FP as provided in Scala.

Scala's complexity is not complicated. It is a well into which you willingly dip as deeply or as shallowly as you like to be productive. This is another way of looking at Martin's Scala Levels.

What if different developers have different depths they dip to? How does this affect readability among developers? It could easily affect readability if developers go beyond their depth, but the same applies to inner classes and interfaces, runtime annotations, generics and reflection in Java. Chances are, if your team is uncomfortable reading code using these features, then they are equally unlikely to use them effectively in Java and will write obscure or incomprehensible code when they use them. However, effective use of these features yields shorter, more readable code that more clearly expresses it intent.

Abstractions give developers more tools to clearly express their intentions. Java's abstractions clearly help. When it appears that they don't it is simply a case of ineffective or novice application. The same is true of Scala, but its power in expressing intent is substantially magnified by a much richer set of abstractions. Java has a deep well of abstractions and gives a great deal of power to developer. Scala has a much deeper well of abstractions and gives an order of magnitude more power than Java for expressing intent directly.

Clear expression of intent is absolutely central to maintainable code. Scala is worth the work of learning and the cost of training to make your team more effective. It is worth it because it gives your team a considerable advantage over Java in expressing intent which will dramatically reduce maintenance cost over time.

I strongly suggest migrating from Java to Scala in the pursuit of intention.

Thursday, February 3, 2011

Integrating IntelliJ IDEA 10 into the Linux Mint Main Menu

Wouldn't it be nice if IntelliJ IDEA lived in the menus in Mint and was available from the search box?

The good news is that it can and the better news is that it is easy to achieve :)

  1. Download IntelliJ IDEA and extract it where you want it to live (ex: ~/Applications)
  2. From the desktop: Open Main Menu | Control Centre
  3. In the Control Centre window: Under Personal open Main Menu
  4. In the Main Menu window: Under Menus in the left sidebar select Programming
  5. In the Main Menu window: Click New Item button on right hand side of window
  6. In the Create Launcher dialog: Click the place-holder icon
  7. In the Choose an icon dialog: navigate to the IDEA bin folder and select idea128.png
  8. In the Create Launcher dialog: set Name to
    IntelliJ IDEA
  9. In the Create Launcher dialog: set Command to
    env IDEA_SDK="/usr/lib/jvm/java-6-sun" /path/to/idea/bin/idea.sh
  10. In the Create Launcher dialog: set Description to
    Java IDE from JetBrains

Now you can raise IntelliJ IDEA from the search on the Main Menu by typing IntelliJ, JetBrains or Java, etc. :)

Thursday, November 11, 2010

HOWTO: Install Erlang/OTP R14B with Homebrew on Snow Leopard with wxErlang Support

UPDATE: Hopefully this fix won't be necessary for long. I have submitted a Pull Request for the Homebrew team's consideration.

I have installed 32-bit Erlang/OTP R14B with wxErlang support successfully with modified Homebrew Formulae. It looks like it works perfectly fine so long as I don't close the Attach Process window when the debugger isn't ready for me to do that :)

I modified /usr/local/Library/Formula/wxmac.rb to enable opengl, unicode, gnomeprint and graphic_ctx and disable shared libs and install dev headers and libs resulting in:

require 'formula'

class Wxmac <Formula
  url 'http://downloads.sourceforge.net/project/wxwindows/2.8.11/wxMac-2.8.11.tar.bz2'
  homepage 'http://www.wxwidgets.org'
  md5 '8d84bfdc43838e2d2f75031f62d1864f'

  def caveats; <<-EOS.undent
    wxWidgets 2.8.x builds 32-bit only, so you probably won't be able to use it
    for other Homebrew-installed softare on Snow Leopard (like Erlang).
    EOS
  end

  def install
    # Force i386
    %w{ CFLAGS CXXFLAGS LDFLAGS OBJCFLAGS OBJCXXFLAGS }.each do |compiler_flag|
      ENV.remove compiler_flag, "-arch x86_64"
      ENV.append compiler_flag, "-arch i386"
    end

    system "./configure", "--prefix=#{prefix}", "--disable-debug",
                "--enable-unicode", "--disable-dependency-tracking",
                "--with-opengl", "--enable-unicode", "--enable-gnomeprint",
                "--enable-graphics_ctx", "--disable-shared"
    system "make && make install"
    system "cd contrib/src/stc/ && make && make install"
  end
end

I modified /usr/local/Library/Formula/erlang.rb to depend on wxmac, forced it to build in 32-bit and took out the wx skip file resulting in:

require 'formula'

class ErlangManuals <Formula
  url 'http://erlang.org/download/otp_doc_man_R14B.tar.gz'
  md5 '011530a24fbcc194be9bd01f779325a2'
end

class ErlangHeadManuals <Formula
  url 'http://erlang.org/download/otp_doc_man_R14B.tar.gz'
  md5 '011530a24fbcc194be9bd01f779325a2'
end

class Erlang <Formula
  # Download from GitHub. Much faster than official tarball.
  url "git://github.com/erlang/otp.git", :tag => "OTP_R14B"
  version 'R14B'
  homepage 'http://www.erlang.org'

  head "git://github.com/erlang/otp.git", :branch => "dev"

  depends_on 'wxmac'

  # We can't strip the beam executables or any plugins, there isn't really
  # anything else worth stripping and it takes a really, long time to run
  # `file` over everything in lib because there is almost 4000 files (and
  # really erlang guys! what's with that?! Most of them should be in share/erlang!)
  # may as well skip bin too, everything is just shell scripts
  skip_clean ['lib', 'bin']

  def options
    [
      ['--disable-hipe', "Disable building hipe; fails on various OS X systems."],
      ['--time', '"brew test --time" to include a time-consuming test.']
    ]
  end

  def install
    ENV.deparallelize
    fails_with_llvm "See http://github.com/mxcl/homebrew/issues/issue/120", :build => 2326

    # If building from GitHub, this step is required (but not for tarball downloads.)
    system "./otp_build autoconf" if File.exist? "otp_build"

    args = ["--disable-debug",
            "--prefix=#{prefix}",
            "--enable-kernel-poll",
            "--enable-threads",
            "--enable-dynamic-ssl-lib",
            "--enable-smp-support"]

    unless ARGV.include? '--disable-hipe'
      # HIPE doesn't strike me as that reliable on OS X
      # http://syntatic.wordpress.com/2008/06/12/macports-erlang-bus-error-due-to-mac-os-x-1053-update/
      # http://www.erlang.org/pipermail/erlang-patches/2008-September/000293.html
      args << '--enable-hipe'
    end

    #args << "--enable-darwin-64bit" if snow_leopard_64?

    # Force i386
    %w{ CFLAGS CXXFLAGS LDFLAGS OBJCFLAGS OBJCXXFLAGS }.each do |compiler_flag|
      ENV.remove compiler_flag, "-arch x86_64"
      ENV.append compiler_flag, "-arch i386"
    end

    system "./configure", *args
    #system "touch lib/wx/SKIP" if MACOS_VERSION >= 10.6
    system "make"
    system "make install"

    manuals = ARGV.build_head? ? ErlangHeadManuals : ErlangManuals
    manuals.new.brew { man.install Dir['man/*'] }
  end

  def test
    `erl -noshell -eval 'crypto:start().' -s init stop`

    # This test takes some time to run, but per bug #120 should finish in
    # "less than 20 minutes". It takes a few minutes on a Mac Pro (2009).
    if ARGV.include? "--time"
      `dialyzer --build_plt -r #{lib}/erlang/lib/kernel-2.14.1/ebin/`
    end
  end
end

Monday, October 11, 2010

Riak, now with Search

Riak is distributed key-value store which now has easy full text search.

Install Riak Search before continuing.

Put riaksearch/bin in your session PATH:

export PATH=/path/to/riaksearch/bin:$PATH

Enable indexing on the “companies” and “testimonials” buckets:

search-cmd install companies
search-cmd install testimonials

Create some convenience functions for easier KV ops:

# USAGE: riak_post "bucket" "value"
function riak_post { 
    curl -v -d "$2" -H "Content-type: text/plain" "http://127.0.0.1:8098/riak/$1"
}

# USAGE: riak_put "key" "value"
function riak_put { 
    curl -v -X PUT -d "$2" -H "Content-type: text/plain" "http://127.0.0.1:8098/riak/$1"
}

Add some facts about a couple of companies I really like:

riak_post companies "\
Verafin is one of North America's leading BSA/AML \
Compliance and Fraud Detection software providers."

riak_post companies "\
Verafin was founded in 2003 by a team of computer \
engineers with a background in artificial intelligence and \
pattern recognition. We have become recognized as a \
thought leader for delivering an innovative solution to the \
financial services industry by introducing unconventional and \
sophisticated artificial intelligence technologies that \
traditionally have only been used in the field of science."

riak_post companies "\
Basho Technologies, Inc., founded in January 2008 by a core group of \
Software Architects, Engineers and Executive Leadership from Akamai \
Technologies, Inc. (NASDAQ:AKAM) is headquartered in Cambridge, \
Massachusetts."

riak_post companies "\
Basho works with a wide array of companies from various industries, \
spanning FORTUNE 100 companies like Comcast to innovative startups \
like Mochi Media, Opscode, and SelfServeApps."

Add a couple of testimonials from happy customers of those same companies:

riak_post testimonials "\
\"Verafin staff have an understanding of the whole objective and end \
goal which leaves them open to recommendations for enhancements and \
accommodation in fulfilling requests. I think overall, with Verafin \
I know we have options versus just what the company is willing to \
provide. I totally enjoy working with Verafin.\" Phyllis B, IN"

riak_post testimonials "\
\"A big thank you to the guys at Basho for Riak, its seriously \
awesome.\" Jebu Ittiachen, Inagist.com"

What are the facts we know about Verafin?

search-cmd search companies Verafin

I got back (keys will ):

 :: Searching for 'Verafin' in companies...

------------------------------

index/id: companies/7008zOvhqaNLMpQ2ISSVCzsPYFP
p -> [0]
score -> 0.5

------------------------------

index/id: companies/XIEUYXungQb9DWMOAYyVvc9OlEb
p -> [0]
score -> 0.5

------------------------------

 :: Found 2 results.

What are people saying about Verafin?

search-cmd search testimonials Verafin

I got back:

 :: Searching for 'Verafin' in testimonials...

------------------------------

index/id: testimonials/R4oIibVNRzqr4Nean6D5jkn8nHO
p -> [0,20,34]
score -> 0.8660254037844386

------------------------------

 :: Found 1 results.

What are the facts we know about Basho?

search-cmd search companies Basho

I got back:

 :: Searching for 'Basho' in companies...

------------------------------

index/id: companies/JD1h3Erznyj47AKHKwPx0zyWddi
p -> [0]
score -> 0.5

------------------------------

index/id: companies/T8kqjUkWIOgvUDaIHExkSbiJCU8
p -> [0]
score -> 0.5

------------------------------

 :: Found 2 results.

What are people saying about Basho?

search-cmd search testimonials Basho

I got back:

 :: Searching for 'Basho' in testimonials...

------------------------------

index/id: testimonials/YqSiksF5WQmSGlKNmM1udPXm6vx
p -> [4]
score -> 0.5

------------------------------

 :: Found 1 results.

Why not get some really snazzy XML with actual content using the Solr interface?

curl "http://localhost:8098/solr/companies/select?start=0&rows=10000&q=Verafin"

curl "http://localhost:8098/solr/testimonials/select?start=0&rows=10000&q=Verafin"

curl "http://localhost:8098/solr/companies/select?start=0&rows=10000&q=Basho"

curl "http://localhost:8098/solr/testimonials/select?start=0&rows=10000&q=Basho"

Bear in mind that values in a bucket before search was enabled are not automatically indexed.

Enjoy your distributed masterless key-value store even more now that it has full text search. Yeah, this is pretty awesome. Thank you Basho for this great addition to Riak :)

Wednesday, April 7, 2010

Dusty Old Projects: Erlang/Dojo Settlers of Catan

A couple of years ago I got it in my head that I should write a Settlers of Catan clone with an Erlang server and a Dojo Toolkit client. I got fairly far with it, but the rubber never hit the road. Instead of letting the experience, the bruises and the documents generated from that go to waste I have made all available on Github at http://github.com/AlainODea/erlang_dojo_settlers.

I think this is a worthwhile project to look at to see the first intuitions of an experienced Java developer attempting to build a system in Erlang. Particularly the heavy use of processes as objects of a sort. It also makes some interesting use of JavaScript and The Dojo Toolkit as well.

Enjoy :)

Friday, March 26, 2010

Enabling SyntaxHighlighter in Blogger Step-by-Step

  1. Learn about SyntaxHighlighter
  2. Go to Layout from you Blogger Dashboard
  3. Select Edit HTML
  4. Immediately after <head>, add the following code:
    <script src='http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js' type='text/javascript'></script>
    <script src='http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushErlang.js' type='text/javascript'></script>
    <script src='http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js' type='text/javascript'></script>
    <link href='http://alexgorbatchev.com/pub/sh/2.1.364/styles/styles/shCore.css' rel='stylesheet' type='text/css' />
    <link href='http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css' rel='stylesheet' type='text/css' />
    
  5. Select Save Template
  6. Select Page Elements
  7. Select Add a Gadget
  8. Select HTML/JavaScript
  9. In the Title field, enter SyntaxHighlighter
  10. In the Content box enter the following code:
    <script class='javascript'>//<![CDATA[
    SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf';
    SyntaxHighlighter.all();
    //]]></script>
    
  11. Select Save
  12. Select Edit HTML
  13. Make note of the widget id of the b:widget whose title is SyntaxHighlighter (for me it was HTML1)
  14. Immediately before ]]></b:skin>, add the following code (with your widget id in place of HTML1):
    #HTML1 {
    display:none;
    }
    
  15. Select Save Template (this step hides the unnecessary visible gadget from your readers)
  16. Enjoy syntax highlighting :)

Thursday, March 25, 2010

Getting __git_ps1 in Homebrew

Homebrew's Git Formula does not appear to include __git_ps1. It is trivial to emulate with a shell alias though, so I did.

Add these lines to ~/.bashrc:

alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;\w \$(__git_ps1)\a\]\$> "
    ;;
*)
    ;;
esac

SyntaxHighlighter