Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Incoherence
May 22, 2004

POYO AND TEAR

floWenoL posted:

Because it's an archaic overreaction to spaghetti code. It should be used only when doing so would make the code most clearly understandable.
But at the same time, not using it ever is an overreaction. If it makes sense, use it. If it doesn't, don't use it.

dwazegek posted:

the "retVal" variable (it always seems to be named that way)
Personally when I write a IsFooCondition() that calls for such a variable, I feel stupid calling the variable some variant of isFooCondition.

Incoherence fucked around with this message at 01:51 on Mar 22, 2008

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

tef posted:

See, where you might use "result" I would use bln_flg_tst_cnd_args_x.
And CoC has its first in-joke.

Incoherence
May 22, 2004

POYO AND TEAR

pokeyman posted:

Found this in the PHP manual. It's like the guy knew he wanted some kind of conditional execution, but forgot about the "if" keyword.
:psyduck:

Okay, that's a pretty good one. I'm surprised that works at all.

Incoherence
May 22, 2004

POYO AND TEAR

admiraldennis posted:

I'm a CS student (actually IS but its very similar here), and our first freshman programming class is taught entirely in scheme. Coursework was fairly demanding and topics included natural recursion (for everything), functional programming, lambda programming, etc. Iterative recursion (for loops, etc) aren't even mentioned until halfway through the second semester, in which Java is used to teach object-oriented design, abstraction, encapsulation, inheritance, polymorphism, and so forth.

Neither course focused on syntax or a practical overview of either language. There are other courses for that. These classes were literally How to Design Programs (Functions) and How to Design Classes, and that's what was emphasized.

I'm very happy with the CS program here (Northeastern) so far. I know I've become a much better programmer because of it.
Sounds like the program I came through. If it's anything like mine, one of the main things you should get out of it is a fine bullshit filter around the application of Java design patterns.

But... uh... !false definitely qualifies as a Coding Horror. I can at least fathom why someone would write if (true), but not !false.

Incoherence
May 22, 2004

POYO AND TEAR

MEAT TREAT posted:

:aaaaa:
Wow this is so simple that it never occurred to me. I always thought ++i was a matter of style. Is it safe to assume that modern compilers do this automatically now? Except in the case of the iterator you mentioned.
It's possible that a present-day compiler could optimize for (int i = 0; ...; i++) into ++i, but probably not any sort of class (the previously mentioned example where some rear end in a top hat defines operator++() and operator++(int) to do different things).

Incoherence
May 22, 2004

POYO AND TEAR

wolf_man posted:

my thinking is, if your not able to read my code, or at least figure it out, then you shouldnt be looking at it in the first place
This is the kind of statement that allows people to justify all the stupid "I'm so clever" tricks. Yes, I COULD figure it out, but it will take me longer than if you'd just spent the 5 seconds to adhere to a decent coding standard in the first place.

Incoherence
May 22, 2004

POYO AND TEAR

bcrules82 posted:

rather than have an equals method why not just overload operator== ?
i see this sort of avoidance by old 'C' engineers all the time :)
I believe the answer you're looking for is "Java".

Incoherence
May 22, 2004

POYO AND TEAR

Entheogen posted:

this is kinda lengthy but bear with me.

So here is 250-point Division 2 problem from TopCoder SRM
Programming contest solutions tend not to be known for their elegance.

Incoherence
May 22, 2004

POYO AND TEAR

Sebbe posted:

I think I'll start using roman numerals as names for nested loop variables in the future.
Another way to make people crazy: if you ever have an opportunity to write a 4-level nested loop, use the variables i, ii, iii, and iiii.

The real WTF is, of course, the fact that you're writing a 4-level nested loop, but that's another story.

Incoherence
May 22, 2004

POYO AND TEAR

Plorkyeran posted:

Lines 6921-6934 of a 10458 line function:

:barf:
To be fair, the thing this is apparently trying to model is the following flowchart:
http://www.unbearably.net/blogfiles/simplecatdps.jpg

Incoherence
May 22, 2004

POYO AND TEAR

Seth Turtle posted:

