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
Kidane
Dec 15, 2004

DANGER TO MANIFOLD

Trammel posted:

Why it copies the contents of each row into another variable? .. :iiam:

Because dereferencing is just so hard!

Adbot
ADBOT LOVES YOU

TSDK
Nov 24, 2003

I got a wooden uploading this one

GrumpyDoctor posted:

homegrown resizable array that's basically std::vector without bounds checking
Just so we're clear, unless you're using .at(n), then std::vector doesn't have to have bounds checking either. Some implementations choose to add bounds checking to operator[] in debug builds, but it'll get compiled out in a release build.

I know you probably know that, but it is a common myth about the STL.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

rjmccall posted:

I'm curious if there's a difference between DynamicArray::Size() and DynamicArray::GetNumb().
GetNumb() is what you do when you have to work with code like that.

Contero
Mar 28, 2004

My girlfriend :smug: wrote this:

code:
for (j = 0; j < 15; j = j++) {
   ...
}
Which took a while to explain why j = j++; is pretty much the same as saying j = j;.

tripwire
Nov 19, 2004

        ghost flow

Contero posted:

My girlfriend :smug: wrote this:

code:
for (j = 0; j < 15; j = j++) {
   ...
}
Which took a while to explain why j = j++; is pretty much the same as saying j = j;.

The horror




The horror

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
Some javascript/jQuery:
code:
function check(){
        var ok=true;
        html='<div>'+document.forms[0].html.value+'</div>';
        html=$(html).html();
        if(document.forms[0].html.value != html){
                document.forms[0].html.value=html;
                if(!confirm('Your HTML was altered to correct syntax. Continue saving?')){
                        ok=false;
                }
        }
        return ok;
}

UraniumAnchor
May 21, 2006

Not a walrus.

Contero posted:

My girlfriend :smug: wrote this:

code:
for (j = 0; j < 15; j = j++) {
   ...
}
Which took a while to explain why j = j++; is pretty much the same as saying j++;.

Fixed that for you.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Contero posted:

Which took a while to explain why j = j++; is pretty much the same as saying j = j;.

The real horror

















is you :smug:

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through

UraniumAnchor posted:

Fixed that for you.

its undefined

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

UraniumAnchor posted:

Fixed that for you.

I thought it might work that way too. But it doesn't in Java. Observe!

code:
public static void main(String[] args) {
  for (int j = 0, i = 0; j < 15; j = j++) {
    System.out.print(j + " ");
    i++;
    if (i == 20) return;
  }
}
Output:
code:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

schnarf
Jun 1, 2002
I WIN.
I'm doing some embedded development on a custom-designed board provided by some company. They wrote software to run on the board. It all works perfectly, the board is great, and they documented it well, but their code is atrocious.

First off, there's a file called "include.h" which includes all of the header files. Then every source file includes "include.h"

What's in those header files? Well, there's this:
code:
#define ON 1
#define OFF 2
#define OK 1

#define BIT_0 1
#define BIT_1 2
#define BIT_2 4
...
#define BIT_16 65536
Then of course there's code for dealing with some of the peripherals. It looks roughly like this:
code:
#define PERIPHERAL_INIT 0x238293
#define PERIPHERAL_OFF 0x823
#define PERIPHERAL_STUFF 0x723

#define PERIPHERAL_INITIALIZE { *pPort = PERIPHERAL_INIT; }
#define PERIPHERAL_TURNOFF { *pPort = PERIPHERAL_OFF; }
#define PERIPHERAL_DOSTUFF { *pPort = PERIPHERAL_STUFF; }
#define PERIPHERAL_INIT_AND_DOSTUFF { PERIPHERAL_INITIALIZE; PERIPHERAL_DOSTUFF; }
There are maybe a hundred of these macros, and all the commands for interacting with each peripheral are scattered across the many includes and source files. Then the actual functions look like this:

code:
void PeripheralOn() {
   PERIPHERAL_OFF;
   PERIPHERAL_INIT;
   PERIPHERAL_STUFF;
}
Every system task is accomplished through nested macros, pretty much. That being said, the whole thing works great.

raminasi
Jan 25, 2005

a last drink with no ice

TSDK posted:

Just so we're clear, unless you're using .at(n), then std::vector doesn't have to have bounds checking either. Some implementations choose to add bounds checking to operator[] in debug builds, but it'll get compiled out in a release build.

I know you probably know that, but it is a common myth about the STL.

I didn't actually know that, thanks for telling me. That being said, "doesn't have bounds checking in debug mode whereas my STL implementation does" was still a big problem, because when I went through and changed a bunch of these things to vectors the program started throwing out-of-bounds exceptions all over the place.

The bugs I was trying to fix weren't merely incorrect behavior - they were actually undefined behavior and I guess nobody noticed!

Contero
Mar 28, 2004

Kilson posted:

I thought it might work that way too. But it doesn't in Java. Observe!

The real horror






is Java.

tripwire posted:

The horror




The horror

Ok how about :


:colbert:

Contero fucked around with this message at 09:19 on Feb 14, 2009

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
I love the Thing class. From now on all my objects will derive from Thing.

julyJones
Feb 12, 2007

Stopped making sense.

Contero posted:

The real horror

BlueJ flashbacks! D:

tripwire
Nov 19, 2004

        ghost flow

Contero posted:

The real horror






is Java.


Ok how about :


:colbert:


Ah yes. The Thing class.

Spell
Nov 20, 2000

Eat your vegetables or you'll DIE!
Let me guess, the Thing class implement a name property.

That Turkey Story
Mar 30, 2003

Contero posted:

My girlfriend :smug: wrote this:

code:
for (j = 0; j < 15; j = j++) {
   ...
}
Which took a while to explain why j = j++; is pretty much the same as saying j = j;.

UraniumAnchor posted:

Fixed that for you.

You're both wrong, it's undefined behavior because you're modifying j multiple times between sequence points.

Edit: Oh, nm didn't realize it was java

That Turkey Story fucked around with this message at 00:44 on Feb 16, 2009

Trammel
Dec 31, 2007
.
Again, not strictly a coding horror, but come across while dealing with the code.

code:
mysql> desc Event;
| YearMonth | int(11)   |      | MUL | 0       |       |

mysql> select YearMonth FROM Event....
+-----------+
| YearMonth |
+-----------+
|    200609 |
|    200610 |
|    200611 |
|    200612 |
|    200701 |
|    200702 |
Yep. This 'YearMonth' field uses an INT data type to store a year and month value, by concatanating the year and the month into a string, then converting it to a single integer.

So we have the full number: two hundred thousand, six hundred and nine, being stored in one column, requiring split & join operations in the program, rather than storing two values, 2000 and 9, stored in separate, more easily indexed, more easily processed columns.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
I got Bel-Aired by some very annoyingly written collection management software today:

code:
function bellair(){
        if(!cookieEnabled){
        alert(error_cookies);
        } else {
        document.bell.submit();
        }
}

// duplicate bellair to fix bottom menu option and maintain page conformity

function bellair2(theForm){
        if(!cookieEnabled){
        alert(error_cookies);
        } else {
        theForm.submit();
        }
}
Actually duplicate Bel-Aired.

But seriously, why the hell is the function called "bellair"?
Why not just attach the cookie check to an onsubmit?

Kelson
Jan 23, 2005

On a single line:

if ((!( src in usr.contents ) && (((!( isturf(src) ) && (!( isturf(src.loc) ) && (src.loc && !( isturf(src.loc.loc) )))) || !( isturf(usr.loc) )) && (src.loc != usr.loc && (!( istype(src, /obj/screen) ) && !( usr.contents.Find(src.loc) ))))))
return

drat past developers!

jarito
Aug 26, 2003

Biscuit Hider

FeloniousDrunk posted:

code:
function bellair(){

...

function bellair2(theForm){

UberJumper
May 20, 2007
woop
On friday i was asked to update a small internal app, all it needed was a few little changes, maybe a weeks of work. A coop student wrote this, about 5 years ago in Java.

What the gently caress...?

A small snippet of a function:

code:
            int k1 = a(i1, j1);
            b(l1, k1, j1 + 1);
            k1 = c(i1, j1);
            b(l1, k1, j1 + 1);
            k1 = i1 - 1;
            b(l1, k1, j1);
            k1 = i1 + 1;
            b(l1, k1, j1);
            int j2 = j1;
            int i2 = i1;
            d d1 = this;
            d1 = a(i2, j2);
            b(l1, d1, j1 - 1);
            j2 = j1;
            i2 = i1;
            d1 = this;
            d1 = c(i2, j2);
            b(l1, d1, j1 - 1);
            return;
:smithicide:

The name of that function is a

0 Comments. FML.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

UberJumper posted:

:smithicide:

The name of that function is a

Part of me wants to see what b() and c() are.

That code almost looks like it came out of a bytecode "decompiler."

Blue Footed Booby
Oct 4, 2006

got those happy feet

UberJumper posted:

...
:smithicide:

The name of that function is a

0 Comments. FML.

I've unintentionally written code like that. It happens when I'm working through some mathematical process on paper or referencing a math book and start mindlessly copying what I've worked out into the code. The difference is that I look at the code when I'm done, realize it's crap, and search-and-replace with useful names. I can't imagine skipping that last step in code other people have to work with. Even if I don't care about making their lives easier I don't want people to think I'm retarded. :smith:

UberJumper
May 20, 2007
woop
I think the old coop student (who will become a wind-chime soon) didn't use a decompiler. I looked a bit into java Decompilers, but from my understanding is that in java it will return the original functions names, etc. It also keeps comments :confused: Also this code, has sprinkles of names that, are slightly more descriptive. There is just random blobs of BS code like this(its almost all BS code).

I don't quite understand how this works, the vast majority of the code though. To me, this shouldnt work, gently caress i dont even know why it works.

I dug around and looked at b.

Theres two b's

First:

code:
public final double b(int i1)
{
	//Todo: 
	return new Double(22D + ((double)i1 * t[1]).doubleValue();
}
Now. Can anyone see at least two things that make this some sort of coding horror?

code:
public final void b(int i1, int j1)
{
	//RET CODE
	boolean RET = true;
	//access
	int k1 = PROC[l1].FIRST;
	int l1 = PROC[l1].SECOND;
	//WORKS
	if(PROC[j1].s > 22D || j1 < k1)
	{
		k1 = ag.FIRST;
		l1 = ag.SECOND;
	}
	if(i1 <= k1 - (int)60D || j1 >= l1 + (int)60D)
		RET = true;
	
	if(RET)
	{
		l1 = b(l1);
	}
}
Okay okay.

I don't understand.... Would this function even change anything? Aside from manipulating the global RET value(even though it can never be false here.).....

:confused:

The comments are the most descriptive ever. I love my job.

:suicide:

Brain Candy
May 18, 2006

UberJumper posted:

code:
public final void b(int i1, int j1)
{
	//RET CODE
	boolean RET = true;
	...
}
...
Aside from manipulating the global RET value(even though it can never be false here.).....

It doesn't even do that! :v:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
If I had to guess, I would say a source-to-source compiler of some sort — possibly an extremely buggy one.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
code:
(int)60D
What?

No, really, my Java is rusty, and I have no idea what in the flying hell this means or is doing. He's casting "60D" to an int. But what the hell is 60D? A constant? I didn't think any sane programming language let you start constants with numbers, though that would also explain the "22D"... and that scares me.

Did this guy learn to code in BASICA, and just never got over insane variables?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

McGlockenshire posted:

code:
(int)60D
What?

No, really, my Java is rusty, and I have no idea what in the flying hell this means or is doing. He's casting "60D" to an int. But what the hell is 60D? A constant? I didn't think any sane programming language let you start constants with numbers, though that would also explain the "22D"... and that scares me.

Did this guy learn to code in BASICA, and just never got over insane variables?

xxxxD forces the number xxxx to a double. Can do the same with xxxxF for float.

Zhentar
Sep 28, 2003

Brilliant Master Genius

UberJumper posted:

I think the old coop student (who will become a wind-chime soon) didn't use a decompiler. I looked a bit into java Decompilers, but from my understanding is that in java it will return the original functions names, etc. It also keeps comments :confused:

Even if this is the case, an obfuscation program could still have been used to strip any useful names or comments.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

TRex EaterofCars posted:

xxxxD forces the number xxxx to a double. Can do the same with xxxxF for float.
But... if it's being created as a double, why is he immediately casting it to an int? And since when have primitive non-decimal numbers been anything but ints? This assumes that the coder thought of this. This code makes my head hurt.

UberJumper
May 20, 2007
woop

McGlockenshire posted:

But... if it's being created as a double, why is he immediately casting it to an int? And since when have primitive non-decimal numbers been anything but ints? This assumes that the coder thought of this. This code makes my head hurt.

Thats what i am wondering, its full of litttle things that have enough little things (random comments, including one about subtle anal sex :confused:) to make me think it wasnt decompiled. I think it was done as a gently caress you kind of thing.

Anyways im working on this today so i'll see if i can find function c

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

McGlockenshire posted:

But... if it's being created as a double, why is he immediately casting it to an int? And since when have primitive non-decimal numbers been anything but ints? This assumes that the coder thought of this. This code makes my head hurt.

I couldn't even venture a guess. Probably some rear end in a top hat making things more complex than they need be to justify how smart they are.

narbsy
Jun 2, 2007

TRex EaterofCars posted:

I couldn't even venture a guess. Probably some rear end in a top hat making things more complex than they need be to justify how smart they are.

"I'm bored and this is all I have to do! Let's see how many lines of code I can make it..."

Aredna
Mar 17, 2007
Nap Ghost

UberJumper posted:

code:
b(l1, k1, j1 + 1);

UberJumper posted:

I dug around and looked at b.

Theres two b's
code:
public final double b(int i1)
code:
public final void b(int i1, int j1)

I think there may be a 3rd be somewhere that you missed... looks like he is using 3 parameters in every function call.

RoadCrewWorker
Nov 19, 2007

camels aren't so great
Whats weird is that l1 in b(int,int) is declared int, but then is assigned the return value of the double b(int) method. Funny he wasnt forced to cast there, considering he probably had no clue how basic types work and just "used the most exact one wherever possible to get rid of all those pesky errors" so he creates/wraps everything as doubles, but then needs to add casts to allow them as array indices. :suicide:

Since all variables are ints and should be passed by value, doesnt the part of a you posted just do this?
code:
b(l1, a(i1, j1), j1 + 1);
b(l1, c(i1, j1), j1 + 1);
b(l1, i1 - 1, j1);
b(l1, i1 + 1, j1);
b(l1, a(i1, j1), j1 - 1);
b(l1, c(j1, i1), j1 - 1);
Yeah, im kinda curious what that third void b(int?,int,int) does.

RoadCrewWorker fucked around with this message at 19:16 on Feb 23, 2009

SLOSifl
Aug 10, 2002


It's probably been obfuscated (by a very ambitious obfuscator) if you're sure it hasn't been decompiled.

zergstain
Dec 15, 2005

I see the class is called "d".

Is the a() being called in that code snippet an overloaded version of the a() that snippet is from, or is there an early return above that part?

Adbot
ADBOT LOVES YOU

UberJumper
May 20, 2007
woop
Yeah so i found the other b function, it was buried. I showed my boss some stuff, and basically told him its FUBAR. I don't think its been run through a code obfuscator, since half of the code can make sense, otherwise its the most ambitious/random obfuscator, i have ever heard of or seen.

The update (which is to add a little bit more functionality to it) has been put on hold :woop:. But i love this, so i will keep digging when i have time :)

Function B:

(this is pretty much all unmodified, i changed the employee name written in the code though)

code:
public final void b(WrapperFIXED_A l1, WrapperFIXED_B l2, int l3)
{ 
	WrapperFIXED_C cWRAP = NULL;
	if(l2 == null)
	{
		// Roger wanted me to make sure that this cant happen if it does anyways
		String checkIT = new String(l1.VALUE())
		if(checkIT == NULL)
		{
			throw RuntimeException("CRTIAL ERROR! THIS CANNOT HAPPEN!!!!!");
		}
		// MAKE SURE
		else if(checkIT != NULL)
		{
			return;
		}
		else
		{
			return;
		}
		return;
	}
	// Gte rid of stupid roundin
	if(l1.CALC((double)l3 * 0.1000001D) < 40D)
	{
		//TOTAL
		//Reason 
		for(l3 = 0; l3 < 10; l3++)
		{
			l1.a += (new Double(l1.CALC((double)l3 * 0.1000001D)).doubleValue());
			l1.b += (new Double(l1.CALC((double)l3 * 0.1000001D)).doubleValue());
		}
	}
	else if(l1.CALC((double)l3 * 0.1000001D) > 40D)
	{
		for(l3 = 0; l3 <= 10; l3++)
		{
			// STUPID JAVA
			// They shuod make it where:
			//	Like: new int's(temp1 AND temp2) = PROC[l3].FIRST AND PROC[l3].SECOND;
			// IT WOULD be BETTER!! 
			// Java i sstupid if i dont cast then it might give me back a boolean or somthing, if FIRST is 0 or 1 it will give me A BOOLEAN!!!!
			//This will crash.
			//
			int temp1 = (int)PROC[l3].FIRST;
			int temp2 = (int)PROC[l3].SECOND;
			double d2;
			l1.RET = (int)((d2 = l2.a + CONSTANTS.getCONSTANTVARIABLE(new String("K"))) / 22D);
			l1.RETSECOND = a(l2.b + L);
			int constantKVALUE = new Integer(CONSTANTS.getCONSTANTVARIABLE(new String("K"))).intValue();
			if(CHECK_VALUE(l1.a, l1.b) && PROC[l1.a][l1.b] == -1 && (l1.a % 2 == 1 && l2.a + constantKVALUE > 0D) &&
			 constantKVALUE >= 11D && (l1.a % 2 == 0 && constantKVALUE < (double)PROC[216] || constantKVALUE <= (double)PROC[216] - 11D))
			{
				String constantUSED = new String("K");
				//MAKE WRAP!
				cWRAP = new WrapperFIXED_C(new String("CLIMATE_CHECKER"), temp1, temp2, constantUSED);
				//CHECK to makje sure it was built
				if(cWRAP.GETVALUE() == "CLIMATE_CHECKER")
				{
					//OKAY
				}
				else
				{
					throw new RuntimeException("CRITICAL ERROR NOT EQUAL!!!!!!!!");
				}
			}
		}	
	}
	else
	{
		//JUST in case it goes bad
		throw new RuntimeException("CRITICAL ERROR SHOUDLDNT BE");
	}
	//IF WE MADE it this far we update GLOBAL variables with new CWRAP!
	//WE make sure its CWRAP.
	PROC[3] = (WrapperFIXED_C)cWRAP;
	//THERE fixed this.
	
	//TODO:
	// FIX BUGS
	// But it si done!
}
:???:

I like the nice little, rant though. It made me warm and fuzzy.

*EDIT*

Fixed it so it doesnt destroy the page.

*EDIT2*

Sigh, is there a better way to do this? I cant stop it from destroying this page.

UberJumper fucked around with this message at 03:00 on Feb 24, 2009

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