Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to eliminate repetitive code. #783

Merged
merged 1 commit into from
Oct 7, 2020
Merged

Refactor to eliminate repetitive code. #783

merged 1 commit into from
Oct 7, 2020

Conversation

mikecasas
Copy link
Contributor

Simple improvement to keep the code DRY.

@@ -173,13 +173,15 @@ public string CreateApiUrl(Alias alias, string serviceName)
// add entityid parameter to url for custom authorization policy
public string CreateAuthorizationPolicyUrl(string url, int entityId)
{
string qs = "entityid=" + entityId.ToString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

return url.Contains("?") ? "&" : "?" + "entityid=" + entityId.ToString(); 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go for the simple approach. I know what the code you pasted does, but IMO it's so complex for a one-liner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that complex ;) coz the first letter depends on whether the url contains query string or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both ways are fine for me. The boss indicated a preference for the longer form.
#155 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer inline condition in such case but if the condition is complex or has nested conditions I may prefer if block for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jimspillane I thought I had read that somewhere. Plus at this point I don't want to change a lot of the code, meaning if it's an 'if block', then I will leave it as an if block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This take too long for a tiny change ;) could you please give a meaningful name instead of qs and I'm fine with that

@sbwalker sbwalker merged commit fde43b6 into oqtane:master Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants