Very cool Scala code snippet from GridGain…

I just came across this very cool Scala code snippet from GridGain’s Visor (part of the Enterprise Edition that allows for advanced scriptable monitoring of GridGain installations). Visor is entirely written Scala and use Scalar – our distributed programming DSL.

This particular code snipped (actual screenshot) deals with restarting the remote node. Take a look:

What it essentially does is to check if we are to restart the node (reference to which we obtained above), check if reference is null and then ensure that remote node indeed supports remote restarting… And that’s the kicker – take a look how this check is performed!

Basically, this expression node #< grid.isRestartEnabled executes closure grid.isRestartEnabled on the remote target node and returns boolean (on whether the restart is enabled on that node).

As with anything else in GridGain:

  • there’s nothing to compile, build or deploy,
  • nothing to manually marshall or demarshal,
  • no need to care about versioning,
  • or failover, or class loading,
  • or anything else for that matter.

You just use distributed closure execution right in the if statement as if it was a local operation (minus the exception handling).

Pretty cool!

12 responses

  1. What’s so cool about 1) Using a weird symbolic method name instead of a plain English one and 2) Having a hidden synchronous remote call?

    Probably a good example of what not to do, if you ask me.

  2. The symbolic alias is precisely the problem: nobody understands what #< means except whoever committed that code (and shame on the code reviewer for letting it through). He's probably a former Perl coder.

    And to repeat what I said: you should not 1) mask a remote call as a local one (a lesson we learned in 1994 from the paper "A Note on Distributed Computing". I strongly recommend you read it and 2) Put a synchronous call here.

    • Steve,
      I’ve read the paper (as everyone else) in the mid 90s when I was developing my 1st distributed middleware.

      I think you are confusing context of the call and semantics of the call (as most people who read this and countless following papers on this subject).

      Semantic is 100% clear: operator ‘#<' is used in Scalar DSL for remove closure execution. If you don't like operator notation you can use 'call' method name. Nothing is hidden and everything is clear.

      Context in which this operation is used looks very "localized" though. And this is on purpose. In fact – WE DO want to have our distributed operations be *clearly marked semantically* but be able to use them just as easily as local operations. Again – semantics vs. context…

      Hence my original post.

      Thanks for questions – le's move on.


      • If you think that “#<" is 100% clear, then you do indeed have bigger problems than hiding remote calls.

  3. This symbolism is one of the many reasons why Scala will always be a niche language. I checked out the new 2.9 beta eclipse IDE and was pleasantly surprised that the auto-complete worked but then quickly got turned off big time by all the strange symbols it suggested me on a simple Array.
    If that is what the world wanted, we all would be working with Haskell.

    • We’ll disagree on this. In fact, we have several people in GridGain that criticize me for overdoing this “symbolism”. I’m probably guilty of this somewhat.

      But for every symbolic alias we have normal method names – so you can use any approach you like.

      Btw, allowing operator characters in method names have absolutely nothing to do w/Haskel or Scala for that matter. it’s a small footprint feature of Scala…


  4. I’m not sure why some are getting upset about there being a remote call in the snippet. The snippet is Visor — the /grid/ management dsl. You know, grid being the distributed fabric thingy. So why should it be surprising that there are remote calls in the remote management dsl?

    • 1) It’s synchronous, it doesn’t seem the best choice in this case. Why block the thread if something happens? A pull model sounds better.

      2) It’s hidden. There is no RemoteException and no hint to a reviewer of the code that as opposed to the rest of this statement, this one will go over the network.

      3) It uses a method called #< which is completely meaningless and that you can't even pronounce to describe it.

      In short, it's everything that we get warned *not* to do at Google and I can guarantee you such a piece of code would never pass code review.

      • Steve,
        You got me cracking here… 🙂

        1. It must be synchronous in this case. We, obviously, support asynch version of the same call – but I need to wait for the result… This is either instantaneous or throws exception.

        2. It’s hidden only for you – ’cause you don’t want to see it. Do I need to point out to GridException in this example? 🙂

        Furthermore, I already pointed out that function ‘call’ (or its alias ‘#<') is provided by our DSL that is specifically for… "distributed programming".

        3. Nothing to discuss. Brainwashing 1-0-1… I'm sure you'd argue that '!' in Scala for actor sending is also a bad idea.

        Dude, you need to relax. We are not going to agree on everything. And as far as code reviews in Google – give me a laughing break! Make sure that LinkedIn doesn't fall into the same category…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: