why you should consider a microframework for your next web project

21
Why you should consider a microframework for your next web project by Joaquín Muñoz, age 24 and two thirds. @Chekosoft | github.com/Chekosoft

Upload: joaquin-munoz-munoz

Post on 01-Nov-2014

457 views

Category:

Technology


0 download

DESCRIPTION

An explanation why you should consider to use a microframework over an MVC, depending on what you want.

TRANSCRIPT

Page 1: Why you should consider a microframework for your next web project

Why you should consider a microframework for your next web project

by Joaquín Muñoz, age 24 and two thirds.@Chekosoft | github.com/Chekosoft

Page 2: Why you should consider a microframework for your next web project

A good web framework is a good companion

because it speeds up development (a lot)

How?

They implement and/or simplify most of the tedious tasks and boilerplate.● Data manipulation● Templating● Security● Session management● {insert a tedious but necessary task to do}

Page 3: Why you should consider a microframework for your next web project

The most popularMVC-based frameworks, like:

Page 4: Why you should consider a microframework for your next web project

But MVCs have a little “problem”

They areRIGID

Page 5: Why you should consider a microframework for your next web project

But, before going like this:

Because of my previous statement.

Page 6: Why you should consider a microframework for your next web project

Why are they rigid?● Strict adherence to a set of development

patterns/philosophies/principles.

● If you want to replace one core component, additional work must be done.

● When a core component is replaced, some “magic” is gone with it. And replacement magic isn’t as good as the default one.

● Implementing your own magic/extensions/etc require from little modification to mashing your head on the table.

(the previous statements may not apply to some frameworks)

Page 7: Why you should consider a microframework for your next web project

But they’re rigid because they need to be

All those cool features are built on top of a rigid, stable base.(Comfortable, too)

So, it begs the question:Should I remove the cool things for

customization?

Page 8: Why you should consider a microframework for your next web project

Short answer:

No.

Long answer:

OH GOD PLEASE NO! NO! NOOOOOOO!

Page 9: Why you should consider a microframework for your next web project

“But I really want to do {x} on {y}”

You have two ways:

● Roll Your Own○ If it doesn’t remove core features:

■ Awesome!○ If something else breaks in the process:

■ Welcome to Stack Overflow.

● Use a microframework

Page 10: Why you should consider a microframework for your next web project

A microframework like

only deals with a reduced set of tasks(mostly routing and session handling)

Giving you freedom over the components/patterns/conventions you want/need to use.

Page 11: Why you should consider a microframework for your next web project

Freedom is a keyword here

Page 12: Why you should consider a microframework for your next web project

So, you can use anything you want to develop different

aspects of your project

with little or no additional work.

● NoSQL databases● Custom templating engines● ViewModel paradigm● Custom user management● or nothing at all

Page 13: Why you should consider a microframework for your next web project

Think of a microframework as a nice foundation to stack the components

of your future solution.

Page 14: Why you should consider a microframework for your next web project

Another advantage of microframeworks

If your project is small the code will be small.

With an MVC framework, your project starts at almost medium size and then it grows from there (big projects won’t even notice).

(most of the time)

Page 15: Why you should consider a microframework for your next web project

An example

Contoso wants to do a “Hello” public API. Which answers with “Hello!”.

Let’s pretend this is a very interesting project.

Page 16: Why you should consider a microframework for your next web project

$ gem install rails

$rails new hello-app$rails generate controller hello index

$vim app/controllers/hello.rb(write the code)$emacs routes.rb(write the route file)

$rails s#Success

If we use Rails, we should do something like:

Page 17: Why you should consider a microframework for your next web project

It works......but all the additional components will only be using extra space.

And it will require time to remove them (or you must remember to not include them in first place).

Page 18: Why you should consider a microframework for your next web project

$gem install sinatra$touch hello.rb

$subl hello.rb

require ‘sinatra’get ‘/hello’ do ‘Hello!’end

$rails hello.rb== Sinatra has taken the stage …>> Listening on 0.0.0.0:4567

If we use Sinatra, this could be done as:

Page 19: Why you should consider a microframework for your next web project

The same happens with Django and Flask

With Django you need to create a project, then an application, then edit the controllers, add the created application to…

(it keeps going on)

With Flask, you need to do this after getting it using pip or easy_install (maybe not easy_install).

from flask import Flask

app = Flask(__name__)

@app.route(‘/hello’)def hello(): return u’Hello!’

if__name__ == ‘__main__’: app.run()

Page 20: Why you should consider a microframework for your next web project

With ASP.NET MVC, use Visual Studio.

With Nancy, it’s like this:

1. Create a project with your favorite IDE.2. Get Nancy from NuGet3. Create a new file (C#) with the following.

namespace Hello { public class HelloModule: Nancy.NancyModule { public HelloModule(){ Get[“/hello”] = _ => “Hello!” } }}

Press F5, get bacon.

Page 21: Why you should consider a microframework for your next web project

Thank you for your attention.And, if you want to use a microframework:

Be Tidy(Or you’ll really regret it)