|
bmoyles posted:
1. $_GET and $_POST instead of $_REQUEST. 2. while(list($key,$val) = each(...)) instead of foreach(... as $key => $val). 3. There's already a function that does exactly this. So: Step #1 - Replace that block of code with extract($_REQUEST); Step #2 - Get rid of it and fix your loving script!
|
# ? Apr 28, 2008 13:17 |
|
|
# ? May 15, 2024 03:56 |
|
A classmate tragically misunderstands how HTML works (dead link)
Dazzling Double V fucked around with this message at 01:30 on Jun 14, 2012 |
# ? May 2, 2008 01:22 |
|
Dazzling Double V posted:A classmate tragically misunderstands how HTML works. He even tried to match the syntax coloring from the tutorial he was using. This was the culmination of his efforts before giving up and switching to iWeb. Wait, is that what his code looks like, or did he use some composer to create a page to display the code like that?
|
# ? May 2, 2008 01:27 |
noonches posted:Wait, is that what his code looks like, or did he use some composer to create a page to display the code like that? It looks like he typed HTML code into Microsoft Word, then saved it as a web page. That's - amazing.
|
|
# ? May 2, 2008 03:37 |
|
RegonaldPointdexter posted:Not only is it a bad idea, it's not executed well either. $_REQUEST wouldn't work for this because it goes $_GET -> overwritten by $_POST -> overwritten by $_COOKIE. That code is $_POST -> overwritten by $_GET.
|
# ? May 2, 2008 17:19 |
|
duz posted:$_REQUEST wouldn't work for this because it goes $_GET -> overwritten by $_POST -> overwritten by $_COOKIE. That code is $_POST -> overwritten by $_GET. http://us2.php.net/manual/en/ini.core.php#ini.variables-order
|
# ? May 2, 2008 17:33 |
|
ryanmfw posted:http://us2.php.net/manual/en/ini.core.php#ini.variables-order Yes, the default is GPC which is what I used. I figured anyone who writes code like that doesn't know how to edit the php.ini (or isn't allowed to).
|
# ? May 2, 2008 18:09 |
|
duz posted:Yes, the default is GPC which is what I used. I figured anyone who writes code like that doesn't know how to edit the php.ini (or isn't allowed to). I think you put too much faith into idiots not putting too much effort into finding the wrong solutions for their own problems.
|
# ? May 2, 2008 21:56 |
|
In my data-structures CS class, you would think that most of the people who can't really hack programming would have been filtered out by now. The introductory logic class, the "intro to computer science" and "computer science" classes that tell you how to program and such would usually intimidate people. But... well: code:
This happened a few months ago. I'm still in awe. Not only is that conditional a tautology, but... !false? Seriously? There's a keyword for that-- it's called "true" for gently caress sake! I think being a Java school is to blame here.
|
# ? May 4, 2008 03:20 |
|
argolithm posted:But... well: FYI, I'm almost positive that word.length() call will get optimized into an inline by HotSpot. I actually thought javac would take care of it, but the disassembler says otherwise.
|
# ? May 4, 2008 03:57 |
|
Drx Capio posted:It's an application of the Single Function Exit Point philosophy, with which I don't agree. I think it's good for some issues, especially resource management, but largely you want to use RAII for that anyway, and code can get very messy if you can't bail out early (goto, anyone?). Single function exit point are for BASIC and assembly, that's about it. If your programming language has function define/call/return features built-in, you might as well use them.
|
# ? May 4, 2008 04:36 |
|
argolithm posted:This happened a few months ago. I'm still in awe. Not only is that conditional a tautology, but... !false? Seriously? There's a keyword for that-- it's called "true" for gently caress sake! Even if I managed to type something as horrible stupid as !false, I would immediately correct it and give myself a slap on the face. Who the gently caress thinks that is acceptable? 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.
|
# ? May 4, 2008 04:55 |
|
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. But... uh... !false definitely qualifies as a Coding Horror. I can at least fathom why someone would write if (true), but not !false.
|
# ? May 4, 2008 07:30 |
|
The !false looks like it comes from debugging the loop (or maybe code right after it). Like, instead of commenting out the loop, he initially just put the false in there to short-circuit it, and then at the end he !ed it? I don't know - !false is just too weird to not have a little backstory that does make some modicum of sense.
|
# ? May 4, 2008 13:51 |
|
I ran into this in PL/SQL this week.code:
Xae fucked around with this message at 17:32 on May 4, 2008 |
# ? May 4, 2008 17:30 |
|
Incoherence posted:I can at least fathom why someone would write if (true), but not !false. I've heard plenty of people describe conditions as being not false. The author of that code probably overhead someone making a comment along those lines and ran with it.
|
# ? May 5, 2008 11:18 |
|
nrichprime posted:I've heard plenty of people describe conditions as being not false. It's true: code:
MrMoo fucked around with this message at 14:59 on May 5, 2008 |
# ? May 5, 2008 13:55 |
|
dustgun posted:The !false looks like it comes from debugging the loop (or maybe code right after it). Like, instead of commenting out the loop, he initially just put the false in there to short-circuit it, and then at the end he !ed it? I don't know - !false is just too weird to not have a little backstory that does make some modicum of sense. Yeah, I've actually done that myself in the past, usually with if statements though, so you can occasionally find one left over in my code, such as: if($conditions && 1) {}
|
# ? May 5, 2008 14:42 |
|
TRex EaterofCars posted:FYI, I'm almost positive that word.length() call will get optimized into an inline by HotSpot. I actually thought javac would take care of it, but the disassembler says otherwise. Would the compiler be able to tell ahead of time that length() is going to return the same value for the whole loop though?
|
# ? May 6, 2008 10:31 |
|
I've gone about this at length on irc and will do so when provoked, but pretty much this is some of the ugliest code I've ever had to work on. Anti Pattern doesn't even begin to describe some of it. Redundancy is good. This is why we have two different naming schemes within the code base, often small little details like numAdult vs NumAdults or numChildren vs NumChild, or QueryReturnDate vs DateBack. We also have at least four different functions that perform uppercase, including uc, uppercase and getuppercase. There are three components to the project, two are kept in svn with manual version numbers in the top of every file, and the other is kept in the database. This would mean deploying is a nightmare, but it is ok we edit the database bits live and only push the svn code to production. XSL turned out to be a bad choice of language for text mangling so it is augmented with vbscript heavily. Which has lead to some weird calling conventions - at least one function takes three arguments as a space seperated string like getfoo("3 2 1"). Nearly every function that is in use follows the abstraction inversion principal, it is better to pass one parameter in and have 140 cases inside, rather than pass two parameters in. I can go on - it's only recently we have moved away from the 'stick everything in one file' development model. Although we still have a 'stick things with a similar name together, rather than things that call each other in the same directory' policy. It would be like doing an OO project where there is one file for each method name, and inside are the defintions for every type of object.
|
# ? May 6, 2008 14:34 |
|
triplekungfu posted:Would the compiler be able to tell ahead of time that length() is going to return the same value for the whole loop though? Can't speak for Java, but in C++ length() would almost certainly be simple enough to inline. That's not the whole story, though, since I don't believe inlining works when length() is in a shared library, which it probably is. (I think you can get inlining to work across library boundaries, but you have to do extra work? I dunno, I should read up on this.)
|
# ? May 6, 2008 15:43 |
|
tef posted:Although we still have a 'stick things with a similar name together, rather than things that call each other in the same directory' policy. It would be like doing an OO project where there is one file for each method name, and inside are the defintions for every type of object. That's actually pretty close to a legitimate pattern.
|
# ? May 6, 2008 15:47 |
|
JoeNotCharles posted:That's actually pretty close to a legitimate pattern. I'll admit it can make sense, like putting all your include files in one directory, and all your shared objects in another when distributing them. I I had a hard time thinking of an appropriate metaphor - and I meant putting every length method in length.c and every hashcode method in hashcode.c so the definition of each object would be spread around 15 or so files throughout the project. In this specific instance, it only serves to ofuscate the structure - for some reason normal websites within the project are in per website directories, but more general templates are in part1/website1.xsl, part2/website1.xsl and so on. We *never* need to refer to things by the part that they are in, and always are doing per website things. (So, on top of the multiple naming schemes we have multiple directory structures too). Oh and I just found out that in one part we have AirlineCode and in another we have AIrlineCode for the same variable.
|
# ? May 6, 2008 15:56 |
|
tef posted:Oh and I just found out that in one part we have AirlineCode and in another we have AIrlineCode for the same variable. Oh, god, that reminds me of one of my pet peeves: ".lenght()" I've worked on code where the guy before me consistently spelled it that way. It's not even a typo he never bothered to fix, because it's that way EVERY TIME. And now I have to do it too, since I can't change the interfaces! And I've seen multiple people do this, although usually not more than once or twice. People - if you have that many problems with this word, just use .len()!
|
# ? May 6, 2008 16:01 |
|
JoeNotCharles posted:Can't speak for Java, but in C++ length() would almost certainly be simple enough to inline. That's not the whole story, though, since I don't believe inlining works when length() is in a shared library, which it probably is. (I think you can get inlining to work across library boundaries, but you have to do extra work? I dunno, I should read up on this.) code:
|
# ? May 6, 2008 16:35 |
|
JoeNotCharles posted:Oh, god, that reminds me of one of my pet peeves: ".lenght()"
|
# ? May 6, 2008 16:53 |
|
Lexical Unit posted:Old code expects longititude to be populated, new code expects longitude to be populated. Good night, and good luck. The output of the screen scraper produces xml in <quote>...</quote> or sometimes <Quote>...</Quote>. Parts of the website expect <Quote>...</Quote> and so a series of search and replace operations have been tacked on to the website code to fix this. Even though we could fix it in the program itself now we are in the position of not being able to change the output format for fear of breaking other code. I also managed to fix a number of bugs by sorting the output.
|
# ? May 6, 2008 16:55 |
|
As I understand it, Java strings are immutable, so as long as the compiler can prove that the variable in the loop test always references the same string object, it can pull the call to length() out of the loop.
|
# ? May 6, 2008 17:37 |
|
Lexical Unit posted:I can one-up that. A struct with longitude, latitude, and longititude. No longititude is not different that longitude, it is just there because somehow longititude got into a spec sheet and it was easier to add to the spec than change it. Old code expects longititude to be populated, new code expects longitude to be populated. Good night, and good luck. I see this and raise you: http://en.wikipedia.org/wiki/Referer
|
# ? May 6, 2008 18:20 |
|
Ah, the classics have a beauty to them that is unparalleled.
|
# ? May 6, 2008 19:15 |
|
JoeNotCharles posted:Can't speak for Java, but in C++ length() would almost certainly be simple enough to inline. That's not the whole story, though, since I don't believe inlining works when length() is in a shared library, which it probably is. (I think you can get inlining to work across library boundaries, but you have to do extra work? I dunno, I should read up on this.) string is a template, so it would never be compiled into a shared library anyway. The compiler is pretty much going to inline it all the time unless you explicitly tell it not to inline anything. Then it just becomes an issue of the following: is this, code:
code:
Anyone who would complain about this who isn't working entirely on tiny embedded micro-architectures needs to quit stroking their e-penis and focus on the problem domain instead of premature optimization. The OP said he didn't care about it, and rightly so. But drat does it piss me off when I get into a conversation with someone -- usually it was one of my "advanced" students -- who thinks they're just oh-so-clever and thinks they're smarter than a tried-and-tested professional compiler. And to stroke my e-penis a little, code like what I just wrote above pisses me off. It should be code:
|
# ? May 6, 2008 20:29 |
|
Flobbster posted:The answer is no, because the string class stores its length explicitly (in every implementation that I've seen)
|
# ? May 6, 2008 20:45 |
|
This is more of a its worse because its a first day thing.code:
|
# ? May 6, 2008 21:01 |
|
Flobbster posted:It should be ++i damnit!
|
# ? May 6, 2008 21:16 |
|
more falafel please posted:++i damnit! FWIW, I do use pre-increment when I'm dealing with iterators, so that I don't have to worry about the cost of a temporary copy. But for integral values, it's a wash. Speaking of, has anyone ever examined the optimized assembly code for using ++iterator vs. iterator++ in a for-loop (or anywhere for that matter)? I wonder if the compiler is smart enough to optimize post- to pre- if it sees that the result isn't used as part of a larger expression.
|
# ? May 6, 2008 22:15 |
|
Flobbster posted:Speaking of, has anyone ever examined the optimized assembly code for using ++iterator vs. iterator++ in a for-loop (or anywhere for that matter)? I wonder if the compiler is smart enough to optimize post- to pre- if it sees that the result isn't used as part of a larger expression. In contrast, int is a built-in type so the compiler does know exactly when it's safe to substitute ++int for int++. Standish fucked around with this message at 22:36 on May 6, 2008 |
# ? May 6, 2008 22:32 |
|
Wait, could someone explain what iter++ is doing different than ++iter in a loop? I've never heard this before.
|
# ? May 7, 2008 05:15 |
|
Standish posted:I'd be surprised if it could optimize that for std::iterators, remember the STL is just another library as far as the compiler is concerned -- from the compiler's point of view, it doesn't know anything about iterator semantics and std::iterator::operator++() (the prefix overload) and std::iterator::operator++(int) (the postfix overload) are completely distinct functions which could have completely different sideeffects. Good point, it hadn't occurred to me that some rear end in a top hat could overload operator++() to do the correct thing and operator++(int) to do while(1) printf("Penus\n");. Chin Strap posted:Wait, could someone explain what iter++ is doing different than ++iter in a loop? I've never heard this before. Semantically, for(...; iter++) and for(...; ++iter) do the same thing, since the increment stands alone in the expression. The difference is in the lower-level implementation -- ++iter is more efficient since it increments the operand before evaluating the rest of the expression, if any. iter++, on the other hand, requires that a copy be made, since it increments the operand and then uses its old value in the remainder of the expression. So, in a tight loop, post-increment does O(n) unnecessary copy operations. In most cases it's not going to be that much of a penalty, but why do it if you can avoid it? Flobbster fucked around with this message at 05:25 on May 7, 2008 |
# ? May 7, 2008 05:18 |
|
I never understood why they chose to make ++i and i++ different functions, rather than just having a single ++ function and just change when it gets called relative to when it is evaluated.
|
# ? May 7, 2008 06:00 |
|
|
# ? May 15, 2024 03:56 |
|
Flobbster posted:The difference is in the lower-level implementation -- ++iter is more efficient since it increments the operand before evaluating the rest of the expression, if any. iter++, on the other hand, requires that a copy be made, since it increments the operand and then uses its old value in the remainder of the expression. 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.
|
# ? May 7, 2008 08:24 |