Tired of web development, looking for extreme ways to avoid boilerplate code - a meta-framework? [closed]

StackOverflow https://stackoverflow.com/questions/23570207

  •  19-07-2023
  •  | 
  •  

Вопрос

Having written quite a few apps with modern web frameworks (Symfony2, Laravel, Rails, expressjs, angularjs...) I can't help but think that about 90% of the time I spend developing is spent on writing CRUDs. Then I spend 10% of the time doing the interesting part: basically defining how models should behave.

This is demeaning, I want to reverse the ratio.

The above mentioned frameworks almost all go out of their way to make the boilerplate tasks easier, but still, it is not as easy as I feel it should be, and developer brain time should be devoted to application logic, not to writing boilerplate code.

I'll try to illustrate the problem with a Rails example:

  1. Scaffold a CRUD (e.g. rails generate scaffold user name:string email:string password:string)
  2. Change a few lines in the scaffolded views (maybe the User needs a Role, but scaffold doesn't know how to handle it)
  3. ... do other things ...
  4. Realize you wanted to use twitter bootstrap after all, add the most magical gems I can find to help me and...
  5. Re-scaffold my User CRUD
  6. Re-do the various edits I performed on the views, now that they've been overriden by scaffold
  7. ...

And this will go on and on for a while.

It seems to me that most magic tools such as rails generate will only help you with initial setup. After that, you're on your own. It's not as DRY as it seems.

I'll be even more extreme: I, as a developer, should be able to almost build an entire project without worrying about the UI (and without delegating the task to someone else).

If in a project I need Users with Roles, I would like to be able to write just, say, a .json file containing something along the lines of:

{
    "Schema": {
        "User": {
            "name" : "string",
            "email": "email (unique)",
            "password": "string",
            "role": "Role"
        },
        "Role": {
            "name": "string (unique)"
        }
    }
}

I would then let the framework create the database tables, corresponding views and controllers. If I want to use bootstrap for the UI, there would be a setting to toggle this in the master .json file. And at no point would I edit a single view. If later I add a field to User or want to change the UI style, I just edit the master .json file.

This would open the way for a creative branch of UX design. I could, for instance, assign an importance flag to each field of the User model and let a clever designer write a plugin that designs forms whose layout is optimized by the relative importance of fields. This is not my job, and it is not the UX designers' jobs to rewrite the same thing a 100 times over for different projects, they should write "recipes" that work on general, well specified cases.

I have a feeling that the MVC pattern, with all its virtues, has too much decoupled the view from the model. How many times have you had to write validation code twice: once server-side and once client-side because you wanted richer feedback? There is much information to be gotten from the model, and you should be able to get client side validation by just setting a property on the model telling the framework to do so.

You may say that Rails scaffold is close to what I'm imagining, sure. But scaffolding is only good at the beginning of the project. Even with scaffolding, I need to rewrite many things to, say, only allow an Admin to change a User's role.

The ideal framework would provide me with a simple hook to define whether the action of changing the Role field on a User is allowed or not, and the UI would automagically display the error to the user if I return it properly from the hook.

Writing a User system should only take a few minutes. Even with things like devise for Rails or FOSUserBundle for Symfony2 it takes a huge, unnecessary amount of configuring and tuning.

The meta-framework I have in mind could be, in theory, used to generate the boilerplate code for any modern web framework.

I would like my development workflow to look like this:

  1. Create app.json file defining the models and their relationships, + the hooks I want to specialize
  2. Run a command like generate_app app.json --ui=bootstrap --forms=some_spectacular_plugin --framework=rails4
  3. Implement the hooks I need
  4. Done.

The resulting app would then update itself whenever app.json changes, and adding entities, fields, custom logic should never be harder than writing a few lines of JSON and implementing the interesting parts of the logic in whatever the target language is.

I strongly believe that the vast number of frameworks out there address the wrong question: how to write little bits of unconnected code more efficiently. Frameworks should ask: what is an application and how can I describe it?

Do you know of any projects that would be going in this direction? Any pointers to literature on this?

Это было полезно?

Решение

I have been confronted couple of times to similar development tireness – boilerplate over an over. For me boiler plate is all that does not bring any added business value (static: project setup, contextual: CRUD (backend, frontend), drop-down list, sub-Usecase for affectation etc..., etc...)

The approach presented is command line generation of rails scaffold artifacts which has the following pitfalls : incomplete and brittle on maintenance. Generation covers the aspects of generating same information (redundant info) over different type of artifacts (DB storage, presentation layer, persistence layer etc…)

Furthermore consecutive generation overrides your changes.

To solve this inconvenience, I see only two solutions :

  • Do not use generator but a generic framework that manages in one central place persistence and presentation aspects. In java there is Openxava that is designed for that. It works with annotations (persistence and presentation), it also answers your validation question with stereotype.

  • Use an updatable-generated-code generator. Minuteproject gets updatable-generated-code feature. You can modify generated parts and the next generation keeps your modifications. Meanwhile none of those solutions matches your technology target (Rails).

Minuteproject can be extended to generate for any text based language (java, ruby, python, c, js…).

Minuteproject generates from DB structure, query statement, transfer-object definition see productivity facet for analysts

Remark : minuteproject also provides a reverse-engineering solution for Openxava

In the sequence summary proposed :

  1. create model, relationship + hooks, I would go rather consider the DB model as a center place and add hooks (not yet present) in model enrichment (minuteproject propose a dedicate to enrich the model with conventions…) I rather go for reverse-engineering solution than Forward engineering for the following reasons :

    • correct DB storage is too crucial to be generated :
    • Forward engineering cannot generate view, stored procedure, function etc...
    • Forward engineering may not tune correctly (tablespace) your persistence model.
  2. generate by picking up your technology target

  3. implements the hooks in updatable-generated-code sections, so that at the next generation (model structure has changed, new hooks are to be implemented), your previous hook-implementations are kept.

I have create some to-be-implementated (hook) for Openxava (http://minuteproject.blogspot.be/2013/08/transient-definition-as-productivity.html)

But minuteproject approach is technology agnostic so artifacts could be as well generated for other frameworks.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top