<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <id>tag:blog.codegram.com,2005:/feed</id>
  <link rel="alternate" type="text/html" href="http://blog.codegram.com" />
  
  <title>Codegram Blog</title>
  <updated>2013-05-17T13:46:51Z</updated>
  <icon>http://codegram-web.s3.amazonaws.com/favicon.png</icon>
  <logo>http://codegram-web.s3.amazonaws.com/images/logo.png</logo>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/codegram" /><feedburner:info uri="codegram" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>tag:blog.codegram.com,2005:Post/35</id>
    <published>2013-05-17T13:46:51Z</published>
    <updated>2013-05-17T14:28:15Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codegram/~3/k4r8I9qQNE0/new-gem-released-futuroscope" />
    <title>New gem released: Futuroscope!</title>
    <summary>Future Ruby objects in your hands... Today!</summary>
    <content type="html">&lt;p&gt;At Codegram, we've been recently working on leveraging &lt;strong&gt;Service Oriented Architectures&lt;/strong&gt; to our products. This comes with real benefits like being able to work on different technologies, databases, teams and architectures in each piece of the product at hand. &lt;em&gt;The right toolset for the right service&lt;/em&gt; - so far it's worked great and now we have an ecosystem of &lt;strong&gt;smaller services that move faster&lt;/strong&gt; than a big'ol monolithic application.&lt;/p&gt;

&lt;p&gt;But it comes with a cost: Communication. Using HTTP for glueing services together is pretty extended and people use to spend a lot of time and resources trying to speed up HTTP responses using different caching strategies, multi-get request and so. But &lt;strong&gt;we tend to forget a really powerful tool: Parallelization&lt;/strong&gt;. But even if we don't, threads are hard, and nobody likes mangling with mutexes and thread-safety. It just feels outside of our domain for the most of the problems.&lt;/p&gt;

&lt;h3&gt;Futuroscope jumps on stage!&lt;/h3&gt;

&lt;p&gt;Futuroscope was created by the following premise: In most of the cases, we don't care about an actual variable's value &lt;strong&gt;right now&lt;/strong&gt;. What if we could run some processes &lt;strong&gt;on the background until we need their values?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's called the &lt;a href="http://en.wikipedia.org/wiki/Futures_and_promises"&gt;future pattern&lt;/a&gt; but we actually tried to give it an extra spin thanks to Ruby's &lt;em&gt;duck typing&lt;/em&gt; - we don't care wether the parallel object is a promise or not. It walks, swims and quacks like the object we're waiting for. So we don't have to change our API's. It just &lt;strong&gt;works right now, for free&lt;/strong&gt;, in your existing libraries.&lt;/p&gt;

&lt;h3&gt;Uhmm... Sure. Can we have an example?&lt;/h3&gt;

&lt;p&gt;Ok, so that's how could deal with an scenario where you need to make 3 searches to Twitter and sum all the result counts:&lt;/p&gt;

&lt;script src="https://gist.github.com/josepjaume/5599354.js?file=without-futuroscope.rb"&gt;&lt;/script&gt;


&lt;p&gt;In my computer, that takes &lt;code&gt;3.059169&lt;/code&gt; seconds. Here's how you could do it with futuroscope:&lt;/p&gt;

&lt;script src="https://gist.github.com/josepjaume/5599354.js?file=with-futuroscope.rb"&gt;&lt;/script&gt;


&lt;p&gt;This takes &lt;code&gt;1.105958&lt;/code&gt; seconds on the same setup.&lt;/p&gt;

&lt;p&gt;We could reimplement this in a more convenient way using futuroscope's map syntax:&lt;/p&gt;

&lt;script src="https://gist.github.com/josepjaume/5599354.js?file=with-futuroscope-map.rb"&gt;&lt;/script&gt;


&lt;h3&gt;Is that black magic?&lt;/h3&gt;

&lt;p&gt;This is actually what's happening behind the scenes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you warm up your Ruby script and load futuroscope, it's &lt;strong&gt;automatically creating a pool of threads&lt;/strong&gt; eager to process stuff.&lt;/li&gt;
&lt;li&gt;When you create a future, will &lt;strong&gt;send that block to be processed by the thread pool&lt;/strong&gt; and will immediately return a proxy object that delegates &lt;em&gt;everything&lt;/em&gt; to that block's return value, &lt;strong&gt;without blocking the main thread&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;When you try to &lt;strong&gt;call any method on that proxy&lt;/strong&gt;, it will &lt;strong&gt;either wait&lt;/strong&gt; for the results to complete &lt;strong&gt;or return them immediately&lt;/strong&gt; if already finished processing them.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;You can check out &lt;a href="http://github.com/codegram/futuroscope"&gt;futuroscope on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Notes&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Futuroscope creates a &lt;strong&gt;thread pool of 8 workers by default&lt;/strong&gt;, which will auto-scale up to 16 when it's given a lot of work. That's configurable. That's meant to help memory management and for performance.&lt;/li&gt;
&lt;li&gt;You &lt;strong&gt;could reach dead locks&lt;/strong&gt; when you're &lt;strong&gt;calling futures inside of futures&lt;/strong&gt; (because of the thread pool). You shouldn't be doing that.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.futuroscope.com/"&gt;Futuroscope&lt;/a&gt; takes its name from an awesome amusement park located near Poitiers, France, and which I believe heavily shaped my childhood - not implying for good. You should check it out.&lt;/li&gt;
&lt;li&gt;Futuroscope will &lt;strong&gt; works great on MRI, Rubinius and JRuby&lt;/strong&gt; in 1.9 or 2.0 syntax.&lt;/li&gt;
&lt;li&gt;On MRI, you'll only notice performance improvements if you're doing IO in between, because is not able to run ruby code in parallel (blame the Global Interpreter Lock).&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Thoughts? Feedback?&lt;/h3&gt;

&lt;p&gt;We're eager of getting feedback from you. Please check out &lt;a href="http://github.com/codegram/futuroscope"&gt;futuroscope on GitHub&lt;/a&gt; and let us now if you find any issues or can think of ways to improve it!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/codegram/~4/k4r8I9qQNE0" height="1" width="1"/&gt;</content>
    <author>
      <name>Josep Jaume Rey</name>
    </author>
  <feedburner:origLink>http://blog.codegram.com/2013/5/new-gem-released-futuroscope</feedburner:origLink></entry>
  <entry>
    <id>tag:blog.codegram.com,2005:Post/33</id>
    <published>2013-03-22T10:53:56Z</published>
    <updated>2013-03-22T11:05:41Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codegram/~3/sjhBydITOPM/elasticsearch-with-ruby" />
    <title>ElasticSearch with Ruby</title>
    <summary>The slides from my talk at Barcelona on Rails user group</summary>
    <content type="html">&lt;p&gt;Hi everyone!&lt;/p&gt;

&lt;p&gt;We have recently been using &lt;a href="http://www.elasticsearch.org"&gt;ElasticSearch&lt;/a&gt; in different projects and we're really happy with the results. I prepared a short talk for the &lt;a href="https://groups.google.com/forum/?fromgroups#!forum/barcelonaonrails"&gt;Barcelona on Rails&lt;/a&gt; user group to let people now how our experience was with using ElasticSearch with Ruby and Rails.&lt;/p&gt;

&lt;script async class="speakerdeck-embed" data-id="a27f34b0750a0130f8e012313b1027d2" data-ratio="1.33333333333333" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;


&lt;p&gt;Also, check out the &lt;a href="https://gist.github.com/oriolgual/5220494"&gt;companion gist&lt;/a&gt; with some code examples.&lt;/p&gt;