Using an else-if in this situation is wise. You don't want to match FALSE and TRUE simultaneously. And you've gotta save that ending 'else' for the third option that's sure to come up later on in development.
Clearly the third option is FileNotFound.

Incoherence
May 22, 2004

POYO AND TEAR

Flobbster posted:

I'd love it if you could track down what that bug was, because weird compiler bugs have always fascinated me.

A few years ago I was the TA for one of our C++ courses, and when it came time to grade students' projects, I would compile and run their code and occasionally it would crash with "SIGILL: illegal instruction". Thinking they were doing something like blowing the stack, I pulled up gdb but it was actually g++ generating an incorrect CALL instruction. Instead of the correct destination address, it was basically generating "CALL (address of this instruction + 1)", which of course would never be correct.

Sadly I was never able to figure out how to duplicate it reliably. Sometimes forcing -O0 would fix it, but then on another student's code it would be broken under -O0 but -O3 would work instead.
The only time I've ever seen a SIGILL was a situation where I managed to compile something whose dependencies included two classes with the same name, and somehow the linker got sufficiently confused that rather than, I don't know, complaining that there were two classes with the same name, or combining them sensibly, it decided to merge the two together into a single vtable that was missing several methods from each, so that when I called one of the missing methods the program of course crashed.

I would love for someone to explain to me (slowly) just why that happened and why the person who finally figured this out gave me the impression that this behavior wasn't a bug.

Incoherence
May 22, 2004

POYO AND TEAR

Broken Knees Club posted:

I see this as iteration done manually with a ton of ifs. My comment was aimed at the fact that this was manual iteration that could be replaced with a loop. I was not talking about the function of this horrifying code, which doesn't need a loop, but the structure. If you got some other meaning from my posts, then I'm probably a bad poster but I did not backpedal or mean anything other that what I said.
A loop would be just as WTF-worthy as that code snippet. That's why people are making GBS threads on you: you're suggesting "optimizing" one WTF into another.

Incoherence
May 22, 2004

POYO AND TEAR

Scaramouche posted:

I found something of my own that's a small h horror but still resulted in head slapping from me. It was a quick little log viewer app that I whipped up in a couple minutes a few years ago:
code:
If Thing = 'blah' then
   'Do nothing
Else if Thing = 'blah blah'
   'Do nothing
Else
   'Do something
End If
Nothing like testing for conditions that don't have to be handled first...
I've done the "if X, do nothing, else do something" pattern before when the condition was sufficiently painful to look at that I didn't want to deal with inverting it. The else if is a bit interesting, though.

Incoherence
May 22, 2004

POYO AND TEAR

HappyHippo posted:

In that case why not simply do "if !X, do something"? There's no need to figure out how to invert it if you just wrap it up in brackets and throw a negation on the front.
Because it's usually something like
code:
if (!(a && b) || c || d) {
  // do nothing
} else {
  // do something
}
(imagine a, b, c, and d are relatively long as well) and just leaving it that way is easier to parse than wrapping the whole thing in a !() and trying to figure out what it means in six months.

Incoherence
May 22, 2004

POYO AND TEAR

plushpuffin posted:

Hoping this was intentional :)
It's an old joke, yes.

Incoherence
May 22, 2004

POYO AND TEAR

Tux Racer posted:

Does blatant plagiarism count?
This is more a coder horror than a coding horror, but we had something fun happen in one of my freshman CS classes. We had take-home exams, because doing a CS exam in a lecture hall on paper is really dumb and just means the graders have to figure out exactly how many syntax errors we let you make before we decide you actually don't know how to program (I ended up TAing the same class afterward).

After the second exam, the professor mentioned in class that someone had posted the exam on Rent-A-Coder, and that someone had told him about it. I can sort of see this: someone really desperate to get a good grade, and doesn't expect the professor to be watching those sites for the exam to show up.

The professor dithers on the final for awhile after this, but finally decides to make it a take-home exam as well. One day, I check the course webpage and there's a news update: the same username has posted the final on the same site. The next day, another update: some other user has accepted the job. The afternoon the exam was due, though, the other user withdrew, saying it was "unethical". I sort of wonder how much of a hand the professors had in this.

Incoherence
May 22, 2004

POYO AND TEAR

rt4 posted:

