Final Days as Student at MakerSquare

I am on my last day as a Student at MakerSquare, I have been accepted as a Fellow (more on that later) but I thought it might be a good time to do some reflecting. First thing that strikes me is how long it seemed at the start and how quickly the time went by. I swear days turned to minutes and weeks to hours. I am amazed at how much I learned in such a short period of time. It has been exponential!

I am also aware that the bonds I have developed need attention if I want them to last a lifetime. I am making it a priority to stay in contact with those I have grown close to. This is easily my weakest area so I hope I can stay on top of it. I will never forget the late nights coding and watching TNG. Even the frustrating moments and mini-conflicts that popped up only seemed to draw me closer to my fellow learners.

Even though I am staying on for a bit longer I am still very excited to see what happens to them next. It will give me a hint as to my own future, more things to look forward too, more struggles, more life! I love you all and can’t wait to see the great things that I am sure you will all do!

Importance of Self Documenting Code

What is self documenting code?

Let’s first take a look at code that is not self documenting.

var x = 1;
if (y === true) {
  x += 1;
}

vs 

let count = 1;
if ( loggedInSuccessfully === true ) {
  count += 1;
}

Even though this is a very simple example you can see right away that in the first example it is unclear what x is used for. You may be able to figure it out in context of the rest of the program but you might not.  In the second example it’s much easier to deduce that we are incrementing count every time someone has logged in successfully is true.

Now imagine this was a more complex function in the code.

function z () {
  let x = [];
  let y = _.keys(s);
  tables = _.map(y, function (y) {
    return function () {
       return z(y);
     };
   });
 return sequence(x);
}

vs

function createTables () {
  let tables = [];
  let tableNames = _.keys(Schema);
  tables = _.map(tableNames, function (tableName) {
     return function () {
       return createTable(tableName);
     };
  });
 return sequence(tables);
}

In this slightly more complex example there is only one clue as to what you might be doing in that first function. It’s the keyword sequence and even that just gives you a hint that they might be using the when promise library. This would require that either you wrote the horrible code so you know what it does or a decent amount of time trying to use it with in the code base.

The second one, well it looks like it wants to create a table based off an array of tables using the a function called keys to read the table names from a Schema variable. Then it builds that array by using a function called map to go over the tableNames schema, returning a function that calls the createTable function on the passed in tableName. Then we return the sequence output on that array we just finished building.

Even if that second paragraph does not make complete sense it will let you discuss the function with other programmers or support forums in a more intelligent way. That is the main benefit of self-documenting code, however it will also help you remember what you were doing when you have to revisit the code later.

One of the side effects of self-documenting code are potentially very long variable names. I have seen things along the lines of thisWillBeWhereWeStoreTheResultsOfTableCreationErrors. A bit hard to swallow but I have a pretty good idea what type of data I should expect to retrieve or store there.

Breaking it down

Reasoning

  • Create readable and understandable source code
  • Make it easier on the next guy (or your memory)
  • Keep code cleaner with less comments
  • Keep the documentation inside the code

Practices

The main goal is to make it as human readable as possible. Instead of single word variables use a phrase that is more closely tied to the meaning. The other aspect is to use white space to keep the structure consistent and reduce obfuscation of the algorithm being used.

Gotchas

 

There are things to watch out for, if working with a team, is to maintain uniformity, consistency and to make sure it doesn’t get too far out that it becomes a novel to go through your code.

If you stick to these basic guidelines you will do better than many professional developers out there. If you want to learn more head over to the wiki page.

Maker Square Day 2

Here is the rough schedule for the day:

  • closures
  • underscore pt1
  • lunch
  • underscore pt1
  • this keyword
  • underscore pt 2
  • group meeting
  • dinner
  • lecture

I am being deliberately vague here. Somethings you have to pay to get the info, ya dig? I list it to illustrate that the days are fairly full right off the bat making me think they will ditch some of the “welcome to…”, “benefits” and “how to kick ass” type lectures in favor of even more JavaScript stuff.

Let’s see if my notes improved:

A closure is a function that has on going access to the variables of the context it was created in, even after outer function calls it was created in have returned.

assign Saga() to global var
 new Saga = function() {
 sagas.push(function(){ blah; }
 sagas[0]();
 }

Okay so not much better really but at least it had a basic definition of a closure. Here is a better example:

function init() {
// name is a local variable created by init
var name = "Mozilla";
// displayName() is the inner function, a closure
function displayName() {
alert(name); // use var declared in the parent function } displayName(); }; init();

Then we examined some underscore functions and the whats going on behind them.
_.extend = function(obj) {
_.each(arguments, function(passedObj){
_.each(passedObj, function(value,key) {
obj[key] = value;
});
});
return obj;
}

In Human:

for an object(s)
iterate over the arguments (objects)
iterate over each passed object
assign object[key] to the passed value

_.defaults = function(obj) {
  _.each(arguments, function(passedObj){
_.each(passedObj, function(key, value){
      if(obj[key] === undefined) {
obj[key] = value;
}
});
});
return obj;
}

In Human:

for an object(s)
iterate over objects arguments
if element does not exist in obj, add to obj

Interesting topic popped up about the !! convention. It forces coercian of the result to boolean.

Interview Question: How do you access a function inside of a return function? ()()… That is a bad note.. avoid this section.

Then there was a lecture on something about macs or something. I only just listened to this at the edges. I use linux so not much benefit, I took notes but I will never use them, so I am not typing them.

There was a cool GIT section though.
git remote -v //shows remotes
git remote add <username> https://github.com/<username>/<repo&gt;.git
git branch -v show //shows branch
git checkout -b pairs //create and go to pairs branch
git checkout master
git push <username> branch:newBranch

Push to two repos in one command:
$ git remote -v
origin me@original:something.git (fetch)
origin me@original:something.git (push)
//add 'pairs' remote
git remote add pairs me@original:something.git
//add url
git remote set-url --add --push both git://somewhere/something.git
$ git push pairs

this

A new four letter word. In 4 steps.

  1. Debugger paused on this.
  2. Scan outward for function {}.
  3. once function containing this is found look at the where stack
  4. inspect syntax of how the function was called to see which run pattern is being is being used.

Run Patterns

  • Global Reference
    • Why?
      • Needs a value
    • What?
      • In a browser its window
    • example
      • this (not enclosed in any function)
  • Free Function Invocation
    • Why?
      • Needs a value…
    • What?
      • global object
    • example
      • functionName()
  • ABC (.apply, .bind, .call)
    • Why?
      • to manually pass in a this binding, like passing in an argument when invoking a function/method
    • What?
      • the first argument to .apply, .bind or .call
    • example
      • fn.call(target) or obj.methodName(target)
  • Method Invocation
    • Why?
      • to execute the method in the context of the object they’re found in
    • What?
      • Object on the left of the call time dot
    • example
      • target.methodName();
  • Construction Mode
    • Why?
      • Allow a constructor to operate on the instance it is creating
    • What?
      • A new object created for that invocation
    • example
      • new functionName()

90% Rule

Inside a function, the keyword ‘this’ will be bound to the object that was left of the dot where that function was called.

The last lecture I took notes on was about some things to do and ways to think that can help you at Maker Square.

Set up a blog. Okay I was a little late on that but as they say blah blah late blah blah never.

There will be people here who work harder, learn faster, code stronger and think better than you…. learn to deal with that. (trust the program)

Have a growth mindset vs a fixed mindset. (trust the program)

This sparked a note for me to tell Muhammad about Richard Feynman, the ultimate in growth mindset.

Judge yourself by the core curriculum, not by others. They said this a few times. (trust the program)

Work hard, be strong and ask for help! (trust the program)

What does a professional developer look like?

coders_block-100531704-orig

Coders Block!

Learn the workflow, its important!