Timeline for How to write correct loops?
Current License: CC BY-SA 3.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 7, 2017 at 11:04 | comment | added | RubberDuck | Map -> Reduce FTW +1 | |
| Apr 19, 2016 at 12:11 | comment | added | Jared Smith | @MichaelKjörling I wasn't necessarily talking about LINQ and I kinda fail to see your point. forEach, map, LazyIterator, etc. are provided by the language's compiler or runtime environment and are arguably less likely to be walking back to the paint bucket on each iteration. That, readability, and off-by-one errors are the two reasons those features were added to modern languages. | |
| Apr 18, 2016 at 19:49 | comment | added | Arseni Mourzenko | @MichaelKjörling: when you use LINQ, the loop is there, but a for(;;) construct wouldn't be very descriptive of this loop. An important aspect is that LINQ (as well as list comprehensions in Python and similar elements in other languages) makes boundary conditions mostly irrelevant, at least within the scope of the original question. However, I can't agree more about the need to understand what happens under the hood when using LINQ, especially when it comes to lazy evaluation. | |
| Apr 18, 2016 at 19:38 | comment | added | user | @JaredSmith Once the computer actually executes that code, how much do you want to bet there is no jump instruction in there? By using LINQ you are abstracting away the loop, but it's still there. I've explained this to coworkers who failed to learn about the hard work of Shlemiel the painter. Failing to understand where loops occur, even if they are abstracted away in the code and the code is significantly more readable as a result, almost invariably leads to performance issues that one will be at a loss to explain, let alone fix. | |
| Apr 18, 2016 at 11:37 | comment | added | Luaan | @JaredSmith Everybody got used to the elephant. Only the newcomers think it's something weird, and they get used to it quickly as well. COBOL is still alive :P | |
| Apr 18, 2016 at 1:10 | comment | added | Jared Smith | Thank you for being the one to mention the elephant in the room: not using loops at all. Why people still code like its 1985 (and I'm being generous) is beyond me. BOCTAOE. | |
| Apr 17, 2016 at 8:52 | comment | added | Arseni Mourzenko | Well, from your original question, I have an impression that the choice is on one hand using TDD and getting the correct solution, and on the other hand skipping the test part and getting the boundary conditions wrong. | |
| Apr 17, 2016 at 8:49 | comment | added | CodeYogi | Yes, I do TDD but sometimes I just get into the trap of hit and try and finally I am able to get to the correct solution but with the cost of time and negative feedback to the interviewer. Don't you think generic proof/thought on loop correctness would be a good heuristic while doing TDD? | |
| Apr 17, 2016 at 8:39 | comment | added | Arseni Mourzenko | @CodeYogi: don't you think the interviewer would be delighted to learn that you know TDD? So why wouldn't you show that during an interview? | |
| Apr 17, 2016 at 8:37 | history | edited | Arseni Mourzenko | CC BY-SA 3.0 | added 1542 characters in body |
| Apr 17, 2016 at 8:37 | comment | added | Philip Kendall | Unit tests are universal. | |
| Apr 17, 2016 at 8:28 | comment | added | CodeYogi | what is I am bound to use a particular language? for example in an interview? | |
| Apr 17, 2016 at 8:25 | history | answered | Arseni Mourzenko | CC BY-SA 3.0 |