4
$\begingroup$

In Ruby, the vast majority of usage is in web backends, 99% of the time with a framework called Ruby on Rails. My problem with rails is that it is full of "magic," wherein you type a command, and suddenly 100 LoC are written for you, or where magic methods make forms for you that include both your JS and CSS. There is another framework called Sinatra which is much closer to the reality of what is happening. I really like that it doesn't have very much "magic," but it also isn't used very much in the real world.

Which would be a better choice for introducing students to Ruby backend web development?

$\endgroup$
3
$\begingroup$

Personally, I'd introduce Sinatra first.

Which one of these is going to be easier to explain? Sinatra's "Hello World" example...

require 'sinatra'

get '/' do
  'Hello world!'
end

Or all the boilerplate that Rails generates...

$ rails new commandsapp
 create
 create  README.md
 create  Rakefile
 create  config.ru
 create  .gitignore
 create  Gemfile
 create  app
 ...
 create  tmp/cache
 ...
    run  bundle install

(and that's just from the script that generates everything!)

I would imagine that Rails would feel a little bit overwhelming for a beginner to web development. It brings a lot of baggage with it, like the MVC pattern and a lot of handy generators that are useful to experienced developers, but hide the logic to a learner.

It seems logical to me to teach using Sinatra first, and then let your students realise what the problems are. They'll be more inclined to go through the process of learning Rails, with all the extra boilerplate involved, if they see why using an opinionated MVC framework is useful.

For trivial backend applications, like you'll probably be developing at first, RoR is overkill, and there are too many concepts that you'd have to teach before actually getting to make anything. I'm a fan of teaching from the basics in this case—showing why each additional layer of libraries and frameworks is needed is far more valuable thank saving some time by skipping Sinatra. And, of course, the motivation to make something can be more easily satisfied by starting with Sinatra, and you can later introduce the 'batteries included' framework of Rails.

$\endgroup$
2
$\begingroup$

I think I can answer this via analogy with Python and a surface-level knowledge of Ruby and Sinatra, having skimmed the docs for the latter. From what I can tell the following holds true (although I'd gladly be corrected if it's too reductive):

Sinatra : Ruby on Rails :: Flask : Django

If you want a full framework for Ruby, you go with RoR; if for Python, Django.

I taught my students the basics of Flask this year, and using some great tutorials, I found I could get students up and running with a basic Flask page in no time at all. It was a powerful and simple way to combine HTML/CSS with Python without having to set up virtual environments or do any configuration beyond installing the framework.

From an educational/pedagogical perspective, I see two advantages to Sinatra:

  • It allows students to build something quickly and thus get their hands dirty with more hands-on experience. As a result...
  • It scaffolds understanding of frameworks as preparation for later use of Rails.

Scaffolding concepts in programming is essential to avoid that conceptual leap that is a hair too great. The logic of Ruby -> Sinatra -> Rails shows a logical progression of increasing complexity. It also affords those interested and more experienced students an additional challenge. Understand Sinatra? Move on to Rails. The extension for further learning is also an important factor to weigh. Where do you want all students to end up in terms of competence? What about this who want to and/or who can exceed that expectation?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.