Timeline for How to write correct loops?
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 20, 2016 at 11:35 | comment | added | James Snell | @Wildcard +1: "Show me the code" is, to me, an excellent indicator as to why this answer is right and that maybe I need to work on ways to better demonstrate that it's a human-factor / design problem that can only be addressed by changes in the human process - no amount of code could teach it. | |
| Apr 19, 2016 at 19:53 | comment | added | Wildcard | @CodeYogi, I think you may have confused this site with Stack Overflow. This site is the equivalent of a Q&A session at a whiteboard, not at a computer terminal. "Show me the code" is a pretty explicit indication that you are on the wrong site. | |
| Apr 18, 2016 at 7:08 | comment | added | CodeYogi | @JamesSnell I would be more then happy to see real examples now, show me the code. Let me know how to write a good quality testable insertion sort. No matter if its already implemented in some book. Telling something bad is not going to help others but showing it how to do may change the view point. | |
| Apr 17, 2016 at 21:05 | history | edited | James Snell | CC BY-SA 3.0 | Updated example from Java to JScript thanks to Jules' feedback. |
| Apr 17, 2016 at 20:58 | comment | added | James Snell | @CodeYogi - you have and as pointed out by others you have broken the problem into sub-problems rather poorly, which is why a number of answers mention your approach to solving the problem as the way to avoid it. It's not something you should take personally, just experience from those of us who have been there. | |
| Apr 17, 2016 at 20:46 | comment | added | James Snell | @Jules - the point was to illustrate that the languages offer ways to do what we need them to and it makes sense to investigate them rather than reinventing the wheel but I do take your point. In fact arraycopy would probably not be great either as we'd want to copy part of an array into itself which could have some fun consequences depending on the implementation, but that would be heading to chat territory. | |
| Apr 17, 2016 at 19:16 | comment | added | Jules | I think you mean System.arraycopy, not Arrays.copyOfRange. The code is for an in-place sort, but copyOfRange creates a new array. | |
| Apr 17, 2016 at 17:55 | comment | added | CodeYogi | I have already broken my problem into sub-problem. Actually the procedure mentioned above is not the original problem but a private helper function for InsertionSort hence I need no bound checking for that. | |
| Apr 17, 2016 at 15:24 | comment | added | James Snell | @BryceWagner - Absolutely true, but without a clear idea of what problem is that you're actually solving you're going to spend a lot of time thrashing about in the dark in a 'hit and hope' strategy which is by far the OP's biggest problem at this point. | |
| Apr 17, 2016 at 14:42 | comment | added | Bryce Wagner | Even if you're passing your indexes to an existing function (such as Array.Copy), it can still require thought to get bound conditions correct. Imagining what happens in a 0 length and 1 length and 2 length situations can be the best way to make sure you're not copying too few or too many. | |
| Apr 17, 2016 at 14:24 | history | answered | James Snell | CC BY-SA 3.0 |