Home > scala > Scala is easier than PHP

Scala is easier than PHP

November 17th, 2010

OK, that was a bit of link bating. However for the types of problems that I am currently working on it really is!  I have been asked a couple hundred times in the last 8 months why I tweet about Scala and Hbase all the time. The larger post is coming but I figured I could answer the technical scala question first. In order to stop the comment flames let’s start by saying that I know PHP better than most human beings. It is something that I have been coding in since PHP 3 and have really enjoyed the language the entire time. I still believe that PHP is the best language for the web for the majority of programmers; it quite possibly has the best documentation and examples of any language like a DSL for the web! I am still slinging PHP and so is my company. I have been a speaker at lots of php conferences, aided in php’s documentation, enjoyed the community, and for the past three years have been Zend Framework committer. That’s all to say that there are lots of other PHP developers that are smarter than me; but I probably have met them.

So why is Scala easier? First it’s easier when you have more requests than you know what to do with. Fundamentally it’s easier because it does so much under the hood for solving concurrency issues in a syntactically concise manor. I have found that as I have moved from writing code that is designed to persist data to a system of service that consist of multiple UI and data service inputs and outputs with different hotspots and unique data mutations requires a different toolset. Partial functions, mutable and immutable types playing together, and scala’s collection library just make this simple. If the system grows just snap on a trait to add what you forgot.  Let’s take Twitter for example. Robey  Pointer wrote Kestrel, and probably others that I don’t know, that enables a lot of real-time scale for them.  Kestrel is a loosely ordered message queue that eloquently wraps scala’s mutable queue hashmap with a swarm of actors to attack the queue. Not to short change Robey as his guthub account is one of the best in the community! But the scaffolding of scala really makes this solution possible. The syntax of scala and ease of deployment also probably made it a reasonable goal to attack while #failwail’s were abound!

Obviously many people have dealt with this scale  problem in PHP successfully. I however find it very difficult to mentor people through the depths of hell that I have been through. When it comes to scalability in PHP this is what your resume looks like.

  • Fantastic at PHP internals
  • Amazing at Apache HTTPD and compiling appropriate PHP extensions.
  • Nginx
  • BigIP – More than round robin load balancing
  • Intimately know how sessions work and probably write your own handlers
  • Memcached
  • APC
  • AMQP
  • BeanStalkd
  • Code based sharding or at least master/slave logic
  • C/C++
  • Lots of security! It’s a problem with all dynamic languages.
  • Zend Framework.

FYI the latest Zend Cluster Server really makes a TON of this easier! Bravo!

This is a really hard resume to replicate. I know; I have tried! More importantly it is very hard to debug. As we continue to add more screens, more protocols, and more data aggregation services, and frankly more data we need to be able use all cores in the server and the cluster. As Guy Steele implied at Strange Loop. The single processor programming model is going the way of the punch card.

What about bringing a scala programmer on board?

This is a scala resume.

It really is a grind to overcome that first 4-6 months but if you need scale I would recommend taking the haul. It will change how you think about problems forever. There is nothing like having your entire system in source code that can be type checked in your IDE as you write. No need for amqp with actors, no beanstalkd with mutable queues, and it’s fast as hell!

If joomla and wordpress do everything you need, then your cool! Just like my lame blog! In the same vain I believe that PostgreSQL is the best database for the majority of data persistence scenarios. Hopefully my next post will be why HBase is the bomb!

Special thanks to the following scala studs for getting me past the grind. I really appreaciate the community support so far! Follow these guys on twitter and read their blogs. They are leaders in the scala community but have still taken the time to answer my neive questions! Almost everything I know has come from their books or blog posts.

So is scala hard? Sure, but I personally recommend never bringing a knife to a gun fight. Especially when the competition has Uzi’s!

Wade

scala

  1. Nate Buwalda
    November 18th, 2010 at 09:36 | #1

    Thanks for this post. It’s nice to see some basic revealing of why we should move to Scala and how simple it is to get started.

  2. Leric Zhang
    November 18th, 2010 at 21:21 | #2

    But you didn’t mention the DB part in scala, which is most tricky in scale

  3. November 20th, 2010 at 11:05 | #3

    Hi, I wrote a reply to your blog post here: http://bit.ly/bY1Tlu

    Let me know what you think.

  4. James Fisher
    November 21st, 2010 at 18:43 | #4

    I would love to live in a syntactically concise manor.

  5. November 21st, 2010 at 20:59 | #5

    @leric You are right the DB part is hard in Scala as well as PHP. I should have noted that the THRIFT implementation in PHP is horrible. It is something that I tried to work with about two years ago when trying to connect PHP to cassandra. It has taken a long time but we finally have a pretty decent PHP client for cassanrda. https://github.com/mjpearson/Pandra

    I have been using HBase for my current development and am very happy with it. I have just used the native Java api’s and that seems to be working fine. As I add additional developers it is becoming apparent that the Java api is to complex and I plan on releasing a Lift Record connection for Hbase.

  6. November 22nd, 2010 at 10:33 | #6

    Oh yes, because ALL PHP developers have C/C++ in their resume. And Scala ones don’t.

    Flamebait.

  7. November 22nd, 2010 at 11:16 | #7

    I am saying that at some point you need to get into the PHP internals or write your own PECL enhancements. If you have not then all is good and this blog post does not apply to you. Note the beginning paragraph.

  8. Mike
    December 14th, 2010 at 03:06 | #8

    ‘Debasish “The almighty” Ghosh’ is so funny. I think of that every time I see him on Twitter now.

  9. December 16th, 2010 at 11:20 | #9

    I actually now call him: Debasish “The Holly” Ghosh

  10. Alex
    June 13th, 2012 at 01:55 | #10

    @wadearnold

    Wade, have you ever got around to writing a Record interface for HBase?

  1. November 18th, 2010 at 15:04 | #1