DAMP

reviving readability


[NebraskaJSLightningTalk initWithPresentorIntroduction:[NEJSSeanLarkinUser giveExceptionalIntroduction]];

Nebraska JS, Lincoln, NE, 2015

Sean Larkin, UI/UX Developer at Infogroup

@TheLarkInn : twitter/codepen/github

Who Am I?

  • Technical Support Background
  • Been a developer for 3.5 years
  • AngularJS Fanboy
  • Readability Junky

  • Written in JavaScript, Obj-C, Rails, ColdFusion, Ruby, C# and JavaScript.
  • Urban Chicken Farmer (ps eggs for sale $3.50/dozen)

My mom really likes the chicken selfies...

Nobody's a worst programmer than your past self.

- Jamie Talbot

My first programming acronyms

WET

DRY

Don't
Repeat
Yourself

What is DRY?

  • The DRY programming philosophy was first coined in The Pragmatic Programmer by Dennis Ritchie and Francisco Granados.
  • The philosophy aims to eliminate as much repetitive information as possible.

"Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." — The Pragmatic Programmer

  • Applies to not only code, but databases , networks, infrastructure; Any and every technical system.

What is

WET?

WE
ENJOY
TYPING

WET Is...

  • Not DRY
  • Code Duplication
  • "Multiple Sources of Knowledge"

WET Is...

var Category = function(objectProperties) {
  this.childCategory = objectProperties.childCategory || [];
  this.name          = objectProperties.name || "";
  this.description   = objectProperties.description || "";
}

Category.prototype.getChildCategoryName = function() {
  if (!this.childCategory instanceof Category) {
    throw("Child Category is not of instance Category")
  }
  return this.childCategory.name;
}

Category.prototype.getChildCategoryDescription = function() {
  if (!this.childCategory instanceof Category) {
    throw("Child Category is not of instance Category")
  }
  return this.childCategory.description;
}

DRY Is...

var Category = function(objectProperties) {
  this.childCategory = objectProperties.childCategory || [];
  this.name          = objectProperties.name || "";
  this.description   = objectProperties.description || "";
}

Category.prototype.validateChildCategoryInstance = function() {
  if (!this.childCategory instanceof Category) {
      throw("Child Category is not of instance Category");
  }
}

Category.prototype.getChildCategoryName = function() {
  this.validateChildCategoryInstance();
  
  return this.childCategory.name;
}

Category.prototype.getChildCategoryDescription = function() {
  this.validateChildCategoryInstance();

  return this.childCategory.description;
}

SO?

DAMP

DAMP...

  • Is not halfway between WET and DRY
  • Compliments WET and DRY
  • But Doesn't interfere

What is it?

Damp Applies to how you name all the things!!!!!!

What is damp?

Descriptive

And

Meaningful

Phrases

Promotes the READABILITY of Code

To maintain code, you first need to understand the code. To understand it, you have to read it. Consider for a moment how much time you spend reading code. It’s a lot. DAMP increases maintainability by reducing the time necessary to read and understand the code. — Chris Edwards

Maintain

Understand

Read

If I HAD A DOllar...

//dataLog.js

var data = [1, 3, 4, 6, 7, 9]; 
var logData = function(data) {
  data.each(function(i, idx) {
    console.log(i);
  }); 
};

logData(data);

MAKES ME ASK?

//Off to a great start... :(
//logData.js

// What is this data for? If it wasn’t defined here, would we know 
// what data type it is?
var data = [1, 3, 4, 6, 7, 9]; 
 
 // What kind of data are we logging?
 // What is the data type of the argument?
 var logData = function(data) {
   
   // What are the arguments inside the each function?
   data.each(function(i, idx) { 
     console.log(i, idx);
   });
};

// Well at-least I know something happens here...-_-'
logData(data);

LETS GET DAMP

//slPrintChildArrayNamesModuleButCommentsAreNotNeededWhenYouProgramWithDAMPFundementals.js

var childAgesArray = [1, 3, 4, 6, 7, 9];

var logEachAgeInArray = function(agesArray) {
   agesArray.each(function(ageInteger, index) { 
     console.log(ageInteger, index);
   });
};

logEachAgeInArray(childAgesArray);

NAMES TELL THE STORY

//slPrintChildArrayNamesModule.js

var childAgesArray; //Guts get assigned here
var logEachAgeInArray = function(agesArray) {
  //Guts here
};

logEachAgeInArray(childAgesArray);
function hnGutlessPredictiveSearchCtrl($scope) {

// ... omitted for brevity

$scope.inputValueIsPreFilledFromNttParam = GUTS
$scope.requestedSearchTermForHighlighting = GUTS
$scope.searchAsYouTypeArray = GUTS
$scope.indexOfLastItemInSearchAsYouTypeArray = GUTS
$scope.selectedSearchTermResultIndex = GUTS
$scope.searchQuery = GUTS

$scope.searchAsYouTypeRequestDidRespondWithSuccess = function(data, status, headers, config) {
   GUTS
};
$scope.searchAsYouTypeRequestDidRespondWithError = function(data, status, headers, config) {
   GUTS
};
$scope.shouldBeHighlightedBasedOnResultTypeAndTypeIndex = function(resultType, typeIndex, nameValue) {GUTS};
$scope.upArrowKeyPressed = function() {GUTS};
$scope.downArrowKeyPressed = function() {GUTS};

$scope.setSelectedIndexViaMouseOver = function(resultType, typeIndex) {GUTS};

$scope.submitProductCategoryToAnalytics = function(productCategory, $event) {GUTS};

$scope.submitSuggestionToAnalytics = function(suggestion, $event) {
  GUTS 
};
  // ... omitted for brevity

};

WHY DAMP!!!

  • CODE BECOMES YOUR STORY!
  • YOU WRITE LESS (NO COMMENTS)
  • YOUR CODE STAYS READABLE
  • MAINTAINABLE

WHO DOES DAMP?

Method Names:

copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:

Interface Names: 

AVCaptureManualExposureBracketedStillImageSettings
AVCaptureAutoExposureBracketedStillImageSettings
AVAudioEnvironmentDistanceAttenuationParameters

 

 

PROPERTY NAMES:

usesAirPlayVideoWhileAirPlayScreenIsActive

LONGEST SINGLE PARAMETER METHOD:

navigationControllerPreferredInterfaceOrientationForPresentation:

 

APPLE!

Thank you!

NSDidDAMPExitFromPresentation

DAMP Coding

By Sean Larkin

DAMP Coding

DAMP stands for Descriptive and Meaningful Phrases. It strives to revive readability and transform your code from a cipher, to a clear and concise story, making it readable, supportable, and flexible.

  • 501