&lt;p&gt;BTW, the awesome design wasn't (obviously) my work, kudos to &lt;a href="http://dribbble.com/ruxii"&gt;Roger&lt;/a&gt; for the work!&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/codegram/~4/sjhBydITOPM" height="1" width="1"/&gt;</content>
    <author>
      <name>Oriol Gual</name>
    </author>
  <feedburner:origLink>http://blog.codegram.com/2013/3/elasticsearch-with-ruby</feedburner:origLink></entry>
  <entry>
    <id>tag:blog.codegram.com,2005:Post/32</id>
    <published>2012-03-12T10:43:34Z</published>
    <updated>2012-03-12T10:44:05Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codegram/~3/bd45_U_-aC0/this-weeks-talks-bdd-best-practices-and-antipatterns-and-brew-your-own-coffeescript" />
    <title>This week's talks: "BDD best practices and antipatterns" and "Brew your own coffee...script"</title>
    <summary>This week's talks have been hosted by Oriol Gual(@oriolgual) and Txus (@txustice)</summary>
    <content type="html">&lt;p&gt;Check out this week's internal talk slides at Codegram:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://talks.codegram.com/bdd-best-practices-and-antipatterns"&gt;BDD best practices and antipatterns&lt;/a&gt;: &lt;a href="http://twitter.com/oriolgual"&gt;Oriol Gual&lt;/a&gt; goes through some best practices that every BDD adopter should consider, and what anti-patterns should be avoided.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://talks.codegram.com/brew-your-own-coffeescript"&gt;Brew your own coffee...script&lt;/a&gt;: &lt;a href="http://twitter.com/txustice"&gt;Txus&lt;/a&gt; shows us how to build a simple transcompiler (like CoffeeScript) in Ruby.&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://feeds.feedburner.com/~r/codegram/~4/bd45_U_-aC0" height="1" width="1"/&gt;</content>
    <author>
      <name>Josep M. Bach</name>
    </author>
  <feedburner:origLink>http://blog.codegram.com/2012/3/this-weeks-talks-bdd-best-practices-and-antipatterns-and-brew-your-own-coffeescript</feedburner:origLink></entry>
  <entry>
    <id>tag:blog.codegram.com,2005:Post/31</id>
    <published>2012-02-27T10:57:55Z</published>
    <updated>2012-02-27T13:29:43Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codegram/~3/uS4RhxVU8xI/this-weeks-talks-encoding-messages-in-a-noiseless-channel-and-http-authentication-methods" />
    <title>This week's talks: "Encoding messages in a noiseless channel" and "HTTP authentication methods"</title>
    <summary>This week's talks have been hosted by Marc Riera (@mrcasals) and Josep Jaume Rey (@josepjaume)</summary>
    <content type="html">&lt;p&gt;Check out this week's internal talk slides at Codegram:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://talks.codegram.com/encoding-for-noiseless-channels"&gt;Encoding messages in a noiseless channel&lt;/a&gt;: &lt;a href="http://twitter.com/mrcasals"&gt;Marc Riera&lt;/a&gt; explained to us how to construct an optimal, unique message encoding using the Huffman algorithm.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://talks.codegram.com/http-authentication-methods"&gt;HTTP authentication methods&lt;/a&gt;: &lt;a href="http://twitter.com/josepjaume"&gt;Josep Jaume&lt;/a&gt; walked us among several http authentication methods, explaining some of their vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://feeds.feedburner.com/~r/codegram/~4/uS4RhxVU8xI" height="1" width="1"/&gt;</content>
    <author>
      <name>Josep Jaume Rey</name>
    </author>
  <feedburner:origLink>http://blog.codegram.com/2012/2/this-weeks-talks-encoding-messages-in-a-noiseless-channel-and-http-authentication-methods</feedburner:origLink></entry>
  <entry>
    <id>tag:blog.codegram.com,2005:Post/30</id>
    <published>2012-02-14T16:12:55Z</published>
    <updated>2012-02-14T16:13:18Z</updated>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codegram/~3/K9kaHB37qcc/linting-the-hell-out-of-your-ruby-classes-with-pelusa" />
    <title>Linting the hell out of your Ruby classes with Pelusa</title>
    <summary>Gain new insights about your code thanks to static analysis</summary>
    <content type="html">&lt;p&gt;As you might know, yesterday morning we had Monday talks at the office! Oriol talked about &lt;a href="http://talks.codegram.com/object-oriented-nirvana"&gt;Object Oriented Nirvana&lt;/a&gt;, inspired by an &lt;a href="http://binstock.blogspot.com/2008/04/perfecting-oos-small-classes-and-short.html"&gt;old post&lt;/a&gt; about how to improve Object Oriented skills by using certain constraints while you're coding.&lt;/p&gt;

&lt;p&gt;Then I got immediately interested on how to automate this, and knowing how easy is dealing with the Rubinius' Abstract Syntax Tree, I decided to give it a try and develop a tool that statically analyzes Ruby code to gain insights from it.&lt;/p&gt;

&lt;p&gt;But what does it mean "statical analysis"? It means that this tool won't run any of your code at all, it just inspects it like you would as a developer, by looking at it. Since code is nothing more than nodes inside nodes, you can easily identify certain patterns that you consider wrong or desirable (for example, having &lt;em&gt;else&lt;/em&gt; clauses in &lt;em&gt;ifs&lt;/em&gt;, nesting blocks, or just using the word "foo" in actual programs). By traversing the AST, you can analyze parts of the code that don't fit your particular style or code quality requirements (actually with a little more work you could programmatically change those parts, i.e. automatic refactoring). I find this really cool!&lt;/p&gt;

&lt;p&gt;The tool I've been working for the last couple of days is something along these lines (excluding, for now, the automatic refactoring part).&lt;/p&gt;

&lt;h3&gt;Introducing Pelusa - a Ruby Lint to improve your OO skills&lt;/h3&gt;

&lt;p&gt;Pelusa (which is Spanish for the word &lt;em&gt;lint&lt;/em&gt;) is a static analysis tool and framework to inspect your code style and notify you about possible red flags or missing best practices. Above all pelusa doesn't run your code -- it just analyzes it syntactically to gain superficial insights about it, and raise red flags when needed.&lt;/p&gt;

&lt;p&gt;Although Pelusa needs Rubinius to run, due to how easy it is to work with a Ruby AST with it, it doesn't mean that you have to run your application or Ruby code on Rubinius. Since it's a static analysis tool, pelusa doesn't care what your code runs on, it just looks at it and tells you stuff.&lt;/p&gt;

&lt;p&gt;If you're curious, it looks like this (running on it's own code base, oh inception):&lt;/p&gt;

&lt;p&gt;&lt;img src="http://f.cl.ly/items/3Z341M0q2u1K242m0144/%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202012-02-14%20%D0%B2%203.29.38%20PM.png" alt="" /&gt;&lt;/p&gt;

&lt;h3&gt;Find the default lint checks too Taliban for your tastes?&lt;/h3&gt;

&lt;p&gt;These are just guides, so you're free to fork the project and add/remove lints as you like.
The fact that I've started with those &lt;em&gt;doesn't mean&lt;/em&gt; that any of us thinks these are the true and only practices of Object Orientation, it's just a set of constraints that are fun to follow to achieve a mindset shift in the long run, or just to explore new styles.&lt;/p&gt;

&lt;p&gt;One of the next features will be easy composability of lints, so you can remove those you don't like and add custom ones that fit your team's style or quality standards :)&lt;/p&gt;

&lt;h3&gt;Pelusa as a static analysis framework&lt;/h3&gt;

&lt;p&gt;With Pelusa, writing your own lints becomes very easy. Check out some of the
default lints under the &lt;code&gt;lib/pelusa/lint/&lt;/code&gt; directory in the &lt;a href="http://github.com/codegram/pelusa"&gt;Github repo&lt;/a&gt;. Rolling your own style has never been easier!&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;My point by doing this was mainly exploring static analysis with Ruby, since I've never done it before, but also proving a point: good development tools are not only for statically typed languages! With a little imagination we can leverage our skills to make life better, or at least more interesting, for Ruby developers as well.&lt;/p&gt;

&lt;p&gt;What do &lt;em&gt;you&lt;/em&gt; think? Would you use this kind of tooling in your everyday job?&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/codegram/~4/K9kaHB37qcc" height="1" width="1"/&gt;</content>
    <author>
      <name>Josep M. Bach</name>
    </author>
  <feedburner:origLink>http://blog.codegram.com/2012/2/linting-the-hell-out-of-your-ruby-classes-with-pelusa</feedburner:origLink></entry>
</feed>
