|
Wheany posted:It's a bunch of initialization functions that need all the previous functions to complete successfully. There is no point in send_http_request() if open_socket() has failed. And I really don't understand what 'testing "status" an unnecessary number of times' even means. Except that I probably could have used a goto after a failure. By "testing 'status' an unnecessary number of times," I mean that the first example has fall-through logic that is better represented in a series of nested "if" blocks rather than, "Did it die here? Did it die here? Did it die here?" checks. It still really falls into the category of personal taste when the question posed amounts to, "Which is the lesser of each of these evils?" I like your third option far better than the others, but if you have a set of functions closely associated with each other, wouldn't you rather group them in one call, and just test the result from that one call? Assuming the language is C, and each function returns OK, which equals 0, if no error has occurred: code:
EDIT: Even with preview post I still miss typos goddamn Mista _T fucked around with this message at 19:16 on Feb 28, 2010 |
# ? Feb 28, 2010 18:57 |
|
|
# ? Jun 5, 2024 04:09 |
|
RussianManiac really is hexadecimal, isn't he
|
# ? Feb 28, 2010 18:59 |
|
Wheany posted:That said, my third idea was having an array of function pointers, with the last array entry being NULL, then doing a Good lord, just use a real language with exception handling.
|
# ? Feb 28, 2010 19:07 |
|
To be perfectly honest, relying on exception handling rather than checking it that number isn't zero before you divide or that pointer isn't null before you dereference is the biggest coding horror of them all.
|
# ? Feb 28, 2010 19:12 |
|
markerstore posted:Good lord, just use a real language with exception handling. To Wheany's defense, there is no elegant way to iteratively call a series of functions without knowing the context of the task at hand, and Exception Handling merely causes a convenient break in control, and you would still have to do cleanup afterwards, if any. Unless you are being sarcastic, in that case: ITERATIVE PROGRAMMING IS SRS BIZNESS
|
# ? Feb 28, 2010 19:14 |
|
Mustach posted:RussianManiac really is hexadecimal, isn't he Who is this hexadecimal you all keep implying I am, which I am not? (USER WAS BANNED FOR THIS POST)
|
# ? Feb 28, 2010 19:25 |
Just a ridiculous piece of code to find out if a passed date came before today.quote:if ( (date.getMonth() == today.getMonth() && date.getDate() < today.getDate() && date.getFullYear() <= today.getFullYear()) || (date.getFullYear() < today.getFullYear()) || (date.getFullYear() <= today.getFullYear() && date.getMonth() < today.getMonth()) )
|
|
# ? Feb 28, 2010 19:33 |
|
Avenging Dentist posted:Congrats on being ignorant. lol defending macros quote:Who is this hexadecimal you all keep implying I am, which I am not?
|
# ? Feb 28, 2010 19:43 |
|
markerstore posted:Good lord, just use a real language with exception handling. I would if I could.
|
# ? Feb 28, 2010 19:59 |
|
Wheany posted:which is worse: Mista _T posted:
Wheany posted:
|
# ? Feb 28, 2010 20:12 |
|
Kelson posted:[All of the code snippets] I'm not even going to defend my code. It's all bad. Bad, bad, bad.
|
# ? Feb 28, 2010 20:19 |
|
Factor Mystic posted:lol defending macros If you think that macros are the problem, then you haven't really thought about what the issue is. It's not the existence of macros that is the problem, it's the non-existence of other important features (modules, inline functions*) that require fallback to macros. * Inline functions are available in C99, but people would rather use a 20 year old standard.
|
# ? Feb 28, 2010 21:24 |
|
Avenging Dentist posted:Labels are local to functions so this is wholly unnecessary. oh, and he even said "two loops in a function". welp, guess that's reading_comprehension--;
|
# ? Mar 1, 2010 00:06 |
|
Hi all! I saw a new code pattern today that I think has the potential to revolutionise the industry and I wanted to share it with you. I call it antipolymorphism. In general it looks like this:code:
|
# ? Mar 2, 2010 00:58 |
|
Contra Duck posted:Hi all! I saw a new code pattern today that I think has the potential to revolutionise the industry and I wanted to share it with you. I call it antipolymorphism. In general it looks like this: They are using an overloaded version of the base class within the class? that's all kinds of retarded.
|
# ? Mar 2, 2010 00:59 |
|
Contra Duck posted:Hi all! I saw a new code pattern today that I think has the potential to revolutionise the industry and I wanted to share it with you. I call it antipolymorphism. In general it looks like this: My god, it's almost beautiful. Was there anything in ClassB?
|
# ? Mar 2, 2010 01:07 |
|
This comes from a Java class I am currently taking. It's part of a program that simulates a bank account. The student in question posted this on the forum asking why the code wasn't passing the unit tester given to him by the professor.code:
Italian Stalin fucked around with this message at 08:14 on Mar 2, 2010 |
# ? Mar 2, 2010 08:08 |
|
armed2010 posted:This comes from a Java class I am currently taking. It's part of a program that simulates a bank account. The student in question posted this on the forum asking why the code wasn't passing the unit tester given to him by the professor. Gee, that's how it works? Nobody told me! I'm heading down to the bank right now to withdrawe £1,000,000 of monety immediately!
|
# ? Mar 2, 2010 10:20 |
|
Making fun of intro to programming "horrors" is kind of unsporting.
|
# ? Mar 2, 2010 10:40 |
|
MasterSlowPoke posted:Making fun of intro to programming "horrors" is kind of unsporting.
|
# ? Mar 2, 2010 11:03 |
|
Personally I'm willing to let this one in just for code:
|
# ? Mar 2, 2010 11:13 |
|
Dijkstracula posted:Indeed, I recall doing Contra Duck's antipolymorphism back in my first semester of CS. I think it's awfully low-hanging fruit unless it's absolutely hysterical I had my share of laughs back when I used to take first year CS classes at uni, but sadly my last example was from industry. Thank god for code reviews though!
|
# ? Mar 2, 2010 11:52 |
|
I think that example's funny because I'm sure that even if I had no experience of programming, I'd be able to look at it and think "else balance = balance + 0? What's the point of that?" Plus withdraweing monety and stuff I guess.
|
# ? Mar 2, 2010 13:14 |
|
To be fair, I've seen quite a few people write that sort of code in introductory programming classes; it's more of a sign that they don't really understand what they're writing than a horror, in my opinion. Usually the people writing these don't have illusions that what they're doing is right, as opposed to the real horrors, where they do.
|
# ? Mar 2, 2010 13:28 |
|
Sebbe posted:To be fair, I've seen quite a few people write that sort of code in introductory programming classes; it's more of a sign that they don't really understand what they're writing than a horror, in my opinion. This is something I was thinking about only yesterday, as I was doing some teaching for a first-year calculus course (I'm a postgrad and we're asked to give a certain amount of help teaching every semester). It's fairly basic stuff that all of the first-year mathematics students have to do, and so you can understand how some of them will find it boring and switch off. But you do come into contact with students who seem not to readily engage with the idea that they need to think critically about what they're doing. By this I mean that they often seem to be used to the idea that there is some algorithmic, rote method that they will be able to learn and apply dutifully to whatever problem they're presented with. To do mathematics at a higher level they need to try and have a real understanding of the ideas they're working with, but while the introductory courses we give try to instill this in them, I have the uncomfortable impression they often don't succeed. I'm talking about my discipline which is maths, but I can readily believe it applies to other technical disciplines too. I know you weren't criticising the student who wrote this, just observing that he didn't understand what he was writing. I tend to feel that while there is a value in "learning by doing", you shouldn't present a piece of work, purporting to be a genuine solution to a problem, in which you've written something you don't understand. I'm not sure in what way it is best to get students to understand that they really need to engage with the material they are learning, however. I'm rambling so I'll shut up now.
|
# ? Mar 2, 2010 14:01 |
|
Sometimes its the one liners that really get you.code:
|
# ? Mar 2, 2010 21:12 |
|
MasterSlowPoke posted:Making fun of intro to programming "horrors" is kind of unsporting. I want to agree with this, but the code armed2010 posted just shows a complete inability to think critically or reason through anything. Just read that deposit method aloud in plain English: "If the amount to deposit is greater than or equal to the current account balance, then add the amount to the current balance. Otherwise, add nothing to the balance." What is it about parentheses and curly braces that cause beginners to turn their brains off?
|
# ? Mar 2, 2010 21:18 |
|
MasterSlowPoke posted:Making fun of intro to programming "horrors" is kind of unsporting. For context, this is a person that was also with me in a much more difficult C language class during the previous semester where we were doing things far more complicated than this by this exact same time, and stayed the entire way through. I'm talking data structures, pointers, functions, etc. Based on the examples I've seen of his code such as this he must have failed the class outright, but you'd think that at least SOME of what the class taught would have rubbed off on him.
|
# ? Mar 2, 2010 21:22 |
|
code:
|
# ? Mar 2, 2010 22:15 |
|
sonic bed head posted:This is everywhere in my current project. I understand null checks when you're calling methods but this makes no sense. It's actually getting a little frustrating because the person who writes this is telling me that my code isn't null pointer safe because I don't check every single object I use. Can "new" in Java ever even return null? I would assume that in circumstances where that's a possibility (out of memory), you'd get shut down with the OutOfMemoryError instead before that statement had a chance to return.
|
# ? Mar 2, 2010 22:55 |
|
MasterSlowPoke posted:Making fun of intro to programming "horrors" is kind of unsporting. EDIT: vvvv I'm missing the reference Bhaal fucked around with this message at 23:15 on Mar 2, 2010 |
# ? Mar 2, 2010 22:55 |
|
Bhaal posted:There's no coding horror there. It compiles, it runs. Code is nicely laid out, names are clear and the functions do a very clean job of encapsulating a discrete set of operations. If there's a business logic bug in there somewhere, it'll be caught in testing, or customers can simply file a bug report. Hey Rob, didn't know you had an account here.
|
# ? Mar 2, 2010 23:09 |
|
Flobbster posted:Can "new" in Java ever even return null? I would assume that in circumstances where that's a possibility (out of memory), you'd get shut down with the OutOfMemoryError instead before that statement had a chance to return. This is correct. "new" in Java NEVER returns null. Even in lovely implementations of a JVM. My guess is that the guy is or used to be a C++ programmer (where "new" is basically malloc plus constructor).
|
# ? Mar 2, 2010 23:44 |
|
Mista _T posted:This is correct. "new" in Java NEVER returns null. Even in lovely implementations of a JVM. My guess is that the guy is or used to be a C++ programmer (where "new" is basically malloc plus constructor). Or it could be C# that can sometimes be null or default values.
|
# ? Mar 3, 2010 00:02 |
|
I'm seriously worried by the number of goons in this thread who cannot spot the fundamental flaws in that Bank Account coding horror.Bhaal posted:...If there's a business logic bug in there somewhere, it'll be caught in testing, or customers can simply file a bug report... This is probably the best troll in the history of man. Sprawl posted:Or it could be C# that can sometimes be null or default values. Directly calling .NET constructors will always return a non-null value. Also, silently logging and proceeding with execution flow on an unexpected null is not necessarily better than just having an exception thrown and letting it percolate up the stack and trapping it further up. e:I can't type. Milotic fucked around with this message at 00:33 on Mar 3, 2010 |
# ? Mar 3, 2010 00:31 |
|
Milotic posted:I'm seriously worried by the number of goons in this thread who cannot spot the fundamental flaws in that Bank Account coding horror. yea there is a huge logic flaw among other things its really bad code but like the guy said a class of into students that wouldn't know any better. code:
code:
|
# ? Mar 3, 2010 00:58 |
|
Mista _T posted:My guess is that the guy is or used to be a C++ programmer (where "new" is basically malloc plus constructor). It still never returns NULL, unless you turn off exceptions or do something crazy like that.
|
# ? Mar 3, 2010 01:04 |
|
Bhaal posted:or customers can simply file a bug report. Heh, yeah, it'll look like this code:
|
# ? Mar 3, 2010 01:17 |
|
Sprawl posted:
quote:
|
# ? Mar 3, 2010 01:19 |
|
|
# ? Jun 5, 2024 04:09 |
|
Sprawl posted:yea there is a huge logic flaw among other things its really bad code but like the guy said a class of into students that wouldn't know any better. To me it looks like someone who hasn't learned to break problems properly up into discrete steps. They know some of what they need, but don't think how to put them together properly through. It's looks a lot like some of the stuff I saw the first few weeks of being a programming intro instructor.
|
# ? Mar 3, 2010 01:37 |