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.
- 1I can make it shorter (in C and C-like languages): if ((expand ? life_max < max_value : life_max > max_value)) life_max = max_value. Not more readable obviously, so leave it as it is.gnasher729– gnasher7292021-08-20 13:19:04 +00:00Commented Aug 20, 2021 at 13:19
- 2@gnasher729 Sure, but “shorter” isn't necessarily “faster”, “simpler”, or “clearer”. I love code golfing as a sport but wouldn't tolerate it in production code (and I say this as someone who likes Perl).amon– amon2021-08-20 13:22:26 +00:00Commented Aug 20, 2021 at 13:22
- Spelling it out as you did, did the trick for me. I just have issues reading code like in my OP and it always leaves me puzzled because I'm trying to optimize or figure out a shortcut.Chibueze Opata– Chibueze Opata2021-08-20 13:42:05 +00:00Commented Aug 20, 2021 at 13:42
- 1@ChibuezeOpata focus that energy on readability. Measure readability by getting others to read your code.candied_orange– candied_orange2021-08-20 15:09:25 +00:00Commented Aug 20, 2021 at 15:09
- 3@ChibuezeOpata - don't think of it in terms of optimizing or finding some clever way to shorten it, rather, think in terms of how can you rewrite the code so that the reader can immediately tell what it's trying to accomplish. In your original code, and even in amon's first example, you have to mentally parse what the conditions are, what they mean, and infer why the developer wrote the code snippet in the first place, while in amon's second example you can pretty much read the intent right away: "Oh, if expand is set, then expand if necessary, otherwise shrink if necessary".Filip Milovanović– Filip Milovanović2021-08-20 21:18:55 +00:00Commented Aug 20, 2021 at 21:18
Add a comment |
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