With great power comes great responsibility...

A colleague and I often get in debates about why:

[new JS framework] > [ --new JS framework].

We get all spun out on things like shadow dom and reactivity. We pontificate about software failures and question if the project would have succeeded if we would have used <new JS framework>.

As projects fail the blame game starts. We blame tools, technology, requirements & deadlines. Rarely do we blame the implementation.

This blog was born by the emergence of two issues created by rapid development "frameworks" (AngularJS & Entity Framework).

I don't plan on teaching you about either but for the purpose of this blog just accept:

both have magical powers referred to as "two-way" data binding.

AngularJS

<div ng-repeat="s in states">  
   <div ng-repeat="c in s.cities">
       <ul>
          <li ng-repeat="p in c.people">                 {{p.Name}}
            <person="p' ng-show="p._editing">
            </person>
          </li>
          <!-- holy crap it works!-->
          <!-- 2k api calls later I DoS myself-->
       </ul>
   </div>
</div>  

And of course the API that is servicing this:

return context.States.ToList()  
   .ConvertAll(s=s> new State(){
      cities = s.cities.ToList()
         .ConvertAll(c=>new City(){
            people = c.peoples.ToList()
               .ConvertAll(p=>new People(p))
        })
});
//so easy!

Wow we are developing so fast this is great.


So whats the big deal?

On the Angular side we don't have to think twice about what we are doing... As long as a I refresh the page and what I expect shows up I love Angular! I add more and more to the app and brag about how productive I am. But when I open it up on mobile and it takes 11 seconds to load I hate Angular! Those fancy click to edits? Little did I know it was not waiting for me to click it .. and was doing an API request for every person in the USA.

Now my mindset is I hate Angular! So slow, eats way to much memory. But its only because it doesn't make me think about what I was doing.

Lets quickly pivot to the api example. With one line of C# I have written code that can query the database and return a JSON object that has a list of all States, Cities, and People! What is SQL again? Exaggeration asside, it really is that easy. What I didn't care about was how it was querying the database. I did a spot check that the correct data was comming back, and moved this party along.

In reality this is what was happening:

  1. select * from states
  2. forEach state
    1. select * from cities where state = state
      1. forEach city
        1. select * from persons where city = city

You do the math but we are talking about N*<States>*M<Cities/State>*K<People/City> O ? ..I was never good at that O notation..


Computer Science is the first engineering discipline in which the complexity of the objects created is limited solely by the skill of the creator, and not by the strength of raw materials.

We assume the framework will be fast & smart. We forget that the framework is just a toolbox with no real instructions. It's on the developer to figure out how to apply the tools responsible ways. It's time we stop searching for sharper pencils and start focusing on fundamentals. Any seasoned software engineer can write good software in any language. But its not because he knows the language its because he understands the process and has S.O.L.I.D fundamentals.

I should not be allowed to use AngularJS until I can explain to you what "OO" means. Once I understand Object Orientation then teach me the prototype chain. Once I understand the fundamentals then its time to use the big boy tools. Same goes with API's I should study REST, I should understand SQL, I should monitor the number of queries I am executing. I should simple care and think about what I am doing.


I want to close by saying that I do produce bad code. Never proud of it/but am always willing to fix and learn from my mistakes. And I am a fan boy of AngularJS and C# is near the top of my favoite languages.

What scares me is how "easy" it is these days to write bad code and hence the title of this blog post:

With great power comes great responsibility...

Nick Capito

Professional developer in all things generic. Good at AngularJS, CSS3 , Sass, .NET, Azure, Node. Love dogs. In an alternate live I would have been an American Cesar Millan.

Richmond, VA http://nixo.us