Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Share the worst code you have ever seen...  (Read 7222 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Posted 2004-11-17 23:47:55 »

During my J2ME porting & localising endeavours I've come into contact with some unbelievably bad code.
Is it just the norm? or is J2ME particularly well off in terms of bad coders?

Lets see some of the abominations you peeps have come into contact with too ^_^

Heres a few to get started :-

1  
Thread Thread = new Thread(Thread());


And it even compiles :d

1  
2  
3  
4  
5  
public static Graphics CurrentGraphics;
public void paint(Graphics g)
{
   CurrentGraphics = g;
}


When you see that, you know your in for a porting nightmare :S

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Line 300: public void doGame()
{
...
...
Line 2300: if(a<q & d>=j) return;
...
...
Line 4571: if(true) return;
...
...
Line 6784: }


Nothing like methods that span 25 pages, have misc returns throughout, and have huge areas of dead code.

1  
2  
3  
4  
public void save_LOAD_data(boolean b)
{
....
}


save/load pah, its all the same - lets chuck both in the same method!
Naming convention? what naming convention!

1  
CONST_STR_5 = 7 - 3;


This is a personal favourite of mine ^_^
and suprising how often you see it!

1  
FILE_LENGTH--;


I like changing constants too! o_0

1  
2  
3  
4  
5  
class Game
{
   public static int i,j,l,z,x,k,y,v,w,j;
   ......
}


Death used to terrify me, now it seems like a peaceful escape from the horror of tracing bugs in programs like the above =/


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
switch(a)
{
   case 1:
   return 2;
   case 2:
   return 3;
   case 3:
   return 4;
   default:
   return a+1;
}


Must.... Kill..... Incompetent... Eastern.... European.... 'Coders'


1  
2  
3  
4  
public static final int SCR_WIDTH = 128, SCR_HEIGHT = 160;

.....
g.drawImage(img, (128-14)>>2, (159-26) >>2, g.TOP | Graphics.LEFT);


Constants are such a good idea..... but using them all the time? that would just require too much effort!






Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #1 - Posted 2004-11-17 23:52:49 »

I'd love to post the worst code I've ever seen, but unfortunately that would require posting about 50% of my company's IP...

Hellomynameis Charlie Dobbie.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2004-11-17 23:56:52 »

CONST_STR_5 \Grin/

That switch thingy is also... creative Cheesy

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #3 - Posted 2004-11-17 23:58:10 »

Just a few 1liners then Wink

I won't tell if you don't Roll Eyes

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2004-11-18 01:21:18 »

1  
2  
3  
4  
public void processKeyEvent(KeyEvent ke) //thx Abuse! :D
{
      controls[ke.getKeyCode()&0xFF] = (ke.getID()==KeyEvent.KEY_RELEASED)?0:1;
}


Heh. Just kidding Grin

Hm...well... the code from TinyRivers is actually rather scary for the most part. Can't even decide what to paste... it's all scary :>

/me looks through old code...

Oh... that's cute Cheesy
1  
money[who]=howmany;


and the rest is... err Embarrassed

An insane mix of german/english/french comments/variables... horrible structure... and no naming convention or anything like that...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
[...]
class MoiListener implements ActionListener
      {
      public void actionPerformed(ActionEvent e)
            {                                                                  
            JFrame f=new JFrame();
            dbug.outmsg("Player "+String.valueOf(activePlayer+1)+" hat gewürfelt");
            if(spieler[activePlayer].getPosition()==40)      //spieler im knast
                 {
                  String option;
                  do
                        {
                        //show stats
                       info.malflaeche.setCubes(0,0); //let the cubes grin ;)
                       info.txtSumme.setText("-");
                        info.txtPlayer.setText(String.valueOf(activePlayer+1));
                        info.txtMsg.setText("Knast");//just for info
                       info.txtMoney.setText(String.valueOf(spieler[activePlayer].getGeld()));
[...]


See? And now imagine there are 5k lines of that stuff. *shudder*

Well, it was my first somewhat bigger java program (featuring a total of 27 classes, a txt file and 21 images). It was somewere in 2000 where you had fun with 1.2's BSODs whenever you did some DB stuff (fortunately 1.3 came out by that time). The timeframe was 3 months and I also learned java in during that time (the architecture is totally "one way" and it's quite odd that it actually works).

My god... I'm so ashamed now Sad

Ok. That connect 4 game where I used getpixel (TurboC) for looking up the fields was also a major wtf Grin (I hadn't known how to use 2d arrays... well, it worked and I also had some kind of ok-ish ai.)

弾幕 ☆ @mahonnaiseblog
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2004-11-18 05:29:26 »

Careful, I got into trouble last time I tried to say that using a naming convention and attempting to write decent code was a good idea... Cheesy

Kev


Offline ap_kelly

Junior Member




Java rocks!


« Reply #6 - Posted 2004-11-18 11:27:01 »

1  
2  
3  
4  
5  
String name = "bob"

name = "";

System.out.println(name);


I was then asked why the name was always blank,  I explained that line 2 set it to empty string after the initialisation. I was then asked if the order of the instructions was important!!!!

I didn't know how to reply to that, I was just very quiet for about 15 mins, rubbing my temples as I walked away.

Andy

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #7 - Posted 2004-11-18 12:30:20 »

Worst I saw was on a commercial game, looking over a friend's shoulder (I was just visiting their "office" at the time), wondering what they were wimpering about.

Code something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
static int YES_HE_IS = 3;
private boolean r; -- nb, this stood for "the real variable"; you'll see why later...

...(assigns to r somewhere completely different)...

int boss = 5;
int gimp = YES_HE_IS;
...

...(now we get to the actual main code: )
int low_paying_bastard = 2;

if( r || boss == (gimp + low_paying_bastard) )
{
  ...
}


Names have been changed to protect the innocent (replace "boss" with the name of someone at the company...).

And other "creative" statements constructed around similar concepts Smiley

malloc will be first against the wall when the revolution comes...
Offline Middy

Junior Member




Java games rock!


« Reply #8 - Posted 2004-11-18 12:42:46 »

Well not as funny as the rest of the stuff. I'll post some of my own trash code :-)

I am too lazy to implement a matrix class in my own engine, and too lazy to change the code to use LWJGl util lib. So here is an ugly hybrid. I know.. it sucks
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
      //transforming the modelGunvector to a worldvector
           Matrix4f matrix = new Matrix4f();
            matrix.load(posrot.getRotationTranslationMatrix());
            Vector4f gunPoint = new Vector4f();
            gunPoint.x =firedByGunPoint._x;
            gunPoint.y =firedByGunPoint._y;
            gunPoint.z =firedByGunPoint._z;      
            Vector4f pos = Matrix4f.transform(matrix,gunPoint,null);
            Vector3 position = new Vector3();
            position._x = pos.x+ posrot.get_position()._x ;
            position._y = pos.y+ posrot.get_position()._y ;
            position._z = pos.z+ posrot.get_position()._z ;
            posrot.set_position(position);

When do I get my makeMyGameAsILike() extension?
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #9 - Posted 2004-11-25 13:01:19 »

Quote

           if( FE_Task == 2 )
                 FE_Task2( );
           else if( FE_Task == 4 )
                 FE_Task4( );
           else if( FE_Task == 0 )
                 FE_Task0( );
           else if( FE_Task == 1 )
                 FE_Task1( );
           else if( FE_Task == 3 )
                 FE_Task3( );
           else if( FE_Task == 5 )
                 FE_Task5( );


meaningful variable/method names?
named constants?
switch statement?
structured code?

/me has very little hair left.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Tzan

Junior Member





« Reply #10 - Posted 2004-11-26 16:01:04 »

Wow! and people got paid to write some of this stuff? Makes me feel rather good about my skills. Maybe I should try to get a programming job Smiley
Online princec

JGO Kernel


Medals: 364
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #11 - Posted 2004-11-26 16:27:02 »

I used to dread having to look through the Yanks' code years ago in one of those "We don't do development in the UK" software ops that I worked at. Amazing things like:
1  
2  
for i = 1 to 100000000
next

etc.

Cas Smiley

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #12 - Posted 2004-11-28 00:38:16 »

I just saw a bit of code use to convert a number from a hexidecimal string to an integer.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
char a = next input char;
switch(a)
{
case '0':
 i += 0;
case '1':
 i += 1;
case '2':
 i += 2;
case '3':
 i += 3;
case '4':
 i += 4;
case '5':
 i += 5;
case '6':
 i += 6;
case '7':
 i += 7;
case '8':
 i += 8;
case '9':
 i += 9;
case 'a':
 i += 10;
case 'b':
 i += 11;
case 'c':
 i += 12;
case 'd':
 i += 13;
case 'e':
 i += 14;
case 'f':
 i += 15;
}


didn't even handle uppercase Smiley

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #13 - Posted 2004-11-28 01:19:47 »

There's also no break... uhm... and there's also Integer.parseInt(bla,16)... and... Grin

弾幕 ☆ @mahonnaiseblog
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #14 - Posted 2004-11-28 12:29:41 »

err..yeah -- the breaks were there, I just typed it quick.  It was also C code.  I also left out the setup and final lines.

Offline cep21

Junior Member




Java games rock!


« Reply #15 - Posted 2004-11-29 15:34:44 »

I remember in C there was this to swap two numbers

1  
2  
3  
void swap(int & a,int & b){
a^=b^=a^=b;
}
Offline shmoove

Junior Member




Doh!


« Reply #16 - Posted 2004-11-30 05:57:22 »

That's actually a well known method, it's just written in a confusing manner. Looks like the programmer was trying to save line numbers. But I do think he has to check that the variables are not the same one or there could be some trouble.
In any case, it's good to know because they like to ask this question on job interviews (how do you swap two numbers without a temp).

shmoove
Offline Raghar

Junior Member




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #17 - Posted 2004-11-30 18:32:04 »

He used XOR for exchanging?
Why? xchng eax, ebx wasn't available?
Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #18 - Posted 2004-12-07 08:06:22 »


this was seen in java code ...

this = null;

Huh Tongue Lips Sealed
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #19 - Posted 2004-12-07 09:57:33 »

Quote
He used XOR for exchanging?
Why? xchng eax, ebx wasn't available?



Changes registers, not variables, and is not available from C/C++/Java!

The xor method has to advantage that no additional register/memory is needed, thus may prevent from another memory page loaded to cache.

Love that!

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #20 - Posted 2004-12-07 09:58:57 »

If you wanna see ugly code, take anything that is produced in my company I'm forced to work for ....  Tongue  Embarrassed  Cry


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #21 - Posted 2004-12-07 11:03:32 »

Quote
If you wanna see ugly code, take anything that is produced in my company I'm forced to work for ....  Tongue  Embarrassed  Cry

Uhm, I guess they dont read these boards either?

We have a lot of nasty code in some of our j2me stuff - like methods performing differently depending on which thread called it Shocked. but it's a required thing to shave bytes :/

Offline shmoove

Junior Member




Doh!


« Reply #22 - Posted 2004-12-08 07:02:57 »

Quote

this was seen in java code ...

this = null;

Huh Tongue Lips Sealed


Now, that's just golden!

shmoove
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #23 - Posted 2004-12-08 07:20:22 »

Quote
Now, that's just golden!


Not to mention uncompilable, "this" not being a variable and all... Grin

Hellomynameis Charlie Dobbie.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #24 - Posted 2004-12-09 08:23:14 »

Actually, u can write java like that, you just have to write bytecode directly.

The 1st local variable of an instance method contains a reference to this - however there is nothing wrong with reassigning it to reference some other object.

Decompilers usually have problems translating that back into meaningful java (as it is unexpressable through the java syntax) hence you get assignment to this.

Heres a new implementation of the Rectangle class I just found in some code im working on :-

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      //default constructor
     public Rect()
      {
            mLeft = 0;
            mTop = 0;
            mRight = 0;
            mBottom = 0;
            mWidth = 0;
            mHeight = 0;
      }

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #25 - Posted 2004-12-09 09:58:48 »

Quote

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      //default constructor
     public Rect()
      {
            mLeft = 0;
            mTop = 0;
            mRight = 0;
            mBottom = 0;
            mWidth = 0;
            mHeight = 0;
      }


Hey if you have CPU use it as much as you can... always a great way to code  Grin

Offline MasterDirk

Senior Newbie




Somebody set up us the bomb...


« Reply #26 - Posted 2004-12-09 10:03:42 »

I should dig up some of my old assembly-code. That's a really ugly language, and dangerous as well Smiley
Offline crystalsquid

Junior Member




... Boing ...


« Reply #27 - Posted 2004-12-12 10:26:07 »

Quote
He used XOR for exchanging?
Why? xchng eax, ebx wasn't available?


xchg takes 3 cycles for r/r, and is non-pairable.
xor takes 1 cycle each, and IS pairable, so in the simplest case you could exchange two pairs of numbers in the time taken to 'xchg' just one. Smiley

On PII and above the xchg IS pairable, but still takes 3 cycles.

Also, there is the chance the compiler may try to xchg with a memory pointer instead of two registers. this is extremely slow and forces a memory lock to occur (>15 cycles!).

Plus, not using the temprary register means that the instructions are much easier to interleave with other operations, making the compilers job significantly easier increasing the chance that they would end up paired (taking an average of 1.5 cycles)

Google for 'Agner Fogg' - he has written what I would consider to be the bible of pentium optimisation Smiley

Quote
I should dig up some of my old assembly-code. That's a really ugly language, and dangerous as well

You should see PS2 vector microcode... 2 instructions per line, branch delay slots - yum!
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #28 - Posted 2004-12-13 10:22:49 »

Believe it or not I do have some really old code around.

Silly beginners listener code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
static int click=0;
     
      public static void main(String[] args)
      {
            ...
            frame.validate();
            Button butt = new Button("CLICK ME!");
            butt.setSize(200,40);
           
            final JLabel label = new JLabel();
            label.setText();
           
            frame.getContentPane().add(butt);            
            frame.getContentPane().add(label);
           
            frame.validate();
           
            butt.addActionListener
            (
                  new ActionListener()
                  {
                        public void actionPerformed(ActionEvent e)
                        {
                              click++;
                              if(click == 1)
                              {
                                    label.setText("1 click");
                              }
                              else
                              {
                                    label.setText("else");
                              }
                        }//public void
                 }//create new action listener
           );//adding action listener
     }

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline zarzus

Innocent Bystander




Java games rock!


« Reply #29 - Posted 2004-12-15 13:29:11 »

Hi,
I've found code like the following in my company:

1  
2  
3  
4  
5  
String a = ....

[...]

String b = (String) a.toString();

We want to be sure that it will be an String....

and:

1  
2  
3  
4  
5  
Vector v = new Vector();
if(v != null)
{
.....
}

It seems to me a bit paranoic....

Funny thread  Wink
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (28 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!