Store an integer containing cents; doubles are just big floats.
[insert Office Space plot summary here]

Incoherence
May 22, 2004

POYO AND TEAR

Randel Candygram posted:

Do you often ship code detailing your meat-vomiting habits?
http://www.vidarholen.net/contents/wordcount/

Incoherence
May 22, 2004

POYO AND TEAR

BonzoESC posted:

. accepts any character, * is a Kleene star closure, your automata theory textbook should cover all this.
And then you read your automata theory textbook a little more closely and discover that regexps in the sense that most languages use them do not fit under the formal definition of "regular expressions". So... maybe that's not such a good idea.

Incoherence
May 22, 2004

POYO AND TEAR

defmacro posted:

The formal definitions offer great approximations of how they're used in practice. You learn about what, lazy/greedy matches and backreferences and you're all set? Do you honestly think understanding formal languages will somehow make it harder to learn regular expressions?
I was reacting to the implication that if you'd just read an automata textbook, you'd understand PCRE. You might know what some of the symbols mean, but you'd have an inadequate understanding of the power of a "modern regex implementation" because the things you mentioned aren't "regular expressions" in the formal sense. Imagine if you played a game of chess without knowing what the knight did, or even knowing that it existed.

Incoherence
May 22, 2004

POYO AND TEAR

Factor Mystic posted:

I have discovered exactly one useful case for an empty exception handler: on Windows when you attempt to launch a process with elevated privileges (such as, relaunching yourself from standard user -> admin with some state parameters) and the user hits cancel, the C# process class throws an exception. But it's very possible you don't want to do anything if they hit cancel. So just swallow.
I don't think that was quite what that post meant, but the obvious example of an empty catch statement is unit testing a method that's supposed to throw an exception.
code:
try {
  doSomething(...);
  fail("Did not throw BogusInputException");
} catch (BogusInputException e) {
  // this is supposed to happen
}
It's when you swallow EVERY exception for the whole program that you start having problems.

Incoherence
May 22, 2004

POYO AND TEAR

Janin posted:

from a while back, but:

This is a coding horror, because you're not verifying the contents of the exception. How do you know the correct BogusInputException was thrown, and that it was constructed with the correct values?
This seems like a great way to make brittle and overly coupled tests, personally. It's one thing if you're catching Exception and not looking at it, but if I'm testing something with a contract that it will throw a specific exception type when the input is bogus, all the unit test should care about is that when the input is bogus it does in fact throw that exception, not that the exception message says exactly "foo must be odd in doSomething; was 42".

Incoherence
May 22, 2004

POYO AND TEAR

enthe0s posted:

I'm only into my 3rd year of programming, but my college teaches us to not use multiple return statements and instead create a single variable at the top and return it at the end. Why exactly, I'm not sure, but I hear it's good form.
As usual, this is sort of a good idea in theory (it keeps you from forgetting to clean up after yourself before returning in languages/situations where that matters, at the possible cost of making your logic harder to follow), but eventually everyone just sort of forgets the tradeoff part of it and it gets upgraded into a Law of Programming.

Incoherence
May 22, 2004

POYO AND TEAR

MEAT TREAT posted:

code:
DefaultMessageHandlerFactoryImpl
:wtc: Java
It's not enterprisey enough until you have a FactoryFactory somewhere.

Incoherence
May 22, 2004

POYO AND TEAR

HORATIO HORNBLOWER posted:

Likewise, I walked into my "intro to CS" class with years of experience with C, whereas my classmates wouldn't have been able to mash out a "hello, world" program if you put a gun to their heads and a copy of K&R in their hands.
This discrepancy is one of the several hard problems in teaching introductory CS in college, because somehow you have to make the hotshots pay attention to the instruction, and at the same time you have to bring the people who are relative newbies up to a reasonable level.

This is, I'm convinced, part of the reason why Scheme became so popular for introductory course sequences: odds are good that the hotshots who have been programming since they can walk don't know Scheme, and odds are at least decent that they aren't familiar with functional programming.

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

OddObserver posted:

That people just starting out would have lots of difficulty getting it.
I'm convinced that the only reason people think recursion is hard is because everyone tells them recursion is hard.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply