Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about its behavior:

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates:

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function:

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to:

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular Convention for naming a function or variable as both plural and singular

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about its behavior:

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates:

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function:

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to:

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about its behavior:

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates:

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function:

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to:

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular

tag, you're it
Link
Dan
  • 3.8k
  • 24
  • 39
edited body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about it'sits behavior.:

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates.:

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function.:

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to:

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about it's behavior.

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates.

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function.

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular

I have a function below that does the following uses a bunch of smaller CRUD operations which I call create, retrieve (instead of read), update, delete. Because this function does a bit of everything it can be hard to name it.

Here's a bit about its behavior:

  • pass in array of redirects (objects with url, and path properties)
  • retrieves all existing redirects
  • checks to see if requesting redirect path exists
  • if existing redirect with path exists and url is the same returns existing
  • if existing redirect with path exists updates redirect
  • if existing redirect with path does not exist creates new redirect

Here are some possible candidates:

  • retrieveAllRedirectsUpdateExistingRedirectsCreateNewRedirectsDoNothingForRedirectsWithNoChange
  • retrieveAllUpdateExistingCreateNewRedirects
  • retrieveUpdateCreateRedirects
  • ensureRedirectsExist
  • ensureRedirects
  • overwriteRedirects // implies will delete redirects not passed to it
  • createRedirects
  • redirects

Here's the function:

Shopify.prototype.ensureRedirects = function(redirects){
 return this.retrieveAllRedirects().then(function(existingRedirects){
 return Promise.map(redirects, function(redirect){
 return Promise.resolve(existingRedirects).then(_).call("findWhere", {
 "path": redirect.path,
 }).then(function(match){
 if(match && match.url == redirect.url) return match
 if(match) return this.updateRedirect(match.id, redirect)
 return this.createRedirect(redirect)
 }.bind(this))
 }.bind(this))
 }.bind(this))
}

What naming convention lends itself to the most flexibility and follows the best pattern?

Other functions that I have in this library include but aren't limited to:

  • retrieveRedirects (paginated)
  • retrieveRedirectsCount
  • retrieveAllRedirects (all pages)
  • createRedirect
  • updateRedirect

This also begs the question should this function above be createRedirects as an alias of createRedirect that detects argument type object v.s. array and creates the redirects accordingly, making the createRedirect function more versatile to handle argument types? Then what do you name the function and argument? Convention for naming a function or variable as both plural and singular

added 258 characters in body
Source Link
ThomasReggi
  • 721
  • 2
  • 7
  • 13
Loading
added 273 characters in body
Source Link
ThomasReggi
  • 721
  • 2
  • 7
  • 13
Loading
Source Link
ThomasReggi
  • 721
  • 2
  • 7
  • 13
Loading
default

AltStyle によって変換されたページ (->オリジナル) /