Coder Social home page Coder Social logo

Comments (1)

francesco-strazzullo avatar francesco-strazzullo commented on June 28, 2024

Hi @apiraino,
In my opinion, the main problem when using a framework is inappropriate coupling. Every time that you let a framework make a decision for you, that decision is hardly reversible. Evolvability is a great asset when developing a complex application, but to evolve you need to make reversible choices.

Every framework will help you with some kind of problem, but the help comes with a tradeoff. And to understand what are the tradeoffs of technical decisions is one of the purposes of this movement.

So, when we use a framework because we accept the tradeoffs we try to stick with an approach that we call "Defend from frameworks". You can translate it with "using Frameworks responsibly". This example should make clear what I mean. This is a standard AngularJS controller.

app.factory(‘getUsers’,[‘$http’,function($http){
 return $http.get(‘api/v1/users’);
});

app.controller(‘home’,[
 ‘$scope’,
 ‘getUsers’,
 function(
     $scope,
     getUsers){
         getUsers().then(function(response){
             $scope.users = response.data;
         });
}]);

As you can see we're using the standard $http service to make XHR requests. Today we have the fetch: a standard API to make XHR requests. The code will change like this. Using fetch the code will look like this:

users.js

export default function(){
   return fetch(‘api/v1/users’).then(function (response) {
       return response.json();
   });
};

Controller

import getUsers from ‘./getUsers’;
app.controller(‘home’,[
   ‘$scope’,
   function(
       $scope){
           getUsers().then(function(users){
               $scope.users = users;
           });
}]);

So as you can see I'm not using $http here. Doing that I probably reduced the coupling between my business logic and the framework, making my application more evolvable.

This is what I mean when I say "using Frameworks responsibly". Use them when it's useful, but never forget tradeoffs.

from manifesto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.