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
POKEMAN SAM
Jul 8, 2004

tef posted:

See, where you might use "result" I would use bln_flg_tst_cnd_args_x.

Hahahahahahahahahahaha

Oh COBOL, you humor me so.

Adbot
ADBOT LOVES YOU

POKEMAN SAM
Jul 8, 2004

ehnus posted:

Two that come immediately to mind are breaking out of nested loops in C/C++/C#

The one thing I did like about PHP was that they offer the break X construct that lets you break out of nested loops as far as you want.

POKEMAN SAM
Jul 8, 2004

jonnii posted:

I'm sure this has been mentioned a million times, but I see this EVERY day and it winds me up.

code:
if(some_variable == true){
   ...
}

I do it because it makes my code look cleaner. I usually don't use == true for if statements whose conditions are method calls, provided that the method has a meaningful name.

I'll do, for example, if (m_isOpening == true) { }

POKEMAN SAM
Jul 8, 2004

floWenoL posted:

C++ is not immune to this.

Especially when you use

#define bool int


:mad:

POKEMAN SAM
Jul 8, 2004

wolf_man posted:

Is there a more elegent/better way of solving this problem ?

Probably not using PHP would make it more elegant :iceburn:

POKEMAN SAM
Jul 8, 2004

enki42 posted:

It's actually pretty easy to hack up an extension method on Object for in if you really want it. I think this should work:

code:
public static bool In(this object toCompare, object[] otherObjects) {
   return otherObjects.Contains(toCompare);
}
And you can throw a couple of extra overloads to avoid the ugly array instantiation syntax:

Assuming this is C# and not Java (I still can't tell the difference, heh) then you don't need the overloads. You can do:

code:
public static bool In(this object toCompare, [b]params[/b] object[] otherObjects) {
   return otherObjects.Contains(toCompare);
}
Then you can just call Whatever.In(1,2,3,4,5) with however many you parameters you want.

POKEMAN SAM
Jul 8, 2004
At work someone wrote this:

code:
if (m_variable != null) {
    throw new ArgumentNullException("m_variable");
}
lol what a retard

POKEMAN SAM
Jul 8, 2004

RegonaldPointdexter posted:

I saw this in some JavaScript yesterday:

code:
var change = true;
change = false;
while(change) {
  change = false;
No, I didn't remove any lines inbetween. It was exactly like this.

Just trying to be thread safe!

POKEMAN SAM
Jul 8, 2004

Nehle posted:

code:
SELECT LAST_INSERT_ID()
:ssh:

You don't want to do this. What if two people are accessing the website at the same time? Your two queries are not one atomic operation, meaning that two individuals' INSERT statements could fire and then their two SELECT statements (not always INSERT SELECT INSERT SELECT). Then they'd both get the same result back from LAST_INSERT_ID() which is obviously NOT what you want.

POKEMAN SAM
Jul 8, 2004

DaTroof posted:

The function returns the last ID inserted on the current connection. As long as those two users' inserts were performed on different connections, they will NOT get the same result from LAST_INSERT_ID().

That's fair then.

POKEMAN SAM
Jul 8, 2004

HappyHippo posted:

Now that I think about it, that's probably what I did. I was trying to remember without actually having the code to look at.

Nice save.

POKEMAN SAM
Jul 8, 2004

netcat posted:

A friend who interns at some lovely gamedev company around where I live told me they had someone applying for a job, and he sent in a game together with the source code. The code (in C++) was riddled with stuff like this:
code:
int f() {
   int *i = new int;
   ...
   return *i;
}
Needless to say, he didn't get the job.

I like to keep my integers on the heap, too, just on the off chance that if my stack gets corrupted my data (integers) will still be correct.

POKEMAN SAM
Jul 8, 2004

shrughes posted:

Well regarding 3000 line functions, they're only sensible when the level of complexity is very low, like when 2975 lines are used to fill a static array.

Maybe you should be reading in your static array in some other fashion then? I mean I do know of reasons for having that data in code, but there are often times better solutions.

POKEMAN SAM
Jul 8, 2004

rotor posted:

n&1 is a little weird, but I don't see what makes it a coding horror!!

It's at least hardware dependent. Unless it says somewhere in the C++ specification that integers have to be represented exactly as they are commonly today...

POKEMAN SAM
Jul 8, 2004

hexadecimal posted:

Do you mean 2's compliment instead of sign bit or something? In that case it would still work for all positive numbers.

Where does it say that 00000001 is 1? What if hardware specifies that the sign bit is the least significant bit instead of the most significant bit? What if it stores the least significant bit in the highest significant bits place for integers?

Edit: Also stop PMing people and get in #cobol, it's more fun.

POKEMAN SAM
Jul 8, 2004

Steve French posted:

Now, I agree that doing &1 to test for even/odd is silly, but this is a pretty dumb point. If you can't assume something as elementary as that, then bitwise operations quickly become nearly (completely?) useless.

No they aren't. They only become useless if you're only doing bitwise operations on integers expecting the bitwise operations to have a result on the numerical representation. In all worlds doing 0xFF & 0x01 would equal 0x01, but not in all numerical representations does the 0x01 bit represent the same thing. What if, for example, a system only had a floating point math processor, so all integers are floating point numbers. Ignoring the precision problems, & 0x01 would not tell you if the number is even or odd, but in all representations it would give you the least significant bit.

POKEMAN SAM
Jul 8, 2004

heeen posted:

Hahaha better yet, how do you define modulus for float numbers?

Ever heard of fmod?

POKEMAN SAM
Jul 8, 2004
I did get pretty carried away with the retarded examples, but it's still loving stupid to rely on the representation of something to do something mathy when you have a perfectly good/obvious/understood/optimizable way of doing it, as in this case.

POKEMAN SAM
Jul 8, 2004

Painless posted:

It won't "bitch", but it's quite possible that it will randomly fail! Just use unions drat it.

Where in the C standard does it specify that unioned elements will occupy the same space in memory?

POKEMAN SAM
Jul 8, 2004
Edit: Thanks.

POKEMAN SAM
Jul 8, 2004

hexadecimal posted:

I was really high at the time and was thinking of truth tables instead of normal comparison. I was trying to think of a way to sort the way I did in one line.

I am special :downs:

Are you high now?

POKEMAN SAM
Jul 8, 2004

Scaevolus posted:

which tends to make useless copies of the object that most compilers are unable to optimize away.

Is that like what happens with Quote != Edit?

POKEMAN SAM
Jul 8, 2004
I mentioned this in IRC as it was playing out, but I'm sitting in a Computer Science majors computer lab, and there are three guys sitting next to me working on a Perl assignment. I know for a fact they're not freshmen or sophomores but even if they were, ugh.

So, they have to take input into their program and want to validate and make sure the user enters in a number (as opposed to something else.)

Their solution?

Store the input in a temp variable. Multiply the temp variable by 1. Make sure the temp variable is the same as the input.

Also this quote "You could also use a regular expression but that'd be a pain in the rear end."

Ugh.

POKEMAN SAM
Jul 8, 2004

Triple Tech posted:

Degrees don't mean poo poo! I wonder what their thought process was that using regexp validation, which is infinitely more robust, was somehow worth less than "multiplying something by one"? Geniuses at work, people.

I think regexps are too hard. One of them used a regexp for something else and the other two were like :dropjaw:.

POKEMAN SAM
Jul 8, 2004

Munkeymon posted:

We have a single point of return policy.

I know some people like that, but Ugg I hate it. I'd rather jump the hell out of a triply-nested loop with a Return statement than try to get out some other way. (Though I guess PHP has a break(x) function that breaks you out of multiple loops, doesn't it?)

