Timeline for Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
Current License: CC BY-SA 4.0
27 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 16, 2018 at 6:02 | history | tweeted | twitter.com/StackSoftEng/status/1029971555558858752 | ||
| Aug 11, 2018 at 22:40 | comment | added | David Hammen | "Better" is a highly subjective word. That said, one can tell at a glance what the first version is doing. That the second version does exactly the same thing takes some scrutiny. | |
| Aug 11, 2018 at 15:28 | history | protected | gnat | ||
| Aug 11, 2018 at 8:19 | comment | added | philipxy | What "explicit invariant"? The test is not the invariant. What "post-condition"? | |
| Aug 11, 2018 at 8:17 | answer | added | cmaster - reinstate monica | timeline score: 2 | |
| Aug 11, 2018 at 6:32 | comment | added | Thorbjørn Ravn Andersen | You may want to find the book and reread it now to see what it actually said. | |
| Aug 11, 2018 at 4:57 | comment | added | nick012000 | Note that both of these code styles potentially leave your code open to timing attacks, if you're using it in a context where computer security is important. A better way of doing it would be something like boolean flag = false, then in your for-each loop set the flag to true if a match is found, then return the value of the flag after the loop is complete. | |
| Aug 10, 2018 at 22:36 | history | edited | Danila Piatov | CC BY-SA 4.0 | added 133 characters in body |
| Aug 10, 2018 at 22:11 | answer | added | Kevin | timeline score: 2 | |
| Aug 10, 2018 at 20:43 | answer | added | PMar | timeline score: -2 | |
| Aug 10, 2018 at 20:17 | comment | added | Berin Loritsch | I know those are examples, but there are languages that have APIs to handle exactly that use case. I.e. collection.contains(foo) | |
| Aug 10, 2018 at 18:46 | vote | accept | Danila Piatov | ||
| Aug 10, 2018 at 17:16 | answer | added | null | timeline score: 9 | |
| Aug 10, 2018 at 16:49 | history | edited | Danila Piatov | CC BY-SA 4.0 | added 52 characters in body |
| Aug 10, 2018 at 16:43 | history | edited | Danila Piatov | CC BY-SA 4.0 | edited title |
| Aug 10, 2018 at 16:37 | history | edited | Danila Piatov | CC BY-SA 4.0 | deleted 137 characters in body |
| Aug 10, 2018 at 16:37 | answer | added | Nathanael | timeline score: 19 | |
| Aug 10, 2018 at 16:36 | history | edited | Danila Piatov | CC BY-SA 4.0 | added 1841 characters in body |
| Aug 10, 2018 at 16:35 | history | edited | Deduplicator | CC BY-SA 4.0 | fixed code to follow text |
| Aug 10, 2018 at 16:28 | history | edited | Deduplicator | CC BY-SA 4.0 | added syntax-highlighting |
| Aug 10, 2018 at 16:19 | history | edited | Danila Piatov | CC BY-SA 4.0 | added 209 characters in body |
| Aug 10, 2018 at 15:45 | comment | added | gnat | Possible duplicate of Should methods always return from one place? | |
| Aug 10, 2018 at 15:40 | review | Close votes | |||
| Aug 17, 2018 at 3:06 | |||||
| Aug 10, 2018 at 15:38 | comment | added | Erik Eidt | The code examples cited here mix several different issues. Early & multiple returns (which for me go to the size of the method (not shown)), array search (which begs for a discussion involving lambdas), foreach vs. direct indexing... This question would be more clear and easier to answer if it focused on just one of these issues at a time. | |
| Aug 10, 2018 at 15:31 | answer | added | Lewis Pringle | timeline score: 56 | |
| Aug 10, 2018 at 15:10 | review | First posts | |||
| Aug 10, 2018 at 15:24 | |||||
| Aug 10, 2018 at 15:08 | history | asked | Danila Piatov | CC BY-SA 4.0 |