HOW-To: Develop your own scripting style
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOW-To: Develop your own scripting style

Started by pHaTTy, 20 April, 2004, 12:11:22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pHaTTy

HOW-To: Develop your own scripting style
-----------------------------------------

ok alot of ppl asked me why there is something called scripting style if all scripts look the same and are set out the same, so here is how-to on devel ur own scripting style..and lol, im bored atm and not upto doing actually any scripting so here goes...

Hello = 1;

if Hello == 1 then
	doafunction()
else
	doafunction()
end;

ok heer an example, a simple way of scripting ^

another way u can do it is

Hello = 1;

if Hello == 1 then doafunction()
else doafunction() end;

depening on u, it can be easier or harder to read, for me its more simple more compact less code to read down.....the reason for this is, code is not compile by style as long as it understands what the code means it compiles it, they are basically commands for the compiler to generate the code

function Main()
	doanotherfucn()
	hello = 2;
	Kicksomeonesass()
	destroysntax()
	killptokax = 2;
	Callkill()
end


ok just a lame main function now lets put it all in one line or spread out in differ formats, so it can look less messy

function Main() doanotherfucn()	hello = 2; Kicksomeonesass()
	destroysntax() killptokax = 2; Callkill()
end

here is 1 way

function Main()
doanotherfucn()	hello = 2; Kicksomeonesass() destroysntax() killptokax = 2; Callkill()
end

heer is another

function Main()
	doanotherfucn()	hello = 2;
	Kicksomeonesass() destroysntax()
	killptokax = 2; Callkill()
end

and another =)

now what about return 1 and end etc ok lets look

i will use a script i wrote earlier for the example

--//NickChanger 0.02 by Phatty
--//Under development lol (bored)

--//Globals
BOT = ".D.R.";
Command1 = "!nick";
Command2 = "!clear";

function Main()
	Nick = {}
end;

function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then
		local data=strsub(data,1,strlen(data)-1) 
		local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
		local s,e,msg = strfind(data, "%b<>%s+(.+)")
		if strlower(cmd) == Command1 and user.bOperator then
			local s,e,newnick = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if newnick then
				Nick[user.sName] = newnick;
				user:SendData(BOT,"You have changed your chat nick to "..newnick)
				return 1;
			end;
		elseif strlower(cmd) == Command2 and user.bOperator then
			Nick[user.sName] = nil;
			user:SendData(BOT,"You have cleared your fake nick!")
			return 1;
		end;
		local sName = Nick[user.sName]
		if sName then
			SendToAll(sName,msg)
			return 1;
		end;
	end;
end;

ok here is script and look standard coding style, now lets stop it going right down the page and change the ends

--//NickChanger 0.02 by Phatty
--//Under development lol (bored)

--//Globals
BOT = ".D.R.";
Command1 = "!nick";
Command2 = "!clear";

function Main()
	Nick = {}
end;

function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then
		local data=strsub(data,1,strlen(data)-1) 
		local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
		local s,e,msg = strfind(data, "%b<>%s+(.+)")
		if strlower(cmd) == Command1 and user.bOperator then
			local s,e,newnick = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if newnick then
				Nick[user.sName] = newnick;
				user:SendData(BOT,"You have changed your chat nick to "..newnick)
				return 1;
			end;
		elseif strlower(cmd) == Command2 and user.bOperator then
			Nick[user.sName] = nil;
			user:SendData(BOT,"You have cleared your fake nick!")
			return 1;
		end;
		local sName = Nick[user.sName]
		if sName then
			SendToAll(sName,msg)
			return 1;
end; end; end;


put lets also drop down the variables and the return 1 with the ends

--//NickChanger 0.02 by Phatty
--//Under development lol (bored)

--//Globals
BOT = ".D.R."; Command1 = "!nick"; Command2 = "!clear";

function Main()
	Nick = {}
end;

function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then
		local data=strsub(data,1,strlen(data)-1) 
		local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
		local s,e,msg = strfind(data, "%b<>%s+(.+)")
		if strlower(cmd) == Command1 and user.bOperator then
			local s,e,newnick = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if newnick then
				Nick[user.sName] = newnick;
				user:SendData(BOT,"You have changed your chat nick to "..newnick)
			return 1; end;
		elseif strlower(cmd) == Command2 and user.bOperator then
			Nick[user.sName] = nil;
			user:SendData(BOT,"You have cleared your fake nick!")
		return 1; end;
		local sName = Nick[user.sName]
		if sName then
			SendToAll(sName,msg)
return 1; end; end; end;


ok and lets do the rest

[code]
--//NickChanger 0.02 by Phatty
--//Under development lol (bored)

--//Globals
BOT = ".D.R."; Command1 = "!nick"; Command2 = "!clear";

function Main()	Nick = {} end;

