Mark Watson’s Artificial Intelligence Books and Blog

Share this post

Scala really is a "better Java"

markwatson.com

Scala really is a "better Java"

Mark Watson
May 31, 2009
Share
Share this post

Scala really is a "better Java"

markwatson.com

I have been so busy this year that I have slacked off on fully getting up to speed on Scala (and Haskell, for that mater). A few people have been working on a Sinatra clone in Scala. (Sinatra is a very nice minimalist Ruby web framework that I like a lot.) I grabbed a version of the Step project off the web today and I just had some time to play with it.

You could not really write something like Step in Java without writing an interpreter. With Scala, you can add syntactic sugar similarly to Ruby. Step nicely emulates parts of Sinatra; here is a code block wrapped to handle an HTTP GET request mapped to the route "/form":

  get("/form") {
    Template.page("Step: Form Post Example",
    <form action='/post' method='POST'>
      Your name: <input name='name' type='text'/>
      <input type='submit'/>
    </form>
    <pre>Route: /form</pre>)
  }

With Scala's ability to define operators and deal with code blocks, and native XML support, Step was defined in less than 100 lines of Scala code. Very nice.

Share
Share this post

Scala really is a "better Java"

markwatson.com
Comments
Top
New

No posts

Ready for more?

© 2023 Mark Watson
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing