Worst code you've written
#1

I was just looking back at the CNR server I'd started upon a year ago, completed till 50% or something and gave up. I literally let out a cry of surprise because it was REALLY crappy. The coding standards I'd used, the methods I'd tried and the layout, the general feel, zero modularisation and stuff. Have you ever come across code of yours that you feel... must vanish into the past... like a dark secret.. never to come back again...?

I feel like I've come a VERY long way from being that guy, to now! Do you feel so?

Example of what I did in that script -
pawn Code:
new Float: store_array_1[][] =
{
      entry_co-ords,
      exit_co-ords
},
      store_1_enter_cp,
      store_1_exit_cp;

public OnGameModeInit()
{
      store_1_cp = CreateDynamicCP(...);
      ...
      return 1;
}

public OnPlayerEnterDynamicCP(playerid, cpid)
{
     for(new i = 0 ... )
     {
           if( cpid == store_1_enter_cp )
           {
            .....
Now I know that there are TONS of SO many better ways of doing this. How could I have been so stupid just one year ago? Probably I'll say the same the next year
Reply
#2

Okay, are you guys telling me you were born coders? I am interested to see what experienced coders once looked like!
Reply
#3

When I started[back to 2010] witing bad code was one of my best skills.
I had a lot of mistakes in it, one of them was something like below:
pawn Code:
public OnPlayerRequestClass(playerid, classid) {
    if(classid == 1)
        PlayerClass[playerid] = CITIZEN;
    else if(classid == 2)
        PlayerClass[playerid] = CITIZEN;
    ......
    else if(classid == 19)
        PlayerClass[playerid] = TERRORIST;
    else
        PlayerClass[playerid] = TERRORIST;
}
I wrote like, almost 20 if statements, instead of using the > < operators.
So... yeah, every day we develop something, we are training, and automatically, we are learning new ways of doing something.
Reply
#4

The oldest backup I still same to have is for 0.3b from late 2010. Though this still looks pretty much okay. I've since rewritten some code because of the discovery of functions that I never knew existed, such as clamp(). I had been doing this:
pawn Code:
robmoney = ((PlayerStats[target][pCurCash]/10) > 50000) ? 50000  : robmoney;
which has since been rewritten as
pawn Code:
robmoney = clamp((PlayerStats[target][pCurCash]/10), 0, 50000);
Now also excessively using STREAMER_EXTRA_ID for easy assignment of a value to a pickup. Money, for instance. Saves a load of headaches because I no longer have to use bloated arrays to keep track of which pickupid has which value.
Reply
#5

Quote:
Originally Posted by Vince
View Post
The oldest backup I still same to have is for 0.3b from late 2010. Though this still looks pretty much okay. I've since rewritten some code because of the discovery of functions that I never knew existed, such as clamp(). I had been doing this:
pawn Code:
robmoney = ((PlayerStats[target][pCurCash]/10) > 50000) ? 50000  : robmoney;
which has since been rewritten as
pawn Code:
robmoney = clamp((PlayerStats[target][pCurCash]/10), 0, 50000);
Now also excessively using STREAMER_EXTRA_ID for easy assignment of a value to a pickup. Money, for instance. Saves a load of headaches because I no longer have to use bloated arrays to keep track of which pickupid has which value.
Wow, I never knew about STREAMER_EXTRA_ID. That is something to remember!
Reply
#6

Quote:
Originally Posted by KyleSmith
View Post
Wow, I never knew about STREAMER_EXTRA_ID. That is something to remember!
True, never thought of such an use! I still remember the old days when I used 256 cells for client messages because everyone on here did it. How far we've come!
Reply
#7

Quote:
Originally Posted by Rajat_Pawar
View Post
True, never thought of such an use! I still remember the old days when I used 256 cells for client messages because everyone on here did it. How far we've come!
now everyone uses 128?
Reply
#8

Quote:
Originally Posted by Kikito
View Post
When I started[back to 2010] witing bad code was one of my best skills.
I had a lot of mistakes in it, one of them was something like below:
pawn Code:
public OnPlayerRequestClass(playerid, classid) {
    if(classid == 1)
        PlayerClass[playerid] = CITIZEN;
    else if(classid == 2)
        PlayerClass[playerid] = CITIZEN;
    ......
    else if(classid == 19)
        PlayerClass[playerid] = TERRORIST;
    else
        PlayerClass[playerid] = TERRORIST;
}
I wrote like, almost 20 if statements, instead of using the > < operators.
So... yeah, every day we develop something, we are training, and automatically, we are learning new ways of doing something.
Mind explaining how < and > eliminated the need for if statements? I'd like to know...
Reply
#9

When I look at my old Dragon Ball mode.....
Reply
#10

Quote:
Originally Posted by admiralspeedy
View Post
Mind explaining how < and > eliminated the need for if statements? I'd like to know...
Code:
public OnPlayerRequestClass(playerid, classid) {
    if(classid < 10)
        PlayerClass[playerid] = CITIZEN;
    else
        PlayerClass[playerid] = TERRORIST;
}
On topic:
Very first gamemode, worst code in the entire file, good days when scripting was something new and intresting: https://docs.******.com/document/d/1...it?usp=sharing
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)