function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then local data=strsub(data,1,strlen(data)-1) 
		local s,e,cmd = strfind(data, "%b<>%s+(%S+)") local s,e,msg = strfind(data, "%b<>%s+(.+)")
		if strlower(cmd) == Command1 and user.bOperator then local s,e,newnick = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if newnick then	Nick[user.sName] = newnick;
				user:SendData(BOT,"You have changed your chat nick to "..newnick)
			return 1; end;
		elseif strlower(cmd) == Command2 and user.bOperator then Nick[user.sName] = nil;
			user:SendData(BOT,"You have cleared your fake nick!")
		return 1; end;local sName = Nick[user.sName]
		if sName then SendToAll(sName,msg)
return 1; end; end; end;

ok now u have 1 compact script, harder or easier to read, dunno for you but i find it easier, saves keep changing line =)

it is possible to write it all in 1 line but i aint gonna do that make the page to large lol, ok enjoy updating ur scripting style, and hope you's find a better way for you to script, more comfortable =)
Resistance is futile!

NotRabidWombat

#1
Ask any programmer, compact is BAD.

1) Tabify properly.
2) One command per a line.
3) Use meaningful variable *names*.
4) Don't use globals.
5) Stop using 2 instead of to (u instead of you, etc). You're NOT l33t. Oh, this is posting style.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

QuoteOriginally posted by NotRabidWombat
Ask any programmer, compact is BAD.

1) Tabify properly.
2) One command per a line.
3) Use meaningful variable.
4) Don't use globals.
5) Stop using 2 instead of to (u instead of you, etc). You're NOT l33t. Oh, this is posting style.

-NotRabidWombat

5) Stop using 2 instead of to (u instead of you, etc). You're NOT l33t. Oh, this is posting style.

haha since when did 2 become elite? and u?

its short hand way of typing,

7h47 pR084b1y \/\/0[_]1D 8? D1##3R =)

2) One command per a line.

dont matta, it dont make any differ to the compiler, and if ya say it is, well ya can say what ya like =) free world for opinions =)

hmm lets see

elite

to = ']['[]
you = Y[][_]  (cant do the elite y)

so try make sure ya knwo what ya talking bout first, many ppl use u for you and 2 for to, says typing more then ya have 2 =)
Resistance is futile!

plop

QuoteOriginally posted by NotRabidWombat
Ask any programmer, compact is BAD.

1) Tabify properly.
2) One command per a line.
3) Use meaningful variable.
4) Don't use globals.
5) Stop using 2 instead of to (u instead of you, etc). You're NOT l33t. Oh, this is posting style.

-NotRabidWombat
number 5 is somehow hammered into me, when i make a help menu or some other feedback from the scripts i reguarly have TO go back and change the 2's.
1-4 are going fine and are indeed a must, makes it a lot easyer 2 read, and saves you from thinking what a variable was doing when you see the code back after a while.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

[NL]Pur

Quote1) Tabify properly.
2) One command per a line.
3) Use meaningful variable.
4) Don't use globals.
5) Stop using 2 instead of to (u instead of you, etc). You're NOT l33t. Oh, this is posting style.


i also think that rule number 5,  not really matters.
i often use the 2 when converting stuff
like,   avi2mpg and i think it's readable

NotRabidWombat

#5
The fifth comment was a criticism on using compact instead of clear. Posts are more difficult to read when you use b4, 2, u, r, etc. Likewise, code is more difficult to read when you write compact rather than readable ie: "let's just remove all white space".

I guess some did not get the joke.

Pur. What if I want mpeg2avi? Is that mpeg2 or mpeg? Would I write mpeg22avi? Is there a new mpeg22 out? What if I wrote MpegToAvi. Hey, that's only one character longer, AND there's no confusion.

Nah, I must be CRAZY.

Phatty.
"7h47 pR084b1y \/\/0[_]1D 8? D1##3R =)"
Yeah, how much time did you waste typing that out and how much time am I going to waste trying to decypher it.

"many ppl use u for you and 2 for to, says typing more then ya have 2 =)"

Many people are lazy and stupid.

I know what is leet is. I DESPISE it. I also recognize that this lazy writing stems from its creation. I DESPISE it just as much.

"dont matta" "ppl"

Thank you for proving my point

"so try make sure ya knwo what ya talking bout first"

Maybe you should learn a programming style (and how to type words) before posting a "HOW-TO" on style.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

LoL

heh heh, now i like those last 2 comments, but ya gotta try better then that lol

and ehmmm, actually i write in c, c++, vb, and php, if that aint enough tell me =)

oh btw the os i wrote was not completed that was in asm n c =)

mind i have to admit asm is a real bi7ch

oh annddd maybe i can ask em when i get to london, what they think about styles when they writing games, we will see =)

and the elite well didnt take no time at all and decypher dont have to you can read it liek anyother words =)
Resistance is futile!

YetAnotherStylist

Interesting, you only need to learn like 36 relation-mappings (26 letters and 10 numbers) between characters
and other encoded characters to classify yourself as "elite". Why arent we all "elite" then?
Just for the child in yourself: all you are doing by writing this "elite-style" is to create an empty hull.
The reason is most likely that you are not qualified (e.g. this does not equal elite) in any other way of life.

And about your collection of programming "skills":
Just by the way, the relationship between "being qualified" and "showing off how many programming
languages one is 'expert' in" is likely to be in inverse proportion.

Just my 2 (yes it is TWO, not TO) cents ...

pHaTTy

QuoteOriginally posted by YetAnotherStylist
Interesting, you only need to learn like 36 relation-mappings (26 letters and 10 numbers) between characters
and other encoded characters to classify yourself as "elite". Why arent we all "elite" then?
Just for the child in yourself: all you are doing by writing this "elite-style" is to create an empty hull.
The reason is most likely that you are not qualified (e.g. this does not equal elite) in any other way of life.

And about your collection of programming "skills":
Just by the way, the relationship between "being qualified" and "showing off how many programming
languages one is 'expert' in" is likely to be in inverse proportion.

Just my 2 (yes it is TWO, not TO) cents ...


hmm wel to you, i dont class myself as elite, in fact i dont even type it, i type what i type and dont call it elite, but im showing that he is wrong by saying its l33t by saying 2 instead of to or two etc........
Resistance is futile!

[NL]Pur

QuotePur. What if I want mpeg2avi? Is that mpeg2 or mpeg? Would I write mpeg22avi? Is there a new mpeg22 out? What if I wrote MpegToAvi. Hey, that's only one character longer, AND there's no confusion.

ok, i can see the confusion :)


some other points:

i think that a short comment at certain points is nice.
i hate comment that are almost stories, some ppl tend todo it at the beginning of there file.

about the varibles names, if you have international
group of programmers it's harder too understand the
code if they use there own language for varible names.
(better use english).

i think an (un)written rule in programming concerning
variable names is that the first letter of the first word is
lowercase, all words following are uppercase. for
example:

with methods

getInstance()


variable names:
justAnotherString








oh , yetAnotherThing it's nice to use 1 nickname when
posting on 1 forum.

NotRabidWombat



Saying I am incorrect regarding my l33t statement does not change the fact that writing/coding in this manor is lazy and thoughtless.

If someone can not write clear, coherent sentences, I doubt that person can effectively code.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

NotRabidWombat

Pur.

The lower case first letter of variables is typically intended to describe the type of varible ie:

sPersonName - string
iPersonAge - signed int
ulPersonSocialSecurity - unsigned long
ptrPerson - ptr

This helps with type casting and avoiding truncation.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

QuoteOriginally posted by NotRabidWombat


Saying I am incorrect regarding my l33t statement does not change the fact that writing/coding in this manor is lazy and thoughtless.

If someone can not write clear, coherent sentences, I doubt that person can effectively code.

-NotRabidWombat


hmmm well ok i admit ikinda agree with ya there, but it depends if u are working in a team, and if u are in a rush to get it done, if ya alone doing ur own project, its faster n comfortable todo it ur own way =)
Resistance is futile!

NotRabidWombat

How about this for style!

1) Put the constant in front of the variable in a comparison.

if( 1 == var ) OR if( nil ~= var )
or for you c++ guys
if( null == var)

Helps avoid accidental assignments in conditions.

2) Error handling.

There is a reason there is an assert function and type function in lua. There is also a reason for throw/try/catch in C++. Use them.

3) Comments

Comment the parameters, purpose, and return value of every function.

4) Use hash tables rather than switches (if/elseif/elseif...) blocks.

Switches are sequential and SLOW. They perform O(N). A hash table typically performs at O(1). Use them to call functions from commands.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

NotRabidWombat

Phatty,

We're not alone on projects here. Almost all source is posted here which is wonderful. People can learn, reuse, and then help. I would hate to see people develop bad programming habits.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

QuoteOriginally posted by NotRabidWombat
Phatty,

We're not alone on projects here. Almost all source is posted here which is wonderful. People can learn, reuse, and then help. I would hate to see people develop bad programming habits.

-NotRabidWombat

lets just remember, this is also a place to learn, and this was based on styles, so if people use lua for there projects like my upcoming lai project then they will have there own useful and comfortable style =)
Resistance is futile!

NotRabidWombat

"useful and comfortable style"

So why include bad styles in the HOW-TO?

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

Skrollster

QuoteOriginally posted by (uk-kingdom)pH?tt?
oh annddd maybe i can ask em when i get to london, what they think about styles when they writing games, we will see =)

Hmm.. game programers isn't too good then it comes to optimizing applications..

