You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- 3Wh do you think that rearrangement is for optimizing the running code instead of minimizing the source? All else being equal, shorter code is easier to comprehend because there's less of it.Deduplicator– Deduplicator2017-08-18 20:24:01 +00:00Commented Aug 18, 2017 at 20:24
- 1@Deduplicator I can't agree with shorter code being easier to comprehend. I've edited my answer to propose a C++ solution (OP accepts any language) using function pointers, but it could be implemented in any language that supports lambda functions. The source is shorter, but the generated code will be slower, and the human mind will have to think twice to follow a logic that was very natural in OP's initial code. ;-)Christophe– Christophe2017-08-18 21:09:22 +00:00Commented Aug 18, 2017 at 21:09
- 1Well, "all else being equal". Naturally, that condition does not always apply.Deduplicator– Deduplicator2017-08-18 22:06:21 +00:00Commented Aug 18, 2017 at 22:06
- "Don't diddle code to make it faster; find a better algorithm." This quote makes no sense to me. For one thing, I'm already trying to find a better algorithm. Also, where is the line drawn between diddling code to make it faster and finding a better algorithm? There doesn't seem to be a clear distinction.Kyle Delaney– Kyle Delaney2017-08-20 23:09:40 +00:00Commented Aug 20, 2017 at 23:09
- @KyleDelaney didling code is to change for find small optimisations in order to gain to gain a couple of ms here and there but without changing fundamentally the approach. Finding a better algorithm consist of using a different approach to solve the problem. I agree that your approach is somewhat btw the two, I can remove this quote if it upsets you.Christophe– Christophe2017-08-20 23:24:10 +00:00Commented Aug 20, 2017 at 23:24
| Show 2 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you