Unleash your JavaScript – using ancient philosophy



Unleash your JavaScript – using ancient philosophy

0 0


AncientJavascriptPhilosophy

AncientJavascriptPhilosophy - Slides from Buildstuff.lt

On Github emilcardell / AncientJavascriptPhilosophy

Unleash your JavaScript

using ancient philosophy

Philosophy + JavaScript

WAT?

Selfie

  • Father
  • Zerg player
  • Humble anarchist
  • Developer at Thomas Cook NE (Stockholm Office)
  • Fluent in C# and JavaScript

Conways law

"organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations"

Stoics

Ethos, Pathos, Logos

"I cannot know whether I shall help the man to whom I give advice; but I know well that I shall help someone if I advise many.  I must scatter this advice by the handful. It is impossible that one who tries often should not sometime succeed."

Seneca, Lucius Annaeus - Letters from a stoic

Path to happiness

control those things that are within our power (namely our beliefs, judgments, desires , and attitudes) and be indifferent or apathetic to those things which are not in our power (namely, things external to us)

Fooled By RandomnessThe Black Swan Antifragile

Nicolas Taleb

Dealing with dependencies

  • Isolate
  • Reduce/Remove
  • Multiple options

Make it

Transparent

Always

List of dependencies

  • Place
  • Order
  • Time
  • Input
  • Output
  • State/Change

Autonomy

Starting point

var aDependency = "I'm a dependency";

var module = (function (publicModule, myDependency) {
	
	var somethingPrivate = "I'm private";
	publicModule.somethingPublic = aDependency;

	return publicModule;
}(module || {}, aDependency));

var output = module.somethingPublic;
output;
Repl

Autonomy

Order

Place

Dependency injection

var aDependency = "I'm a dependency";

var myModule = function (myDependency) {
	var publicModule = {};
	publicModule.somethingPublic = aDependency;
	return publicModule;
};
Repl

Input

Place

Testable

Pub / Sub

Single truth

var aTruth = function () {
    var publicModule = {};
	publicModule.number = 0;
	publicModule.ChangeState = function(aNumber) {
		publicModule.number = aNumber;
		//Publish
	};
	return publicModule;
};

var aSubscriber = function()
{
	//Subscribe to change
	return {};
}
Repl

Input

Output

State/Change

Callback hell

var longRunning = function()
{
    window.setTimeout(function() { logger("Work done") },2000)
}

var yetAnotherLongRunning = function()
{
    window.setTimeout(function() {logger("Work done") },1000)
}

longRunning();
yetAnotherLongRunning();    
logger("All done!");
JsFiddler

Time

Multiple options

describe("First state", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
  describe("Something else is going on", function() {
	  it("contains spec with an expectation", function() {
	    expect(true).toBe(true);
	  });
	});
});

Order

State/Change

Dealing with dependencies

  • Isolate
  • Reduce/Remove
  • Multiple options

Path to happiness

control those things that are within our power (namely our beliefs, judgments, desires , and attitudes) and be indifferent or apathetic to those things which are not in our power (namely, things external to us)

Apply to other things

Read more philosophy

Write more code

Farwell

@emilcardell