|
Bonus posted:Also what the hell is up with setting a variable to false and then doing var = var || x Some point along the way, retVal will become true (found a valid item), so it should stay true. Of course, a sane person would just say "if(item.isValid) return true;" but that's neither here nor there. Also my favorite is still code:
|
# ¿ Mar 21, 2008 20:12 |
|
|
# ¿ Apr 30, 2024 03:42 |
|
Triple Tech posted:Ample worry (self awareness?) is step one on your journey to not being here. If at any time you thought "my code looks like this" or "that looks like a good idea", then you should be really worried. (Just don't read any programming blogs and you'll be fine.)
|
# ¿ Dec 6, 2008 00:03 |
|
I see that Kharya is taking the middle-man out of the equation and just putting his horrible code/ideas in this thread directly!
|
# ¿ Jan 3, 2009 06:32 |
|
Painless posted:I've done that occasionally with cousin int_expression and uncle pointer_expression to make visual c++ shut up. Yeah, there are other ways, such as (bool)int_expression and !!pointer_expression. I don't like them What is wrong with you why wouldn't you just use expression != 0
|
# ¿ Jan 5, 2009 00:22 |
|
Sartak posted:I force my boolean return values to be true or false so that I don't leak information and have to maintain that in APIs I write. Paranoid programming is actually a really good example of a "coding horror." http://codepad.org/64BJzSQu
|
# ¿ Jan 5, 2009 03:57 |
|
Sartak posted:That's different. I'm not second guessing the language. I'm second guessing the user. Nooo, what I mean is that, by definition any (initialized) boolean value in C++ is either true or false, and that any integral/float promotion turns true into 1 and false into 0. While, in theory, the standard allows for bool types to store their value in any form, (e.g. storing "true" as any non-zero value), attempting to determine what this value actually "is" is undefined by the standard. Besides that, I don't know of any C++ compiler that stores bools as anything but 0 or 1. Furthermore, an optimizing compiler will likely ignore "== true" anyway, so chances are that you aren't doing anything in the first place. The moral of the story is: don't try to outsmart the compiler. (I'm confining this discussion to C++ because it's one of the only languages that both has a "bool" type and allows "clever" conversions between types to peek at the underlying data.)
|
# ¿ Jan 5, 2009 04:16 |
|
The bigger horror is that an optimizing compiler (i.e. all of them) will convert x mod 2n to an appropriate bitwise operation. Don't try to outsmart the compiler with micro-optimizations.
|
# ¿ Jan 6, 2009 01:02 |
|
ih8ualot posted:I didn't mean it like that. Of course performance is important for any application you write. Actually, the best metric would be results from the language you're using.
|
# ¿ Jan 6, 2009 23:15 |
|
Victor posted:You must have missed that post of passion of mine above. It's ok, it's shorter than what I used to post long ago, so maybe you missed it. Maybe longs posts were good... Your posts are just as long as they were before, now you just hit "Submit Reply" every few sentences.
|
# ¿ Jan 8, 2009 10:53 |
|
Steampunk Mario posted:
Does that even compile? Post-increment returns an rvalue and you can't assign to rvalues.
|
# ¿ Jan 8, 2009 21:35 |
|
Scaevolus posted:With complex object types, which post almost certainly is Let's not get too full of ourselves here, ok?
|
# ¿ Jan 9, 2009 02:31 |
|
Well, it's better than one site I went to where the "save password" option sent your raw password as the "value" attribute in an HTML password field. For some reason it didn't do the same for the username.
|
# ¿ Jan 9, 2009 23:02 |
|
zergstain posted:As opposed to sending a cookie with a secret key in it? Or something like that. Usually when you tick "remember my password" it just signs you in automatically but with this method you had to sign in manually. I mean there's still potential security issues with using magic cookies, but at least in most cases, you can only use that cookie to sign into that particular site, not to actually get a user's raw password and use it everywhere.
|
# ¿ Jan 9, 2009 23:54 |
|
Zombywuf posted:There is a flow chart floating around telling you which type of collection to use for different situations. It's wrong, it should read "use a vector". Every rule has exceptions of course, when you encounter one of these exceptions you will wish you used iterators. Vectors are gross.
|
# ¿ Jan 19, 2009 00:35 |
|
julyJones posted:I meant that vector::sort doesn't exist. You can use algorithm sort though, so I am wrong about not being able to sort. And it shouldn't. That violates the whole idea of generic programming. Honestly, I hope that with concepts, we can do away with list::sort, which really could be implemented as a free function (and probably should have).
|
# ¿ Jan 20, 2009 03:37 |
|
Zombywuf posted:I'd always assumed that the current STL used iterator categories to handle that. Bit odd that it doesn't. It does, in the sense that std::sort expects a random-access iterator (which list iterators obviously do not satisfy).
|
# ¿ Jan 21, 2009 23:07 |
|
shrughes posted:Codepadded into #cobol: What.
|
# ¿ Jan 28, 2009 02:21 |
|
LIEUTENANT INTERNET posted:nice try but it was poorly formatted and part of a do while loop u mad?
|
# ¿ Jan 28, 2009 02:24 |
|
LIEUTENANT INTERNET posted:nice try but Id Rather Be JavaProgrammingtm Enterprise Level Scalable Turnkey Networked Future-Proof Java Solutions instead of fooling around with c++ Do you indent in Java like you do in C++?
|
# ¿ Jan 28, 2009 02:27 |
|
LIEUTENANT INTERNET posted:real tabs Look upon your works, ye coder, and despair!
|
# ¿ Jan 28, 2009 02:30 |
|
LIEUTENANT INTERNET posted:good thing that isnt me It is now, and nothing you can say will change that.
|
# ¿ Jan 28, 2009 02:35 |
|
Sartak posted:What the hell was that code even supposed to do? Possibly $userid -= 5?
|
# ¿ Jan 28, 2009 23:57 |
|
Sartak posted:Even still, why would you subtract 5 from the userid if it contains a period? I've seen worse things. Hell, I've written worse things (though I usually at least have the awareness to apologize for it in comments).
|
# ¿ Jan 28, 2009 23:59 |
|
mr_jim posted:There are so many kinds of bad right there. Yeah, especially the blog's title.
|
# ¿ Jan 29, 2009 23:18 |
|
Zemyla posted:You know you have to include the STL type information into those things, right? Otherwise, it's pointless! What are you talking about?
|
# ¿ Feb 7, 2009 21:15 |
|
TRex EaterofCars posted:I think it's more proof that the designers of RFC 822 were not very forward-thinking when they came up with it. Or that they expected you to write a simple parser instead of using a regex.
|
# ¿ Feb 12, 2009 05:08 |
|
Otto Skorzeny posted:Meh, any programmer should have taken at least one statics course and thus grok i, j and k Yeah but i, j, and k (with hats at least) are unit vectors, not displacements along an axis, as x, y, and z often are.
|
# ¿ Feb 24, 2009 23:53 |
|
Zombywuf posted:std::cout singleton Hahahahahahahaha
|
# ¿ Mar 13, 2009 20:46 |
|
I want my password to be Bender! o-(8 E|
|
# ¿ Mar 13, 2009 23:32 |
|
Janin posted:That code is C++, so "reference" is actually the insanely dangerous "any future code could change the variable used in this context to anything" kind, not Java/C#/Python copied pointers. what
|
# ¿ Mar 17, 2009 05:05 |
|
Janin posted:What does this code print? http://codepad.org/s1Vd99ty
|
# ¿ Mar 17, 2009 05:25 |
|
Otto Skorzeny posted:If you don't know what a function does you probably shouldn't use that function wait do you mean i need to stop doing this in my code code:
|
# ¿ Mar 17, 2009 05:37 |
|
Janin posted:http://codepad.org/r279Xoew oh fabulous, a tired talking point about an easy-to-diagnose problem that only occurs when people are intentionally trying to be retarded oh poo poo i might have to load up gdb what has this world come to
|
# ¿ Mar 17, 2009 05:42 |
|
Seriously dude, this code is precisely as easy to debug: http://codepad.org/wGa2VjI4 And before you say "oh but you can assert(sc) in that example, making it easier to find the point of failure", you can do that with references too if you're paranoid. Janin posted:Do you think I just heard about references and decided to hate them based on the name? It may be an easy problem to diagnose in a 20-line program directly in front of you, but you try tracking down the source of an irregular once-per-day crash by talking to a receptionist over the telephone. Then tell me how references are safe. I'm sorry to hear about your inability to run any profiling software. EDIT: forgot fflush Avenging Dentist fucked around with this message at 05:52 on Mar 17, 2009 |
# ¿ Mar 17, 2009 05:49 |
|
Janin posted:References are supposed to guarantee that they point to a valid, allocated region of memory. Nope, sorry. While a program containing null references is not well-defined, the ISO standard does not dictate the behavior of compilation/execution of such a program (given that the dereferencing of a null pointer is explicitly undefined).
|
# ¿ Mar 17, 2009 05:58 |
|
Janin posted:Oh good, so all I have to do to make reference code safe is...treat every reference as a magical pointer? No, you open up a debugger/profiler like anyone in the world who's diagnosing a segfault.
|
# ¿ Mar 17, 2009 06:10 |
|
biznatchio posted:Maybe you'd feel better with a nice cup of Java. Actually, I did a quick Google search about null reference detection in Valgrind and found a research paper all about debugging null references in Java.
|
# ¿ Mar 17, 2009 21:59 |
|
lol you work at Epic Systems.
|
# ¿ Apr 8, 2009 20:18 |
|
GrumpyDoctor posted:I keep finding this idiom lying around: If it weren't for the fact that you're setting to NULL twice, this is completely acceptable and is in fact a recommended thing to do. (Though putting the error handling in the catch statement would be even better.)
|
# ¿ Apr 9, 2009 02:17 |
|
|
# ¿ Apr 30, 2024 03:42 |
|
Lexical Unit posted:Wouldn't LocalPlace* plp = new (std::nothrow) LocalPlace; be recommended over that code though? Seeing as all they seem to want to do is to set the pointer to NULL if new fails... Also, couldn't the catch (...) be masking any exceptions that LocalPlace's constructor might throw? You can do it however you want. It's not a coding horror to check for memory allocation failure. Worst-case scenario, it's slightly more verbose than necessary.
|
# ¿ Apr 9, 2009 21:12 |