Write code that minimizes the time it would take someone to understand it*
* That "someone" might be you 6 months later
Yes, but...
this.document.deserialize(loadedPlugins, docData['state'], changesCallback, docData['action_history_length'], docData['id'], docData['next_connection_id'], docData['creator_id'], function() {...});
this.document.deserialize(
loadedPlugins,
docData['state'],
changesCallback,
docData['action_history_length'],
docData['id'],
docData['next_connection_id'],
docData['creator_id'],
function() {...}
});
Write code that doesn't need comments
container.on('scroll', goog.functions.throttle(function(e) {
var b = this.body;
if(b.scrollHeight - (b.scrollTop + b.clientHeight) < 150) {
this.loadNextPage();
}
}, 20, this))
// infinite scrolling
container.on('scroll', goog.functions.throttle(function(e) {
var b = this.body;
if(b.scrollHeight - (b.scrollTop + b.clientHeight) < 150) {
this.loadNextPage();
}
}, 20, this))
this.infiniteScrollHandler = goog.functions.throttle(function(e) {
var b = this.body;
if(b.scrollHeight - (b.scrollTop + b.clientHeight) < 150) {
this.loadNextPage();
}
}, 20, this);
container.on('scroll', this.infiniteScrollHandler);
//focus on email field
$('#email').focus();
/* can't group selectors with placeholders for different browsers, won't work :( */
::-webkit-input-placeholder {
color: grey;
}
::-moz-placeholder {
color: grey;
}
:-ms-input-placeholder {
color: grey;
}
::placeholder {
color: grey;
}
val (domainPolicyOpt, domain) = Registration.getDomainPolicy(email)
domainPolicyOpt.flatMap { domainPolicy =>
// domain policy found - add new user to existing account
services.user.getDomainAccountId(domain).map { teamAccountId =>
...
}
}
val (domainPolicyOpt, domain) = Registration.getDomainPolicy(email)
domainPolicyOpt.flatMap { domainPolicy =>
logger.debug(s"Domain policy found for $domain. Adding user to existing account")
services.user.getDomainAccountId(domain).map { teamAccountId =>
...
}
}
teamUserProvisioner.processLogin(
newUser,
"free",
productAccount
)
validateForm | getErrors, isValid, bindFromRequest |
getToken | getToken, createToken, generateToken, fetchToken |
checkRestrictedPlugins | alertIfRestrictedPlugins |
processLogin | runPostRegistrationActions |
Maybe your method is doing too much!
All code in any code-base should look like a single person typed it, no matter how many people contributed.
function showOneDriveImport() {...}
function showOneDriveImport() {
var maybeFeature = this.optfeatures.getFeature('oneDriveImageImport');
return !!maybeFeature && maybeFeature.isEnabled();
}
It should be obvious that the value is a boolean
page.getSVG(dpi, true, false)
page.getSVG({
imageDpi: dpi,
includePageBackground: true,
compress: false
})
page.getSVG(
/* imageDpi */ dpi,
/* includePageBackground */ true,
/* compress */ false
)