|
Vanadium posted:I would consider keeping the maths out of the loop head Yes, that too. At first glance I missed that there was a loop hiding in there.
|
# ? Mar 25, 2010 23:38 |
|
|
# ? May 16, 2024 18:28 |
|
Whether you like OTBS or Allman or K&R or some other crappy style, for the love of all that is holy USE BRACES. Fixed late last year:code:
Supervillin fucked around with this message at 16:15 on Mar 26, 2010 |
# ? Mar 25, 2010 23:59 |
|
Supervillin posted:Whether you like OTBS or Allman or K&R or some other crappy style, for the love of all that is holy USE BRACES. Fixed late last year: I'm confused by this. What's wrong with the omission of braces here?
|
# ? Mar 26, 2010 11:58 |
|
mr_jim posted:I'd consider creating well-named local variables to store the results of some of those function calls. player.cursor.getYCoord(), player.cursor.getXCoord, and player.getDistanceOfSight() in particular. Why? Provided you have a half rear end compiler, a query should be in lined running. The only problem with the previous is if the user allowed a player to update while that test was taking place and you didn't want that to change while doing the work. Otherwise, the method calls are fine. I agree with the math in the loops head complaint. An Outland Dish posted:I'm confused by this. What's wrong with the omission of braces here? Nothing or it wouldn't compile. However, adding braces to every if...then...else, while, for, etc block is a really good programming practice. I've run into a lot of code that is: code:
HFX fucked around with this message at 13:53 on Mar 26, 2010 |
# ? Mar 26, 2010 13:47 |
|
An Outland Dish posted:I'm confused by this. What's wrong with the omission of braces here? pre:if(0) //what printf("hi");
|
# ? Mar 26, 2010 14:07 |
|
ColdPie posted:
just for fun I ran this through both java and gcc and neither printed anything.
|
# ? Mar 26, 2010 14:11 |
|
ColdPie posted:
http://codepad.org/Xb6mlPGD Comments are stripped out during the lexical analysis stage, if the compiler does what you're saying it does, it's wrong. (efb)
|
# ? Mar 26, 2010 14:11 |
|
Unless you mean for that comment to stand in for actual code, you are completely wrong. Anyhow, the second-worst part about that big java condition is this: code:
Mustach fucked around with this message at 14:13 on Mar 26, 2010 |
# ? Mar 26, 2010 14:11 |
|
Mustach posted:Unless you mean for that comment to stand in for actual code, you are completely wrong. What is that in reference too?
|
# ? Mar 26, 2010 15:13 |
|
This post
|
# ? Mar 26, 2010 15:16 |
|
Mustach posted:This post He said it was in Java. In order to be assignable to a byte, it has to be integer coercible which only the integer types are capable without a using a cast or a library functions (welcome to Java's one silent type coercion)
|
# ? Mar 26, 2010 15:22 |
|
TRex EaterofCars posted:just for fun I ran this through both java and gcc and neither printed anything. Hahaha durp I typed my test case wrong
|
# ? Mar 26, 2010 15:27 |
|
HFX posted:He said it was in Java. In order to be assignable to a byte, it has to be integer coercible which only the integer types are capable without a using a cast or a library functions (welcome to Java's one silent type coercion)
|
# ? Mar 26, 2010 16:19 |
|
HFX posted:Why? Provided you have a half rear end compiler, a query should be in lined running. The only problem with the previous is if the user allowed a player to update while that test was taking place and you didn't want that to change while doing the work. Otherwise, the method calls are fine. I wouldn't do it as an optimization, just as a matter of style. I think that something like this (using local variables, and leaving everything else the same): code:
code:
|
# ? Mar 26, 2010 16:54 |
|
mr_jim posted:I wouldn't do it as an optimization, just as a matter of style. I think that something like this (using local variables, and leaving everything else the same): They are both pretty readable to me, one is just longer lines and I slightly lose reference that the xcoordinate refers to the cursor and not the player. I'd really recommend a lot of that work being pushed into functions which did returned a result of the test. I've been dealing with people this week who worry about how many functions they call and thus writing terribly large methods. They figure the function calls are expensive (they aren't) and don't realize the compiler is inlining a lot of them anyway. Mustach posted:I was bitching about the code's use of > -1 instead of >= 0. Good point. I really have no idea, but it wouldn't be the first time I've seen people scared of >= or <=.
|
# ? Mar 26, 2010 17:20 |
|
What is wrong with complicated conditions and/or math in for loop? It can make sense and be elegant in certain ways. If you can't really handle a "weird" looking for loop then what are you doing programming in first place? I am pretty sure that coding horror is not just slightly "weird" looking code but something that is wrong/inefficient and/or just plain stupid. Now the real coding horror is the post increment instead of pre-increment as last statement tin for loop's head!
|
# ? Mar 26, 2010 17:47 |
|
RussianManiac/hexadecimal again?
|
# ? Mar 26, 2010 17:55 |
|
Why the hell would java care whether you pre- or postincrement anything
|
# ? Mar 26, 2010 17:58 |
|
LockeNess Monster posted:What is wrong with complicated conditions and/or math in for loop? It can make sense and be elegant in certain ways. Mustach posted:RussianManiac/hexadecimal again?
|
# ? Mar 26, 2010 18:00 |
|
Why can't you just do this and make it readable to everyone? EDIT: North and South might be backwards but whatever. EDIT 2: ClampLo is 10x better than Min. code:
code:
Seth Turtle fucked around with this message at 19:48 on Mar 26, 2010 |
# ? Mar 26, 2010 18:07 |
|
^^^^ Woo re-implementing standard library functions with unusual names! Brilliant!LockeNess Monster posted:What is wrong with complicated conditions and/or math in for loop? It can make sense and be elegant in certain ways. "Elegant" is not the word I'd choose for needing to search through 6 lines of code to find the semicolons needed to even begin understanding what the loop is doing.
|
# ? Mar 26, 2010 18:59 |
|
Mustach posted:RussianManiac/hexadecimal again? Hey mods can we have a price check on how much hexadecimal has spent in order to be repeatedly told to get out of CoC?
|
# ? Mar 26, 2010 20:25 |
|
$entheogen = ? $hexadecimal = ? $russianmaniac = ? $whateverhisnewnameis = ? Let's Find Out!
|
# ? Mar 26, 2010 20:29 |
|
Ok, I was kinda joking about pre/post increment stuff, I just don't think that some slightly complicated for loop header statements are coding horror. The code in question in this thread could be cleaned up and made more concise but it is not really a coding horror. Also who is this hexadecimal you guys think I am?
|
# ? Mar 26, 2010 21:44 |
|
mr_jim posted:I wouldn't do it as an optimization, just as a matter of style. I think that something like this (using local variables, and leaving everything else the same): The real horror is spaces around braces.
|
# ? Mar 26, 2010 22:22 |
|
Zombywuf posted:The real horror is spaces around braces. At least it's (byte) and not ( byte ).
|
# ? Mar 26, 2010 22:38 |
|
Also, breaking lines after a ||, but before a &&.
|
# ? Mar 26, 2010 22:49 |
|
mr_jim posted:Also, breaking lines after a ||, but before a &&. And then forgetting to break a line before one of the &&s. That block is physically painful to read.
|
# ? Mar 26, 2010 22:52 |
|
ColdPie posted:
holy moley coldpie it's you. you're the coding horror itt.
|
# ? Mar 26, 2010 23:24 |
|
Zombywuf posted:The real horror is spaces around braces. I just got access to the source of an extremely expensive product and their coding style is Allman with bracespace.
|
# ? Mar 26, 2010 23:49 |
|
Markov Chain Chomp posted:holy moley coldpie I was sure the comment didn't count as a statement, so I tried it out, and found out that it does! Except I'm apparently retarded and managed to do it wrong. But that sure didn't stop me from posting, no way.
|
# ? Mar 27, 2010 00:10 |
|
At least you're not hexadecimal. …or are you
|
# ? Mar 27, 2010 00:53 |
|
I was teaching some middle schoolers how to use Game Maker's visual programming interface and it turns out that a comment block immediately after an if or an else statement acts in exactly the manner that ColdPie's describing. It sucks when something like that comes up during a live demonstration of how and why you should always comment your code.
|
# ? Mar 27, 2010 01:44 |
|
TRex EaterofCars posted:I just got access to the source of an extremely expensive product and their coding style is Allman with bracespace. if there's one thing visual studio does well (and it actually does a lot of things well), it's that it defaults to enforcing a sensible brace standard, so most c# projects don't have crazy brace styles. unless you have a problem with the default VS brace style, which i guess is a problem for you
|
# ? Mar 27, 2010 01:46 |
|
Ryouga Inverse posted:unless you have a problem with the default VS brace style, which i guess is a problem for you
|
# ? Mar 27, 2010 02:14 |
|
Dijkstracula posted:Am I gonna have to go on another tirade about how Allman-style bracing is the most beautiful of all bracing <> It's also the ANSI standard.
|
# ? Mar 27, 2010 02:18 |
|
K&R supremacy.
|
# ? Mar 27, 2010 02:59 |
|
Seth Turtle posted:
|
# ? Mar 27, 2010 04:24 |
|
Scaevolus posted:Why isn't he just using the normal int type? This is the kind of optimization you would do on an 8-bit processor. Why isn't he making a generic--- oh wait, Java.
|
# ? Mar 27, 2010 04:28 |
|
|
# ? May 16, 2024 18:28 |
|
mr_jim posted:K&R supremacy. 1TBS is accurately named.
|
# ? Mar 27, 2010 04:29 |