Hacker News new | past | comments | ask | show | jobs | submit login
Sinatra clone in Scala (github.com/alandipert)
31 points by wooby on May 31, 2009 | hide | past | favorite | 12 comments



Is the whole thing really just the one file (110 lines)? http://github.com/alandipert/step/blob/42cee9ecd360205def359... I know it describes itself as "tiny", and sinatra is also tiny, but that seems... small. (I don't know anything about Scala - is it especially concise?)

I like how the HTML seems to be a first-class datatype in the example (is that a Scala thing? I'd better do some research):

    get("/date/:year/:month/:day") {
      <ul>
        <li>Year: {params("year")}</li>
        <li>Month: {params("month")}</li>
        <li>Day: {params("day")}</li>
      </ul>
  }


Yeah it's pretty small. With Scala you basically get free HTML templating because of XML literal support. It's missing a lot of Sinatra stuff though: 'splat' and regex URI pattern matching, file uploads, sessions...


Maybe leveraging pattern matching could improve.

Actually - we can be able to implement our own methods get(), post(), etc. via pattern matching... So inspiring - on my way to fork it. ;)


Awesome. I actually fired up Sinatra on JRuby for a micro-app that needs to talk to some Java stuff last week. All of the existing stuff in Scala was way too heavy for the purpose. (Clojure/compojure has comparable overhead to Sinatra assuming you're familiar with Clojure, but it was untenable in this particular circumstance.)

At least half the magic of Sinatra is that you can write a single Ruby script, exec it and not have to fool around with build/generate/scaffold script or web server configuration to get something useful. It seems like you're pretty close, given that Java has no standard dependency retrieval system.


Amazing conciseness. Don't forget to check out lift web framework http://liftweb.net/. It's written in Scala too and uses similar techniques.


Very cool. I notice that you're using sbt to build. I'm using maven to build a scala project. I'd be very interested to know how sbt compares to maven if you have experience with both build systems.


I haven't used maven (the first version of this thing used ant+ivy), but it was pretty messy compared to what I have going now. I'd say if you have the luxury of working with a Scala-only project, sbt is definitely the way to go.


It looks like there is no separation between view and controller. Mixing HTML into your controller methods seems like a step backwards.


If this is a port of Sinatra that is an option to make a very small concise webservice. You can choose to do seperation, but if you want something very simple and compact a single file can be easier. We have a Sinatra app that has the model,view,controller, and tests in a single file that is less than 250 LOC. It would be more obfuscated to have 5 files of less than 50 LOC each (Some with as little as 4 lines).

If it doesn't provide any option for separation that is bad, but for micro services it can be really nice.


For sure. I'm just using XML literals in the example because it looks cool. But I'm also using this for a client job, and it's producing JSON.

It's not nearly as powerful as the real Sinatra, but it saves me the shenanigans of warbling Sinatra apps for servlet deployment.


I have barely glanced at Scala, but I assume that it has HTML templating libraries. You can then make your controller pass whatever data structure you want to the template, which then takes care of rendering the view.

Microframeworks are appealing in that way: you can pick and choose which components to use, and they let you adapt MVC to whatever fits most naturally to your application. It's hard to argue with the brevity of the underlying code and the clarity of the example.


Presumably there's nothing stopping you from factoring out all that HTML into methods on a 'view' class.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: