Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Bonus posted:

Also what the hell is up with setting a variable to false and then doing var = var || x
Every kid knows that false || x equals to x (in a boolean context)
He could have mine as well written that line as

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:
#define private public
#define protected public

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Why not quote a post you don't understand and ask for clarification? I'm sure at least one goon won't be able to restrain himself and will wow us with his knowledge of The Right Way.





(Just don't read any programming blogs and you'll be fine.)

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I see that Kharya is taking the middle-man out of the equation and just putting his horrible code/ideas in this thread directly! :xd:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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 :saddowns:

What is wrong with you why wouldn't you just use expression != 0

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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." :colbert:

http://codepad.org/64BJzSQu

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Sartak posted:

That's different. I'm not second guessing the language. I'm second guessing the user. :tinfoil:

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.)

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ih8ualot posted:

I didn't mean it like that. Of course performance is important for any application you write.

I just meant that in terms of determining instruction efficiency, results from a compiled and optimized language might prove to be a better metric. But I could be wrong.

Actually, the best metric would be results from the language you're using.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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. :pwn:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Steampunk Mario posted:

code:
bufferIndex++ %= 2;
(C++)
Just saw this at work, someone should tell this chucklefuck that there's only one sequence point here. :argh: :siren: :ohdear:

Does that even compile? Post-increment returns an rvalue and you can't assign to rvalues.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Scaevolus posted:

With complex object types, which post almost certainly is

Let's not get too full of ourselves here, ok?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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).

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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).

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

shrughes posted:

Codepadded into #cobol:

code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  } while (a > 0);

What.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LIEUTENANT INTERNET posted:

nice try but it was poorly formatted and part of a do while loop

u mad?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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++? :pwn:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LIEUTENANT INTERNET posted:

real tabs :colbert:

Look upon your works, ye coder, and despair!

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LIEUTENANT INTERNET posted:

good thing that isnt me

It is now, and nothing you can say will change that.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Sartak posted:

What the hell was that code even supposed to do?

Possibly $userid -= 5?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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).

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

mr_jim posted:

There are so many kinds of bad right there.

Yeah, especially the blog's title. :pwn:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Zombywuf posted:

std::cout singleton

Hahahahahahahaha

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I want my password to be Bender! o-(8 E|

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Janin posted:

What does this code print?

code:
int foo = 1;
some_function (foo);
cout << foo << endl;
:iiam:

http://codepad.org/s1Vd99ty

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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:
srand(time(0));
typedef int (*func_type)();
func_type f = ( rand()/sizeof(void*) ) *sizeof(void*);
int i = f(1,2,3,4,5);
fuuuuuuuuuuck

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
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

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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).

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
lol you work at Epic Systems. :pwn:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

GrumpyDoctor posted:

I keep finding this idiom lying around:
code:
LocalPlace *plp = NULL;
try {
	plp = new LocalPlace;
}
catch (...) {
	plp = NULL;	//lint !e423 Creation of memory leak in assignment
}
LocalPlace::LocalPlace(void) is trivial. Naturally, plp will be compared to NULL later on down the line to see if it allocated successfully.

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.)

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply