SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 07/04/2014, 08:22 AM   #1
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,289
Reputation: 311
Default Worst code you've written

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 -
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
RajatPawar is offline   Reply With Quote
Old 08/04/2014, 07:01 AM   #2
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,289
Reputation: 311
Default Re: Worst code you've written

Okay, are you guys telling me you were born coders? I am interested to see what experienced coders once looked like!
RajatPawar is offline   Reply With Quote
Old 08/04/2014, 09:24 AM   #3
GWMPT
High-roller
 
Join Date: Nov 2012
Location: Portugal.
Posts: 1,020
Reputation: 287
Default Re: Worst code you've written

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

Last edited by GWMPT; 08/04/2014 at 05:57 PM.
GWMPT is offline   Reply With Quote
Old 08/04/2014, 10:18 AM   #4
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,996
Reputation: 2647
Default Re: Worst code you've written

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:
Code:
robmoney = ((PlayerStats[target][pCurCash]/10) > 50000) ? 50000  : robmoney;
which has since been rewritten as
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.
__________________
Vince is offline   Reply With Quote
Old 08/04/2014, 10:23 AM   #5
Kyle
High-roller
 
Kyle's Avatar
 
Join Date: Mar 2009
Location: United Kingdom
Posts: 2,390
Reputation: 314
Default Re: Worst code you've written

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:
Code:
robmoney = ((PlayerStats[target][pCurCash]/10) > 50000) ? 50000  : robmoney;
which has since been rewritten as
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!
Kyle is offline   Reply With Quote
Old 08/04/2014, 12:59 PM   #6
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,289
Reputation: 311
Default Re: Worst code you've written

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!
RajatPawar is offline   Reply With Quote
Old 09/04/2014, 06:13 AM   #7
AssMunchingFool
Banned
 
Join Date: Jan 2013
Posts: 61
Reputation: 4
Default Re: Worst code you've written

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?
AssMunchingFool is offline   Reply With Quote
Old 09/04/2014, 12:34 PM   #8
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,206
Reputation: 497
Default Re: Worst code you've written

I use 144 for perfect length.

Worse code, since everyone's talking about money and robbing player command..

Code:
robcash = (PlayerInfo[id][Money] / 100) * randpercent;
 		if(robcash == 0) {
 		    robcash = random(PlayerInfo[id][Money]);
 		}
 		start:
		if(robcash > 50000 && PlayerInfo[playerid][pCivilianSkill] != SKILL_CON_ARTIST)
		{
			robcash /= 2;
			goto start;
		}
        start2:
		if(PlayerInfo[playerid][pCivilianSkill] == SKILL_CON_ARTIST && robcash > 400000)
		{
			robcash -= (robcash - 400000);
			goto start2;
		}
Kar is online now   Reply With Quote
Old 12/04/2014, 03:33 AM   #9
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,416
Reputation: 1224
Default Re: Worst code you've written

Code:
PUB:AMSpawn(playerid)
{
    if(PlayerJustConnected[playerid] == 2) PlayerJustConnected[playerid] = 0;
	if(NumUpdateRequests[playerid] > 0 || IsPlayerConnected(playerid) == 0 || MissionMode == 0) return 1;

Fucking idiot Pottus
Pottus is offline   Reply With Quote
Old 12/04/2014, 04:09 AM   #10
admiralspeedy
Little Clucker
 
Join Date: Jul 2012
Posts: 44
Reputation: 1
Default Re: Worst code you've written

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:
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...
admiralspeedy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worst code snippets you encountered Misiur Everything and Nothing 36 01/05/2015 03:21 AM
What if SA-MP was written in...? ACI Everything and Nothing 56 19/03/2014 07:22 AM
Replace what's written in the file Semo Scripting Help 0 12/03/2014 01:22 PM
What language was SA written in? glbracer Everything and Nothing 4 07/04/2013 07:12 PM
[Tool/Web/Other] JSA-MP - SA-MP library written in Java. Faab234 Tools and Files 8 17/07/2011 09:54 AM


All times are GMT. The time now is 03:42 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.