<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>The adventures of a polyglot programmer as he explores emerging technologies and languages.</description><title>Arbia - Cogitations</title><generator>Tumblr (3.0; @arbia)</generator><link>http://cogitations.arbia.co.uk/</link><item><title>Breaking the Rules - Making Java Fun with Mirah</title><description>&lt;p&gt;&lt;img height="312" width="297" alt="Nobody Likes A Java Programmer! ;)" src="http://img507.imageshack.us/img507/1831/programadorjava.jpg" align="right"/&gt;&lt;/p&gt;
&lt;p&gt;With any luck this should become a series of postings on new and emerging languages and I am going to begin on familiar territory with, somewhat counter intuitively, one of the most widely adopted languages of them all; Java. Java has gained a bad reputation within the communities of the up and coming dynamic languages; Python, Ruby and their peers, for its perceived bloat, boilerplate and seemingly endless determination to over-engineer. Goslings decision to recycle much of the C++ syntax for his new language was a pragmatic one at the time, aiming to ensure the language the best possible chance of survival and adoption in a world heavy on C family programmers. It worked, oh did it work. Unfortunately for Java though a largely unforeseen movement was taking place within the backstreets of programmer land where language terseness, readability and programmer enjoyment were being prioritised over a programs computational efficiency.&lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;&amp;#8220;Java is C++ without the guns, knives, and clubs&amp;#8221; - James Gosling, Co-Inventor Of Java&lt;/strong&gt;&lt;/blockquote&gt;
&lt;!-- more --&gt;
&lt;p&gt;This prioritisation lead to the emergence of languages which have become, for many, the ‘programmers choice.’ There are doubtless wars of words between them, which is the true path to divine happiness?, but what they all do is; make programming fun, intuitive and, above all, extremely productive. You only have to look to the existence of &lt;a title="Hackety Hack" target="_blank" href="http://en.wikipedia.org/wiki/Hackety_Hack"&gt;_why&amp;#8217;s Hackety Hack&lt;/a&gt; project to see the compelling simplicity advantage. Would you want to try and teach programming to a child with java? The ability to prototype programs in minutes instead of hours, expressing control-flow in linguistic order and the incorporation of functional paradigms, in a pragmatic salute to simplicity and expressivity, has made returning to Java for the day job a chore for many and an impossibility for some. That is until &lt;a title="Charles' Blog" href="http://blog.headius.com/" target="_blank"&gt;Charles Nutter&lt;/a&gt; (founder of the JRuby project) and Ryan Brown found themselves in the same situation while writing JRuby and working at Google respectively.&lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;&amp;#8220;It is better to create a language than curse the Java&amp;#8221; - Charlese Proverb&lt;/strong&gt;&lt;/blockquote&gt;
&lt;p&gt;It was Charles who sparked the movement by asking the question; Does it have to be the case that Java with all its performance, libraries, functionality, portability and tooling is destined to be hated for its syntax? Well the simple answer is categorically no.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a title="Mirah" target="_blank" href="http://www.mirah.org/"&gt;Mirah&lt;/a&gt; was born.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img height="150" width="281" alt="The Ruby Influence" src="http://img826.imageshack.us/img826/5719/rubyinfluence.jpg" align="left"/&gt;The beautiful lovechild of Ruby and Java; &lt;a title="Mirach Homepage" target="_blank" href="http://www.mirah.org/"&gt;Mirah&lt;/a&gt;, which was for a small time known by the awful name of Duby, offers a fabulous combination of its mothers looks and its fathers brains resultant, in a truly cogent alternative to tiresome development. By inheriting, to a large extent, the Ruby syntax and coding style and incorporating many of its most compelling features, from numeric ranges through closures and on to hash parameters, the language has much the feel and appearance of developing in a modern dynamic language. Acceding Java’s most compelling technologies also brings the aforementioned features, performance, libraries etc. and better yet, being both byte code and language compatible means that no matter what it can take the place of Java. Let&amp;#8217;s jump in:&lt;/p&gt;
&lt;script src="http://gist.github.com/492598.js?file=hello_world.mirah"&gt;&lt;/script&gt;&lt;p&gt;Sorry I couldn&amp;#8217;t help myself. Though it does identify a feature; the main method is implicit. Anyway:&lt;/p&gt;
&lt;script src="http://gist.github.com/492619.js?file=bigger_hello.mirah"&gt;&lt;/script&gt;&lt;p&gt;Looks good no? Simple, concise, expressive. Well so it should, in fact I can’t for the life of me work out why general programming languages have ever been charged with a task other than making the coders life happier, anyway, I digress. So what does the language bring to the table?&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Pluggable type inference, compilation and checking.&lt;/li&gt;
&lt;li&gt;No additional runtime library. Maps straight to the JVM runtime.&lt;/li&gt;
&lt;li&gt;Extensible backend allowing for new output targets; CLR, C, Fortran, COBOL lol&amp;#8230;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;What does all that mean? Well, it means it&amp;#8217;s modifiable, customisable and ripe for some brains to get in there and help with its direction. It also means that creating your own additions to the language is hugely simple too. Anyway, imagine if writing dynamic/duck typed Java could be as easily as this:&lt;/p&gt;
&lt;script src="http://gist.github.com/878458.js?file=dynamic_type.mirah"&gt;&lt;/script&gt;&lt;p&gt;Happily, it is (you will need to use the JVM 7 beta though.) Dynamic types are already a working feature of the language mopping up those occasions where type safety is too restrictive. Pragmatism through and through. All Java libraries are exposed as, well&amp;#8230; It is just Java we are writing. It just happens to be Java using a slightly different syntax. Many say that syntax shouldn&amp;#8217;t be a persuasive argument for or against the use of a language, and obviously in most cases it isn&amp;#8217;t, however, it is equally true that syntax can effect the simplicity its users have in developing and maintaining within that language. Let&amp;#8217;s look at these two snippets of code:&lt;/p&gt;
&lt;script src="http://gist.github.com/492827.js?file=sort.java"&gt;&lt;/script&gt;&lt;script src="http://gist.github.com/492732.js?file=sort.mirah"&gt;&lt;/script&gt;&lt;p&gt;The use case is the same but the second provides the functionality with so much more elegance (in my opinion of course.) Its intentions are somehow more obvious and this is merely a trivial snippet of code. Daydream and think of how your complex threaded java app could be instantly simplified&amp;#8230; Pass a block here a simplified loop there and suddenly the difficulty inherent in the syntax is reduced. Even writing graphical applications with cross-platform compatibility features becomes trivial:&lt;/p&gt;
&lt;script src="http://gist.github.com/878451.js?file=graphical.mirah"&gt;&lt;/script&gt;&lt;p&gt;&lt;strong&gt;Status?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Mirah is currently demonstrably under heavy development as can be seen at &lt;a title="Mirah Repository" target="_blank" href="https://github.com/mirah/mirah"&gt;its Github repository&lt;/a&gt; and there are a few &lt;a title="Current Issues" href="https://github.com/mirah/mirah/issues" target="_blank"&gt;issues&lt;/a&gt; which are currently awaiting resolution, however, it is usable right now and there are some seriously awesome features in the pipeline too. So if you&amp;#8217;re finding that you are losing your marbles with the &lt;a title="Slow slow slow!" target="_blank" href="http://en.wikipedia.org/wiki/Geologic_time_scale"&gt;geological&lt;/a&gt; pace of Java production I implore you to give it a go. Read the code, check out &lt;a title="Mirah examples." target="_blank" href="https://github.com/mirah/mirah/tree/master/examples/"&gt;the examples&lt;/a&gt; and get involved in &lt;a title="Mirah mailing lists" target="_blank" href="http://groups.google.com/group/mirah/"&gt;the community&lt;/a&gt;. If nothing else it may supercharge your &lt;a title="Dubious - Mirah apps for app engine" href="https://github.com/mirah/dubious" target="_blank"&gt;web app development&lt;/a&gt; but more likely; it may well be the best thing to happen to Java since, umm, Java.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Video&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For those hungry for more &lt;a title="Mirah Video" href="http://confreaks.net/videos/196-rubyconf2009-ruby-mutants" target="_blank"&gt;here is a video&lt;/a&gt; of Charles (Mirah King) at presenting the then &amp;#8220;Duby&amp;#8221; and &amp;#8220;Surinx&amp;#8221;, both of which have become subsumed by Mirah at confreaks a few years ago.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The comic found at the top of the article is from the fantastic &lt;a title="Geek And Poke" target="_blank" href="http://geekandpoke.typepad.com/"&gt;Geek And Poke&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description><link>http://cogitations.arbia.co.uk/post/3984477935</link><guid>http://cogitations.arbia.co.uk/post/3984477935</guid><pubDate>Sun, 20 Mar 2011 17:22:00 +0000</pubDate><category>duby</category><category>java</category><category>jruby</category><category>jvm</category><category>language</category><category>mirah</category><category>programming</category><category>ruby</category><category>syntax</category></item><item><title>Distributed Ruby - Exploiting 'Enterprise' Software</title><description>&lt;p&gt;&lt;strong&gt;Enterprise.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img443.imageshack.us/img443/6017/74149stripprint.gif" align="right" alt="The Enterprise Can Be Unproductive."/&gt;Even saying the word can send shivers down the spine of the &amp;#8216;enlightened&amp;#8217; developer. It can conjure up thoughts of gargantuan XML configuration files tied down with lashings of buzz, pomp and sales patter. Of documentation and usage so verbose that the eyestrain is almost palpable from the mear tonguing of the term. However, sometimes, on rare occasion, our gut is wrong and our reaction foolish because out there in &amp;#8216;enterprise&amp;#8217; land are some truly fabulous nuggets of software. In this posting I will be looking at one such &amp;#8216;diamond in the rough&amp;#8217; and seeing how we can exploit it in rubyland.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Distribution.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the sense of networks within software systems, distribution has near boundless uses; session sharing, shared processing, file access, logistics, analytics, etc., however its implementation is non-trivial. It is, in fact, a bloody hard problem to solve requiring schemes for; networking, fail-over, discovery, clustering, events, backups, locking and more besides.&lt;!-- more --&gt; Its therefore not surprising that few technologies exist in the ruby community to allow for truly distributed sharing of data, clustering if you will. Nor is it particularly surprising that there isn&amp;#8217;t really a potent technology for realtime event broadcast and node synchronisation or for distributed locking. All of these problems can of course be solved through the use of transactional databases, transactions and a strong dose of hack but it simply doesn&amp;#8217;t have to be this way. This difficult!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Money, Money, Money.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Within the world of the enterprise, distribution is big business (puntastic.) It is required for a plethora of business problems from ensuring your bank balance is consistent through to updating the stock in your local supermarket. You see enterprise is massive, there systems scale is truly vast, often intercontinental, and so it is paramount that systems can communicate efficiently, easily and reliably. The fiscal leverage of such organisations has provided an ideal excuse for some seriously sharp minds to pit there wits agains the problem and luckily for the rest of us, the results are ripe for the picking.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Exploit.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a title="Hazelcast" target="_blank" href="http://www.hazelcast.com/"&gt;Hazelcast&lt;/a&gt; is one such solution. An open source clustering and highly scalable data distribution platform which is:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Lightning-fast; thousands of operations/sec&lt;/li&gt;
&lt;li&gt;Fail-safe; no losing data after crashes.&lt;/li&gt;
&lt;li&gt;Dynamically scales as new servers added.&lt;/li&gt;
&lt;li&gt;Super-easy to use; include a single jar.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Waaaait a second! &amp;#8216;include a single jar&amp;#8217; Surely these be the words of the mad?!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img810.imageshack.us/img810/2753/jruby.png" align="left" alt="Duke Holding A Ruby!"/&gt;Ah yes, Java, the undisputed king of the enterprise world. The conservatives choice. Verbosity to ruby&amp;#8217;s terseness, static to it&amp;#8217;s dynamic, rain to it&amp;#8217;s DRY. However again we sometimes forget that in spite of it&amp;#8217;s failings within the eyes of the rubiest it holds advantage for many application. It&amp;#8217;s hugely fast, portable and, in this case probably most importantly, the enterprises love it. Furthermore, for us it&amp;#8217;s hereditary Java genes are too our advantage.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;On walks &lt;a title="JRuby" target="_blank" href="http://jruby.org/"&gt;JRuby&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Due to the nigh insurmountable work of Charles Nutter, Thomas Enebo, Ola Bini and Nick Sieger along with there team we have direct access to Java libraries and thus to a plethora of usefulness. Sometimes I think we forget how lucky we are, the ruby community, to have such awesome people simplifying our lives, anyway, thats quite enough arse kissing. So, on with the show:&lt;/p&gt;
&lt;script src="http://gist.github.com/491427.js?file=hazlecast_map.rb"&gt;&lt;/script&gt;&lt;p&gt;What you see above is a fully distributed hash. It has redundancy, consistency and a smorgasbord of other features all built in and with about 6 lines of ruby we can use it. Download it, run it a couple of times from different terminals and you will see that for each new terminal the system finds and connects with the others and appends it&amp;#8217;s own hello message to the hash (you will see the hash growing.) Close an instance and then open another, the hash will remain along with the destroyed nodes entry. Tell me that isn&amp;#8217;t cool!&lt;/p&gt;
&lt;script src="http://gist.github.com/491483.js?file=hazlecast_queue.rb"&gt;&lt;/script&gt;&lt;p&gt;How about a fully distributed process queue? Sure the example is stupid and there is a million better ways of passing through a function than with a string and eval but for a second ignore the stupidity and look at the potential. A full distributed, falt tolerant job queue in 12 overly verbose and crappy lines of ruby!&lt;/p&gt;
&lt;script src="http://gist.github.com/491502.js?file=hazlecast_chat.rb"&gt;&lt;/script&gt;&lt;p&gt;Potentially the worlds worst chat program but again, distributed, tolerant and broadcast/event enabled. In this example, as the rest, I have provided nothing more than a naive example using strings to broadcast messages however there is no reason that the strings are no objects of more value. We could be passing currency objects or error messages, instances of Person (everyones favorite model) or even binary data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Lowdown.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You are tasked with the job of creating a POS system for a local shop. Nothing fancy is needed, you construct a little interface in HTML, hook it up to a sinatra app running in&lt;img src="http://img696.imageshack.us/img696/1289/enterprise20software20a.jpg" align="right" alt="Interesting Representation Of A Mesh..."/&gt; the back office which records purchases to a database and interacts with some given merchant account and all is well. The shop takes off, expands to 3 stores and suddenly needs a distributed solution. This is still possible with what we have however assuming we now have some stock of goods in a warehouse which is shared amongst the stores it may become cumbersome having stocks updated only when an action is taken on the POS. Imagine how nice it would be to have the stock updated on screen as alterations occur? Ajax/Web-socket + broadcast and your done. You still have your simple system but now it has a new feature and it&amp;#8217;s cost practically nothing and is utterly, enterprise, resilient. This is your traditional enterprise problem domain but with a coat of Ruby simplicity painted on top.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Or.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Want to round-robin load distribute your server hits but need your sessions to be sticky to the user? Database? Or&amp;#8230; simply place the session data onto the distributed hash and you suddenly have no single point of failure! Server dies, all your sessions remain. How about sending emails? Queue them up and have multiple systems take care of delivery without so much as a smidgin of work for you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Basically.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are a million more features to hazlecast which I haven&amp;#8217;t mentioned and doubtless the whole experience could be made yet more loverly with a little gem which wrapped up the little ugliness left over (and in fact &lt;a target="_blank" href="http://github.com/aemadrid/rubyhaze"&gt;it has&lt;/a&gt; by some inspired by this little scribling) but the point is this: Go check out the Java landscape, see what you can find and get it out there. Don&amp;#8217;t be afraid of the BIG Java Enterprise with all it&amp;#8217;s buzz because although there is bloat out there, there is stuff which can blow you away.&lt;/p&gt;</description><link>http://cogitations.arbia.co.uk/post/863857348</link><guid>http://cogitations.arbia.co.uk/post/863857348</guid><pubDate>Tue, 27 Jul 2010 02:54:00 +0100</pubDate><category>chat</category><category>broadcast</category><category>distributed</category><category>enterprise</category><category>hash</category><category>hazlecast</category><category>jruby</category><category>java</category><category>programming</category><category>queue</category><category>ruby</category><category>software</category></item></channel></rss>