POKEMAN SAM
Jul 8, 2004

Avenging Dentist posted:

What are you talking about?

I think it's a joke but idgi

POKEMAN SAM
Jul 8, 2004

ryanmfw posted:

What would be the correct email regex?

this gets brought up all the time:


(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

POKEMAN SAM
Jul 8, 2004
My girlfriend was sent an auto-generated password to log into some medical site. We couldn't believe the password:

)       |.   /

It worked fine to login, but I mean, who the hell thought of writing a generator to create those kinds of passwords?

POKEMAN SAM
Jul 8, 2004

Lord Uffenham posted:

Never heard of the ole generate a password by taking a random 1x14 rectangle out of a piece of ASCII art? Oldest trick in the book, man.

Hahaha, that's great.

POKEMAN SAM
Jul 8, 2004

That Turkey Story posted:

I'm pretty sure I gave an example.

Even TTS isn't willing to read his wall of text to answer that question definitely though.

:smugissar:

POKEMAN SAM
Jul 8, 2004

mr_jim posted:

A friend just told me about a guy he works with who prefaces every function name with his user name, as in:

code:
userName_funcName();


code ownership baby

POKEMAN SAM
Jul 8, 2004

Kidane posted:

Hahahaha, I hadn't seen the first one, that's awesome. What the hell is reverse logic? Using !~ instead?

In C I'd wrap the whole thing in () and put !(...)

POKEMAN SAM
Jul 8, 2004

Janin posted:

It's pretty common in Python code written by people used to C++/Java.

[citation needed]

POKEMAN SAM
Jul 8, 2004

evilneanderthal posted:

I hope that provides some clarification.

I've seen my share of lovely Python code and I've never seen that, sorry.

POKEMAN SAM
Jul 8, 2004

pokeyman posted:

e: Come to think of it, isn't "if" redundant if you have goto?

How would you conditionally branch with goto?

POKEMAN SAM
Jul 8, 2004

shrughes posted:

Put function pointers in a two-element array and index the array with a boolean.

Of course, that has nothing to do with goto. But I think there's some gcc feature that would let you do that with goto. Don't bytecode interpreters use that nowadays?

Pfft, function pointers are such a redundant feature :downswords:

POKEMAN SAM
Jul 8, 2004

Triple Tech posted:

code:
my @originals = ...;

# copied
my @modified_duplicates = map { frobnicate($_) } @originals;

# "in-place"
@originals = map { frobnicate($_) } @originals;

# in-place (ugly)
$_ = frobnicate($_) for @originals;
It's terse, perlish, parallelizable, and makes great julienned fries!

You really like the word frobnicate, don't you? Also I liked your old avatar better.

POKEMAN SAM
Jul 8, 2004
Whenever I see MUMPS I wonder why people actually write it by hand instead of writing it in another language that gets translated/compiled to MUMPS. I swear that would be one of the first things I tried if I got stuck with lovely language work.

POKEMAN SAM
Jul 8, 2004

Milotic posted:

The two features I dislike the most in .NET 3.5 are lambda expressions and the return of the dreaded var. Yes, I know the compiler can work it out. I'm not as smart as the compiler. If I'm looking at your code, there's a good chance there's something wrong with it. Please make my life a bit easier.

At least they gave us automatic properties to make up for it.

1. Lambda expressions are amazing, especially when dealing with dispatching stuff between worker threads and the UI thread.

2. I agree, var blows. It might not be a problem if you're the one writing the code, but when I'm trying to read it...

Adbot
ADBOT LOVES YOU

POKEMAN SAM
Jul 8, 2004

geetee posted:

Something appears to be missing.

he just cut out the long part of the post...

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