Timeline for Is it acceptable to copy and paste long but straightforward code instead of wrapping them into a class or function?
Current License: CC BY-SA 3.0
27 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 13, 2016 at 15:11 | audit | Suggested edits | |||
Feb 13, 2016 at 15:12 | |||||
Feb 9, 2016 at 9:36 | history | unprotected | yannis | ||
Jan 26, 2016 at 18:22 | comment | added | Josh Rumbut | If putting a code block into a method is a burden to you, it is a sign that you need more practice with the language, and to study it's rules so that issues of scope, passing by value/reference, etc are second nature. Beyond that, a good rule of thumb is to aim for 5 or less statements per method, to become very skeptical at 10-15, and to refactor almost always above 20. | |
Jan 26, 2016 at 9:09 | comment | added | Alessandro Teruzzi | which language is that? Doesn't look like java nor C#, it could be C++ but in that case you have a tons of memory leaks. | |
Jan 26, 2016 at 8:21 | comment | added | Laurent LA RIZZA | Everything is acceptable as soon as someone is ready to accept it. On my project, any project of mine, I would not accept it from anyone. There are at least 3 intermingled responsibilities in this code : requesting, handling errors, and displaying errors. At least three functions need to be extracted from this code, and that does not take into account "wrapping [the whole thing] in a function" (which does not "reduce the dependency of code". Dependencies are transitive.) | |
Jan 26, 2016 at 7:37 | comment | added | Tulains Córdova | It's frown upon in formal luncheons. | |
Jan 26, 2016 at 6:46 | history | protected | gnat | ||
Jan 26, 2016 at 1:26 | comment | added | rhughes |
You can pass "(some domain .com)" in as a parameter and then make the code reusable.
|
|
Jan 25, 2016 at 22:32 | comment | added | Criticizing Israel not allowed | Suppose you want to change something about this code later. Are you likely to want to change all instances of it together, or each one separately? If the change is likely to apply to all instances then you should wrap it in a function (to make global changes easy). If instances are likely to evolve separately then you should not wrap it in a function. | |
Jan 25, 2016 at 19:48 | answer | added | supercat | timeline score: -1 | |
Jan 25, 2016 at 18:47 | comment | added | Hagen von Eitzen | I it is really sooo common to use alerts in white 30px font in the middle of the screen, there'd be a standard function for that. Then again, I've been rereading your code again and again and cannot figure out why it is so important that in one ase FontColor is set before Position and in one case the other way round; there must surely be something deep hidden in the difference ... See? Repetition (esp. almost-repetition) can even make the code harder to read | |
Jan 25, 2016 at 17:51 | answer | added | coteyr | timeline score: 6 | |
Jan 25, 2016 at 16:18 | answer | added | JeffO | timeline score: 0 | |
Jan 25, 2016 at 16:12 | comment | added | Karl Gjertsen | I think everyone here seems to think this is a bad idea. But to turn the question around, why would you NOT put this code in a separate class or function? | |
Jan 25, 2016 at 15:31 | comment | added | Patrick Roberts | The fact you even feel obligated to ask is already a sign that you shouldn't. | |
Jan 25, 2016 at 14:38 | comment | added | MonkeyZeus | And along comes the supervisor that says "This alert box in the middle of my screen is an absolute terror. I am watching cat jifs and the pop-up is blocking my view every time it shows up. Please move it to the upper-right." 3 weeks later "What the heck did you do?! I can no longer close my cat jifs because YOUR pop-up is covering the X in the upper-right, fix it." | |
Jan 25, 2016 at 13:30 | comment | added | nhgrif | No. Never. Entirely unacceptable. If you were on my project, you would no longer be on my project and you'd be on a training program or PIP. | |
Jan 25, 2016 at 12:39 | answer | added | Phill W. | timeline score: 18 | |
Jan 25, 2016 at 11:33 | comment | added | sleske | And BTW, mixing networking and error display in one place is already a big no-no, IMHO. | |
Jan 25, 2016 at 10:56 | answer | added | My1 | timeline score: 0 | |
Jan 25, 2016 at 10:45 | comment | added | Thorbjørn Ravn Andersen | What does "acceptable" imply? Being able to get away with it? | |
Jan 25, 2016 at 10:31 | comment | added | Sebastian Redl |
Imagine you have a bug in that code, such as not freeing objects you allocate. (Does your framework free the Alert objects?) Now imagine you have to find every copied instance of this code to fix the bug. Now imagine it's not you who has to do it, but a crazy axe murderer who knows you were the one who created all these copies in the first place.
|
|
Jan 25, 2016 at 9:13 | answer | added | gnasher729 | timeline score: 8 | |
Jan 25, 2016 at 8:36 | history | tweeted | twitter.com/StackProgrammer/status/691540236178972673 | ||
Jan 25, 2016 at 5:44 | answer | added | user949300 | timeline score: 54 | |
Jan 25, 2016 at 4:15 | answer | added | Vaughn Cato | timeline score: 87 | |
Jan 25, 2016 at 4:07 | history | asked | ggrr | CC BY-SA 3.0 |