|
Ugg boots posted:I don't think that the Java problem is the same x87 weirdness as PHP. Their algorithm is different (approximating toward the target from the other direction), and also it seems to work (not work) on 32-bit and 64-bit hardware. Why do so many libraries and runtimes use the correction loop method to begin with?
|
# ? Feb 1, 2011 20:31 |
|
|
# ? May 17, 2024 18:35 |
|
Plorkyeran posted:The indentation is wrong, so no. I didn't mean it was right, I meant it was aesthetically pleasing. Like if ee cummings were a programmer.
|
# ? Feb 1, 2011 21:30 |
|
Ugg boots posted:I don't think that the Java problem is the same x87 weirdness as PHP. Their algorithm is different (approximating toward the target from the other direction), and also it seems to work (not work) on 32-bit and 64-bit hardware. Otto Skorzeny posted:Why do so many libraries and runtimes use the correction loop method to begin with?
|
# ? Feb 1, 2011 21:45 |
|
I misread that first for loop as for ( eof = 0; skip = 0; ) and it was my favorite for loop ever.
|
# ? Feb 2, 2011 00:26 |
|
Xenogenesis posted:http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/ So now PHP, and Java (and therefore Clojure and others). What other languages could be susceptible to this?
|
# ? Feb 2, 2011 00:59 |
|
NotShadowStar posted:I'm taking a numeric analysis course this semester, and the second chapter is literally all about floating point errors and bounds checking and how much this is going to gently caress you over and over until you get it right. The worst abuse/misunderstanding of floating point I've ever seen was someone who decided to implement a bit-flag vector (in C++), but they wanted a human-readable bit-flag vector. So, instead of 15, they would use the number 1111. Also, instead of using an integer, they figured a double would give them more space (it does, but just barely: ~16 decimal digits instead of ~10). Then they decided to pack way more than 16 digits into the double, by using some whole digits and some fractional digits. They didn't realize that the double was going to drop any digits more than ~15 decimal places away from the most significant digit. This also made it really hard to do actual bitwise arithmetic on the number. They could have just used a bitset in memory (which can initialize from and output to a string) and a varchar in the database, but they evidently thought that floats/doubles had arbitrary precision, and thus they could pack digits onto the end indefinitely. The code was 10+ years old, so maybe they didn't have access to STL's bitset at the time, but it wouldn't have taken more than an hour or two to write their own bitset class using a backing string or byte array or something.
|
# ? Feb 2, 2011 01:05 |
|
I'm not sure if this is a coding horror or not:code:
|
# ? Feb 2, 2011 03:18 |
|
I saw this today in actual use. Even if you're familiar with perl, it is probably somewhat confusing.code:
The same thing (in all the cases we care about) can also be accomplished in one line: code:
|
# ? Feb 2, 2011 03:25 |
|
Today's coding horror is courtesy of an applicant for a job at my company. The job's standard C#, and we start off with a phone interview where we make sure they at least know what an abstract class is and the like. We had someone come in today, and one of the questions we always ask them to code up in front of us is FizzBuzz. It's simple and any good developer will knock it out in under 5 minutes. Today's applicant had to use MSDN to look up the syntax for a "for" loop, and then didn't know the modulus operator, so the solution looked (roughly) like this: code:
At the very least, being present for these interviews is making me feel like a superstar programmer.
|
# ? Feb 2, 2011 04:03 |
|
Apparently the real horror is your phone screening. Although, it sounds more like the person you were dealing was competent in some language, just not a C-style one.
|
# ? Feb 2, 2011 04:42 |
|
pwd posted:I saw this today in actual use. Even if you're familiar with perl, it is probably somewhat confusing. I vaguely recall glob not being implemented correctly on non-Unix platforms a while ago. They fixed this along with a lot of other cross-platform behavior way back in 5.6. File::Spec is expressly designed for cross-platform operations. It's not the best code, but there's probably a clear method to the madness.
|
# ? Feb 2, 2011 04:59 |
|
IIRC Path::Class is a more convenient wrapper around File::Spec stuff btw
|
# ? Feb 2, 2011 05:09 |
|
YeOldeButchere posted:I'm not sure if this is a coding horror or not: code:
|
# ? Feb 2, 2011 07:09 |
|
For loop is a coding horror in itself, I wouldn't fault anyone for looking it up to make sure.
|
# ? Feb 2, 2011 14:32 |
|
Beef posted:For loop is a coding horror in itself, I wouldn't fault anyone for looking it up to make sure. I frequently gently caress it up, since it uses semicolons but the statement is in parentheses, so I always use commas. Bit of a logical disconnect there, can't think of another remotely used thing that uses semicolons in parentheses for C-like languages.
|
# ? Feb 2, 2011 15:44 |
|
At least for isn't as ugly as a switch block.
|
# ? Feb 2, 2011 15:55 |
|
NotShadowStar posted:I'm taking a numeric analysis course this semester, and the second chapter is literally all about floating point errors and bounds checking and how much this is going to gently caress you over and over until you get it right. Just out of curiousity what book are you using?
|
# ? Feb 2, 2011 16:37 |
|
evensevenone posted:ah, the simple joys of embedded coding. Most of the code I write is for embedded systems, so (sadly) I don't really see anything too bad there.
|
# ? Feb 2, 2011 17:07 |
|
NotShadowStar posted:I frequently gently caress it up, since it uses semicolons but the statement is in parentheses, so I always use commas. Bit of a logical disconnect there, can't think of another remotely used thing that uses semicolons in parentheses for C-like languages. Well, comma already has a valid meaning in that context so you have to pick something else.
|
# ? Feb 2, 2011 23:48 |
|
Just came across this gem and thought of this thread;php:<? foreach(array_keys($_POST) as $key){ if($key == 'feature_button') { $feature_button = $_POST['feature_button']; } if($key == 'feature_name') { $feature_name = $_POST['feature_name']; } if($key == 'feature_button2') { $feature_button2 = $_POST['feature_button2']; } if($key == 'feature_name2') { $feature_name2 = $_POST['feature_name2']; } if($key == 'listing') { $listing = $_POST['listing']; } } ?>
|
# ? Feb 10, 2011 01:33 |
Rewrite it with "variable variables" because PHP is an awesome language php:<? $keys = array("feature_button", "feature_name", "feature_button2"); foreach ($keys as $key) { if (isset($_POST[$key])) { $$key = $_POST[$key]; } }?>
|
|
# ? Feb 10, 2011 01:42 |
|
Still light years better than enabling register_globals...
|
# ? Feb 10, 2011 14:01 |
|
nielsm posted:Rewrite it with "variable variables" because PHP is an awesome language The best thing is when you come across a php programmer trying to learn another language and they ask how to do this. $LANG can't do that? $LANG sucks.
|
# ? Feb 10, 2011 17:53 |
|
They should go for MUMPS then. It offers the much better named "indirection", which makes PHP's variable variables look extremely limited in comparison.
|
# ? Feb 10, 2011 18:08 |
|
Scheme offers similar features through judicious use of string->symbol.
|
# ? Feb 10, 2011 22:32 |
|
I think to redress the balance of life someone should start a Coding Joys thread for downright clever code, beautifully simple code or LOC-busting refactoring.
|
# ? Feb 10, 2011 23:42 |
|
It just seemed so appropriate.
|
# ? Feb 10, 2011 23:58 |
|
nielsm posted:Rewrite it with "variable variables" because PHP is an awesome language This works for function names too -- Drupal is kind of built around it. http://drupal.org/node/547518 http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7
|
# ? Feb 11, 2011 01:09 |
|
ironypolice posted:This works for function names too -- Drupal is kind of built around it. Not that the practice isn't a nightmarish hell to debug and maintain, but I often found it to be an intuitive approach to problems when I was first learning.
|
# ? Feb 11, 2011 06:29 |
|
baquerd posted:Not that the practice isn't a nightmarish hell to debug and maintain, but I often found it to be an intuitive approach to problems when I was first learning. 20 GOTO 10 is pretty intuitive to a total beginner too.
|
# ? Feb 11, 2011 06:32 |
|
code:
|
# ? Feb 11, 2011 08:11 |
|
code:
|
# ? Feb 11, 2011 09:08 |
|
baquerd posted:Not that the practice isn't a nightmarish hell to debug and maintain, but I often found it to be an intuitive approach to problems when I was first learning. The main argument against using it from a functionality perspective, as far as I can see, is that it doesn't let you do anything you can't already do with an associative array.
|
# ? Feb 11, 2011 13:35 |
|
Hammerite posted:The main argument against using it from a functionality perspective, as far as I can see, is that it doesn't let you do anything you can't already do with an associative array. That's a silly reason. Take that argument far enough and we'll all use assembler whose only instruction is subtract and branch if less than or equal to zero. I haven't touched PHP in a solid decade so I don't know how this particular feature works but does it help make something clearer or easier to use?
|
# ? Feb 11, 2011 16:49 |
|
pokeyman posted:That's a silly reason. Take that argument far enough and we'll all use assembler whose only instruction is subtract and branch if less than or equal to zero. Easier than typing out every single mapping from REQUEST to local variables but less clear.
|
# ? Feb 11, 2011 16:53 |
|
pokeyman posted:That's a silly reason. Take that argument far enough and we'll all use assembler whose only instruction is subtract and branch if less than or equal to zero. Well ok, so what I should really have said was: it's like using an associative array, except with less control over what you're doing and much greater potential for hard-to-spot security problems. Really I think you can compare "variable variables" : associative arrays, with global variables : local variables. If I write $$var then I could be referring to any variable. How do you know what the hell I'm doing? If I write $myarray[$parameter] then you know that line of code can only touch the contents of the associative array $myarray, which presumably is an appropriate thing for my code to be doing. So pretend I said: it's like using an associative array, but with problems that wouldn't apply if you just used an associative array in the first place. pokeyman posted:I haven't touched PHP in a solid decade so I don't know how this particular feature works but does it help make something clearer or easier to use? IMO no it doesn't, if anything it seems to me to obfuscate things, although like any technique I'm sure it gets more intuitive the more you do it.
|
# ? Feb 11, 2011 16:59 |
|
Maybe if you cut off four of your fingers with a table saw, sticking the fifth one in doesn't seem like a big deal anymore.
|
# ? Feb 11, 2011 17:02 |
|
Munkeymon posted:Easier than typing out every single mapping from REQUEST to local variables but less clear. Also less safe and more annoying. REQUEST respects the GPC order (Get, Post, Cookies) by default. This implicit kind of thing makes it so someone can pass in arbitrary variables with any page call that is being made, overwrite what you had, etc. Or it could just be another dev who started using a POST value that you need in a GET and fantastic you now have conflicts. Variable variables are dumb. Using variables for functions and classes is kind of okay (reminds of first class functions), if only the implementation wasn't so dumb (you pass a string around). Then 5.3 apparently got HoF and closures, so that's much better and kills the need for that kind of trick altogether.
|
# ? Feb 11, 2011 17:23 |
|
MononcQc posted:Also less safe and more annoying. REQUEST respects the GPC order (Get, Post, Cookies) by default. This implicit kind of thing makes it so someone can pass in arbitrary variables with any page call that is being made, overwrite what you had, etc. Or it could just be another dev who started using a POST value that you need in a GET and fantastic you now have conflicts. I was talking about the kind of thing posted above where it iterates over a pre-defined array and creates a local variable for anything it finds both in that array and in the magic array, not a hand-rolled register globals.
|
# ? Feb 11, 2011 18:56 |
|
|
# ? May 17, 2024 18:35 |
|
MononcQc posted:Also less safe and more annoying. REQUEST respects the GPC order (Get, Post, Cookies) by default. This implicit kind of thing makes it so someone can pass in arbitrary variables with any page call that is being made, overwrite what you had, etc. Or it could just be another dev who started using a POST value that you need in a GET and fantastic you now have conflicts. Considering there's too many (>1) installations still running PHP 4, requiring PHP 5.3+ features for a large project like Drupal is impossible. Wordpress does a similar trick for converting strings to function names for hooking into processes.
|
# ? Feb 11, 2011 22:48 |