|
Do you honestly not see how a loop could replace that massive tangled mess of ifs? I did not say it was a good idea, just that was a trivial one. One that even a newbie could grasp. Not a good idea. A simple one.Broken Knees Club posted:Yes? You can collapse all of those ifs into a loop and have it do the same thing. Obviously it's the Wrong Way but it should be obvious even for a total newbie.
|
# ? Nov 8, 2009 23:46 |
|
|
# ? May 14, 2024 18:14 |
|
Broken Knees Club posted:Do you honestly not see how a loop could replace that massive tangled mess of ifs? I did not say it was a good idea, just that was a trivial one. One that even a newbie could grasp. Not a good idea. A simple one. I get that you could loop over all the rows and columns and test each one to see if the cursor is in it. That's not what's confusing me. What's confusing me is you saying that it's the first thing that should occur to someone reading the code, and then turning around and saying that it's a bad idea, but it would still somehow be simpler. Reducing the number of lines of code does not automatically make the code simpler to reason about, newbie or not. mr_jim fucked around with this message at 00:22 on Nov 9, 2009 |
# ? Nov 9, 2009 00:17 |
|
As I've said, highlighted and underlined, that comment was directed at newbies. People who are not confident enough to do things the Right Way. Do you understand why a newbie may be better off writing a convoluted loop rather than 200 if statements? It's not about reducing the amount of keystrokes per function, its about developing logical approaches to problems and yes, that means writing loops in places where they don't belong. I don't know if you also missed this bit, but I wasn't suggesting that anyone should use a loop in that case. I merely considered that to be code that screamed "do a loop here" to anyone even slightly familiar with flow control and that merely made it all the more horrifying. tl;dr: this is not about loops
|
# ? Nov 9, 2009 01:01 |
|
Broken Knees Club posted:I merely considered that to be code that screamed "do a loop here" to anyone even slightly familiar with flow control but not at all with basic arithmetic.
|
# ? Nov 9, 2009 01:39 |
|
Broken Knees Club posted:Do you honestly not see how a loop could replace that massive tangled mess of ifs? I did not say it was a good idea, just that was a trivial one. One that even a newbie could grasp. Not a good idea. A simple one. You talked poo poo when you were in no place to have done so and now you're back peddling. Let it go and in a few pages you can try again.
|
# ? Nov 9, 2009 01:42 |
|
geetee posted:You talked poo poo when you were in no place to have done so and now you're back peddling. Well CoC is a pretty good place for a back peddler, I think a lot of people here have back problems and would like to buy a new one
|
# ? Nov 9, 2009 01:48 |
|
Painless posted:Well CoC is a pretty good place for a back peddler, I think a lot of people here have back problems and would like to buy a new one geetee fucked around with this message at 23:43 on May 15, 2011 |
# ? Nov 9, 2009 01:58 |
|
ZorbaTHut posted:I pray to God that it did not, but honestly it was more blackboxy than that. You just said "optimize for X seconds!" and sometimes it did. My current job involves lots of code originating from Japan. I have had this window open for two minutes trying to describe it, but I just can't... I think the engineers there are just prohibited from telling their manager that a given methodology is a horrible idea, so you get this code written around fundamentally flawed ideas dictated by someone who hasn't touched a compiler in ten years. "Optimize for X seconds [in wall time]" fits this style of engineering to a T. Like, a manager probably told someone that they could guarantee that the compile process will be [this] fast, and that was the only place they could think of to put a throttle to get it under the mark. Edit: My best/worst "what the gently caress are the japanese smoking" story is the program that required LESS than 4GB of physical RAM to run. This is because it used the delay from paging out to swap to throttle a particular thread. I have been mulling it over for a year and still can't figure even a possible reasoning for this behavior to exist. It isn't even unintentional - there's a check to make sure that pages/sec had passed a certain amount before the thread resumes. xarph fucked around with this message at 02:15 on Nov 9, 2009 |
# ? Nov 9, 2009 02:03 |
|
xarph posted:Edit: My best/worst "what the gently caress are the japanese smoking" story is the program that required LESS than 4GB of physical RAM to run. This is because it used the delay from paging out to swap to throttle a particular thread. I have been mulling it over for a year and still can't figure even a possible reasoning for this behavior to exist. It isn't even unintentional - there's a check to make sure that pages/sec had passed a certain amount before the thread resumes. Please post more details about insane Japanese software, because this post right here is incredible.
|
# ? Nov 9, 2009 03:06 |
|
code:
|
# ? Nov 9, 2009 16:10 |
|
geetee posted:You talked poo poo when you were in no place to have done so and now you're back peddling. Let it go and in a few pages you can try again. No, really, I'm not. Look at this code again for a second: code:
|
# ? Nov 9, 2009 17:21 |
|
Please god no more. Make it stop.
|
# ? Nov 9, 2009 20:45 |
|
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.
|
# ? Nov 9, 2009 20:56 |
|
Janin posted:Please post more details about insane Japanese software, because this post right here is incredible. Ruby.
|
# ? Nov 9, 2009 21:29 |
|
Tell me more.
|
# ? Nov 9, 2009 21:37 |
|
Incoherence posted: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. For what its worth I think what he's trying to say is a loop would be slightly less wtf worthy than writing 500 if statements despite still being wrong. But that's me being a devil's advocate.
|
# ? Nov 9, 2009 21:54 |
|
Shavnir posted:For what its worth I think what he's trying to say is a loop would be slightly less wtf worthy than writing 500 if statements despite still being wrong. I understood it this way too. I'm chalking the ensuing clusterfuck up to people wanting to feel smart, and not reading what he actually wrote.
|
# ? Nov 9, 2009 22:05 |
|
ErIog posted:I understood it this way too. I'm chalking the ensuing clusterfuck up to people wanting to feel smart, and not reading what he actually wrote. God forbid anyone point out coding horrors in the coding horror thread!
|
# ? Nov 9, 2009 22:34 |
|
floWenoL posted:God forbid anyone point out coding horrors in the coding horror thread! He was pointing out a human horror, that goes in the other thread. The one on page twelve or whatever.
|
# ? Nov 9, 2009 22:47 |
|
code:
|
# ? Nov 10, 2009 00:14 |
|
I just figure you guys might get a laugh out of this. So Jasshelper developed by Vexorian is a compiler that adds extra features to the Jass language. It basically translates your more complicated code into Jass. He created a C like dialect called Zinc and one of its features is anonymous methods. As some natives, and some libraries use function callbacks, and sometimes you want to do something very simple. e.g. php:<? // an example of sane usage. ... forGroup(g,function() { BJDebugMsg(GetUnitName(GetEnumUnit())); }); ?> I decided to implement the Y combinator in anonymous methods. Now they don't support closures [yet], so I had to hack it together by using a hashtable but here goes. php:<? library anony { hashtable closure = InitHashtable(); type func_int_int extends function(integer)->integer; type Ucombinator extends function(Ucombinator)->func_int_int; type Yarg extends function(func_int_int)->func_int_int; type Ycombinator extends function(Yarg)->func_int_int; function U(Ucombinator f)->func_int_int { return f.evaluate(f); } function test() { //return U(r => a => f(r(r))(a)); Ycombinator Y = function(Yarg f)-> func_int_int { SaveInteger(closure,1,0,integer(f)); return U(function(Ucombinator r)-> func_int_int { SaveInteger(closure,1,1,integer(r)); return function(integer a)->integer { Yarg f =LoadInteger(closure,1,0); Ucombinator r = LoadInteger(closure,1,1); return f.evaluate(U(r)).evaluate(a); }; }); }; func_int_int factorial = Y.evaluate(function(Yarg f)->func_int_int { SaveInteger(closure,0,0,integer(f)); return function(integer n)->integer { func_int_int f = LoadInteger(closure,0,0); if(n == 0) return 1; return n*f.evaluate(n-1); }; }); BJDebugMsg(I2S(factorial.evaluate(5))); } function onInit() { test(); } } ?>
|
# ? Nov 10, 2009 01:56 |
|
Shavnir posted:For what its worth I think what he's trying to say is a loop would be slightly less wtf worthy than writing 500 if statements despite still being wrong. I read it the same way... that manual setting of i = <next value> looks like an unrolled loop. Ignoring the underlying algorithm, it screams "loop da loop"
|
# ? Nov 10, 2009 01:57 |
|
weaaddar posted:I just figure you guys might get a laugh out of this. It's just a Y combinator, a useful utility function found in any real programming language. Where's the horror in that?
|
# ? Nov 10, 2009 01:59 |
|
ErIog posted:I understood it this way too. I'm chalking the ensuing clusterfuck up to people wanting to feel smart, and not reading what he actually wrote. i.e this entire thread
|
# ? Nov 10, 2009 02:25 |
|
The worst coding horror I've experienced is working with someone so good that you know you'll never be that good, and that someday you'll be working somewhere that absolutely everyone (including me) will be terrible.
|
# ? Nov 10, 2009 04:26 |
|
shrughes posted:It's just a Y combinator, a useful utility function found in any real programming language. Where's the horror in that? Jass (the warcraft 3 scripting language) doesn't actually have function types, the actual produced code is probably some hideous monstrosity that looks nothing like the code I typed. Its just a complete abuse of syntactic sugar.
|
# ? Nov 10, 2009 04:42 |
|
weaaddar posted:Jass (the warcraft 3 scripting language) doesn't actually have function types Neither does machine code really, but that doesn't affect most people's opinion of the Y combinator in other languages.
|
# ? Nov 10, 2009 07:02 |
|
Vanadium posted:Tell me more. Well you see, Ruby was written by a chinaman, and they have a poor ability to write code.
|
# ? Nov 10, 2009 07:07 |
|
Markov Chain Chomp posted:Well you see, Ruby was written by a chinaman, and they have a poor ability to write code. At least Ruby's not a functional language, because it would be unable to distinguish between foldl and foldr!!
|
# ? Nov 10, 2009 07:09 |
|
Bozart posted:The worst coding horror I've experienced is working with someone so good that you know you'll never be that good, and that someday you'll be working somewhere that absolutely everyone (including me) will be terrible. I think the idea here is that you accept that there will always be those people who are totally insane. As long as you keep educating yourself then you're better than 90% of the dudes out there, and all you have to do is stay up to date, and keep trying to improve.
|
# ? Nov 10, 2009 08:58 |
|
Whelp, I found four instances of gets() yesterday. I think I've hit the bottom of my codebase's barrel. Similarly, I found two of these:code:
code:
|
# ? Nov 10, 2009 13:17 |
|
Mustach posted:So maybe there's a barrel underneath this barrel.
|
# ? Nov 10, 2009 15:23 |
|
Maybe there's a smaller barrel inside.
|
# ? Nov 10, 2009 21:28 |
|
Mikey-San posted:Maybe there's a smaller barrel inside. If there's one thing I've learned about bad code, it's that the inner barrel is invariably larger.
|
# ? Nov 11, 2009 01:54 |
|
My co-workers love the "delete one element at a time, clear after" pattern; I've found (and removed) no less than 10 versions of it. Several were written after I'd removed a few which were causing crashes. Every time I remove one, whoever wrote it is all "oh I never thought that could crash!". Somewhere there's an rear end in a top hat professor wondering how low he can drop standards before being fired, and every one of his students is working with me. A sample: code:
|
# ? Nov 11, 2009 03:50 |
|
Janin posted:
You do realize this is not only legit, but required to avoid a leak? (Unless there's some other behavior in UnregisterChild that breaks things). Avenging Dentist fucked around with this message at 04:24 on Nov 11, 2009 |
# ? Nov 11, 2009 04:21 |
|
Yeah maybe I'm missing something but isn't it good practice to check if a pointer is null or not before you try to delete or free() it?
|
# ? Nov 11, 2009 04:24 |
|
BattleMaster posted:Yeah maybe I'm missing something but isn't it good practice to check if a pointer is null or not before you try to delete or free() it? No because delete checks for null before it does anything.
|
# ? Nov 11, 2009 04:24 |
|
Avenging Dentist posted:No because delete checks for null before it does anything. Oh I didn't know that because I'm a C person. Cool.
|
# ? Nov 11, 2009 04:25 |
|
|
# ? May 14, 2024 18:14 |
|
BattleMaster posted:Oh I didn't know that because I'm a C person. Cool. I've got bad news for you.
|
# ? Nov 11, 2009 04:26 |