i would guess that they produce wores code then M$ ugly code...

pHaTTy

QuoteOriginally posted by Skrollster
QuoteOriginally posted by (uk-kingdom)pH?tt?
oh annddd maybe i can ask em when i get to london, what they think about styles when they writing games, we will see =)

Hmm.. game programers isn't too good then it comes to optimizing applications..

i would guess that they produce wores code then M$ ugly code...

lmfaooo nah, actually they do some of the best coding ive seen, and id like to know all their little coding tricks tbh, heh
Resistance is futile!

pHaTTy

QuoteOriginally posted by NotRabidWombat
"useful and comfortable style"

So why include bad styles in the HOW-TO?

-NotRabidWombat

bad style, where? to me that aint something there can be, u can code any way u like as long as when ya compile the compiler can read it fine then dont matta =)
Resistance is futile!

NotRabidWombat

#20
WHAT?!

So you think combining all source files and removing all white space would be a "fine" practice?! We might as well try to read machine language.

No, a strict, readabe style is a must. A style that limits bugs is another must.

I suppose goto's are another "fine" programming style. Who needs object oriented programming?!

tail -f /dev/forum | grep -v "pH?tt?"

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

hahaha *smirk*

hmm i would say something nice but i aint lame, so you get on with ur temper tamptrums and

its not removing all the spaces lol

if someone == blah then
            dosumit()
end;

is just as readable as

if someone == blah then dosumit() end;

heh so i thnk next thing u will complain about is () brackets etc

if (someone == blah) then
     dosumit()
end;

next to complain about ppl shud use em? i dont and wont bother no point but i know you do, its ur style it also is pretty pointless for the coding that is done here.......

lets take vb for example here:

what wud be the point of

dim something as string
dim somethingelse as long
dim RabidWombat as newobject

or wud it be easier of it was done

dim something as string, somethingelse as long, RabidWombat as newobject

so now lua:

local something = "\n";
local somethingelse = 1;
local RabidWombat = sumit:sumit()

local something = "\n"; local somethingelse = 1; local RabidWombat = sumit:sumit()

n come to think of it

local something,somethingelse,RabdiWombat = "\n",1,sumit:sumit()

abit like

something = nil;
sumitelse = nil;

better do

something,sumitelse = nil,nil


programming u have to be quick to adapt to knew styles and new languages, if u cant ur gonna be dropped like a ton of bricks, so please stfu, grow up and come into the real world, its about learning not just 'you'

if someone finds it easier to do that ^^^ in 1 line then they can go do that in there own projects its not all here just aboiut programming for ptokax lol, yea this is ptokax lua forum but you still can learn for other apps, so stop going on like a 10year old that cant get his own way.....

EDIT: 1 more thing, as i said in the orig post, its someone asked, now this thread is showing u that there is a such thing as different styles of coding, maybe good and bad for there own different reasons, but it doesnt stop ppl from knowing what those different styles are,

for example if u knew what styles are and 'own' projects were u'd realise its much easier todo ur own coding style, ive seen some of your lua code and is pretty differ,

for other ppl that use the space tabs some use the tab key....so its still another way of styling code.......this is here for everyone to read, if they go try then thats up2 them u cant control other people......if they dont then thats ok, at least they know they can do such a thing........ok no more posts on this topic.....later.....
Resistance is futile!

plop

sorry 2 say it but rabit is not the child here, it's you phatty.
ppl come here 2 learn, so teach them the correct way.
learning them a bad style of coding makes it harder for them, and harder for us 2 help.
the compiler might not have trouble reading a script, humans can.
humans write/debug the code so thats more important.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

QuoteOriginally posted by plop
sorry 2 say it but rabit is not the child here, it's you phatty.
ppl come here 2 learn, so teach them the correct way.
learning them a bad style of coding makes it harder for them, and harder for us 2 help.
the compiler might not have trouble reading a script, humans can.
humans write/debug the code so thats more important.

plop

lol, there is no proper way to code

someone doing

void something()
{
}

is same as

void something(){
}

its a style, if ur trying to tell ppl how to code, then ur the child, and this is not for n00bs its for ppl that wonder about coding styles, i have been asked and i did fullfil there request....so ur wrong also =)



looks styles that dont matta and are still readable in c++

void Check()
{
	if (Rabid == True)
	{
		Leave = True;
	}
	else //what is the point of this?
	{
		Leave = false;
	}

}
void Check()
{
	if (Rabid == True)
	{
		Leave = True;
	}
	else Leave = false;
}
void Check(){
	if (Rabid == True){
		Leave = True;
	}
	else Leave = false;
}

altho of course this a false function but wud do same thing
Resistance is futile!

Cyberia

Think everyone uses the style what's handy for him/her.
You can't put everything into standards  8)

SMF spam blocked by CleanTalk