Programming Style. Linear VS Structured

Discuss popular GCS tools like ZZT, Megazeux and Adventure Game Studio, as well as programming and other topics related to game design.
Post Reply

Programming Style?

Poll ended at Sun May 13, 2007 6:08 pm

Structured
5
83%
Linear
1
17%
 
Total votes: 6

tinman47
Lord of Gaming
Lord of Gaming
Posts: 230
Joined: Sat Feb 24, 2007 1:07 pm

Programming Style. Linear VS Structured

Post by tinman47 »

Whats your programming style.If its structured,reply STRUC,
if its linear,reply LINE,then I rank it up in 10 days.
tinman47
Lord of Gaming
Lord of Gaming
Posts: 230
Joined: Sat Feb 24, 2007 1:07 pm

Post by tinman47 »

LINE
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

there, I made it a poll. lol
tinman47
Lord of Gaming
Lord of Gaming
Posts: 230
Joined: Sat Feb 24, 2007 1:07 pm

Post by tinman47 »

Wow,thats what the little POLL button was for,thanks wardrich.
User avatar
Larry Laffer
Admin
Admin
Posts: 4143
Joined: Sun Feb 19, 2006 8:06 am
Location: Romania

Post by Larry Laffer »

lol, yeah it's obvious! :laugh:
<center>
abyss wrote:I don't even know if starcraft 1 was a windows or dos games.
</center>

ModBot™ - Faster than the speed of spam!(and always taking it to where it belongs!)
User avatar
dosraider
Admin
Admin
Posts: 9243
Joined: Tue Mar 15, 2005 2:06 pm
Location: ROTFLMAO in Belgium.

Post by dosraider »

Unruly.


Can't poll. :suspicious:
User avatar
abyss
Moloral Compass
Moloral Compass
Posts: 754
Joined: Mon Nov 06, 2006 6:13 pm

Post by abyss »

What does linear and structured mean.
<i>Formerly known as Hulk Hogan.</i>
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

Linear programming starts at the top and runs down the code until the bottom line.

Structured programming uses classes and methods. Line 3 may tell the interpreter to jump to line 300, then jump back to line 4.
User avatar
abyss
Moloral Compass
Moloral Compass
Posts: 754
Joined: Mon Nov 06, 2006 6:13 pm

Post by abyss »

I don't get it.
<i>Formerly known as Hulk Hogan.</i>
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

what don't you get?
tinman47
Lord of Gaming
Lord of Gaming
Posts: 230
Joined: Sat Feb 24, 2007 1:07 pm

Post by tinman47 »

Linear programming is when you just write a big list of code that is just stuck together and is not organized and just executes straight through,structured programming is when you organize your code into big and small blocks or paragraphs that you can call and use seperately.Do you understand now? B)
User avatar
abyss
Moloral Compass
Moloral Compass
Posts: 754
Joined: Mon Nov 06, 2006 6:13 pm

Post by abyss »

How is that useful. I really don't understand it.
<i>Formerly known as Hulk Hogan.</i>
User avatar
dosraider
Admin
Admin
Posts: 9243
Joined: Tue Mar 15, 2005 2:06 pm
Location: ROTFLMAO in Belgium.

Post by dosraider »

It's extremely usefull.

Think about a coded block, you can call it several times and jump back to the next %% line.

If you need, let's say, a specific process 20 times ( suppose here you need 500 lines or so for that process) , in stead of writing those 500 lines 20x you simply jump to the subroutine and back where you were (now yeah a line down or whatever if there is a variable input ... whatever).

It is very much used in industrial coding ( PLC - Automatisation ...) where repetitive actions are needed.
A good example are electric motors that need a starting/stopping slope , or a check if they are running/stopped before you can safely go to the next step.
You don't code such routine for 2000 motors seperately, you code one and call that one when needed.

Another example ?
Emergency stop buttons, if you ever seen those big red knobs in industry ...
Some complex machinery have hundreds of those, and some machinery needs a specific stopping routine, first shut that motor, next that one, break 1 on, next motor , break 2 on ...
You will NOT write that whole sequence for every emergency stop button, no, you write it once, and call a subroutine with an IF or an OR when such a button is hit.
User avatar
abyss
Moloral Compass
Moloral Compass
Posts: 754
Joined: Mon Nov 06, 2006 6:13 pm

Post by abyss »

I am a completely inept moron, so I still have no idea what you're talking about despite your crystal clear explaination. Forget about it.
<i>Formerly known as Hulk Hogan.</i>
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

Linear = any old book
Structured = Choose Your Own Adventure



Or, a better example... say you want to program walking to the store and back to get some peanut butter and bread...

you'll have to walk to the store open a door walk around in the store to find the bread then take the bread and walk more to find the PB, which you will also take. Then you'll want to pay for the goods, walk to the door and open it again. Then you're going to walk home...

Now, from a linear POV [missing a lot of validation checks]:

Code: Select all

do until location = store
 Move left foot
 move right foot
 get location
repeat

move left arm until hand is on door
push with arm
move left foot through door
move right foot through door
release hand from door
lower arm

do until location = peanut butter
 move left foot
 move right foot
 get location
repeat

raise right arm until right hand is on the peanut butter
place right hand on peanut butter
tighten right-hand fingers around peanut butter
raise peanut butter off shelf
bring right hand to bag
put pb in the bag
loosen right-hand fingers
take right hand off of pb
raise right arm until hand is not in bag

do until location = bread
 move left foot
 move right foot
 get location
repeat

raise right arm until right hand is on the bread
place right hand on bread
tighten right-hand fingers around bread
raise bread off shelf
bring right hand to bag
put bread in the bag
loosen right-hand fingers
take right hand off of bread
raise right arm until hand is not in bag

do until location = cash
 move left foot
 move right foot
 get location
repeat

lower left arm until left hand is in pocket
do until money in left hand = bill total
  put left hand on coin
  tighten left-hand fingers around coin
  raise arm until hand is level with cashier
  align left hand to cashier's hand
  loosen left-hand fingers off of coin
  lower left arm until left hand is in pocket
repeat

raise right arm until right hand is on bag handle
tighten right-hand fingers
raise right arm until bag is off counter
move left foot
move right foot
lower right arm

do until location = door
 move left foot
 move right foot
 check location
repeat

move left arm until hand is on door
push with arm
move left foot through door
move right foot through door
release hand from door
lower arm

And now, from a structured POV:

Code: Select all

do until location = door
 Walk
repeat

position arm&#40;right, down, pocket&#41;

do until location = pb
 Walk
repeat

open&#40;left, up&#41;

position arm&#40;right, up, pb&#41;
grab&#40;right&#41;
position arm&#40;right, down, bag&#41;
release&#40;right&#41;

do until location = bread
 Walk
repeat

position arm&#40;right, up, head&#41;
position arm&#40;right, down, bread&#41;
grab&#40;right&#41;
position arm&#40;right, down, bag&#41;
release&#40;right&#41;

do until location = cash
 Walk
repeat

do until money = bill total
 money = pocket change - coin
 position arm&#40;left, down, coin&#41;
 position arm&#40;left, up, cashier hand&#41;
repeat

position arm&#40;right, up, bag&#41;
grab&#40;right&#41;

do until position = door
 Walk
repeat

open&#40;left, up&#41;

do until location = home
 walk
repeat





Walk
  move left foot
  move right foot
  check location
  
  return location
---

position arm&#40;arm, direction, object&#41;
  move arm direction until it is level with object
---

grab&#40;arm&#41;
  tighten arm fingers
---

release&#40;arm&#41;
  loosen arm fingers
---

open&#40;arm, direction&#41;
  position&#40;arm, direction, door&#41;
  
 push door with arm

 Walk
---
User avatar
abyss
Moloral Compass
Moloral Compass
Posts: 754
Joined: Mon Nov 06, 2006 6:13 pm

Post by abyss »

I understand it now i prefer structured.
<i>Formerly known as Hulk Hogan.</i>
User avatar
Larry Laffer
Admin
Admin
Posts: 4143
Joined: Sun Feb 19, 2006 8:06 am
Location: Romania

Post by Larry Laffer »

Now, that IS a good example (rofl)
<center>
abyss wrote:I don't even know if starcraft 1 was a windows or dos games.
</center>

ModBot™ - Faster than the speed of spam!(and always taking it to where it belongs!)
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

Thanks... feel free to share it. It's one of my best ones yet. :P. I remember my grade 10 programming teacher I think it was asking me "how would you program yourself to make a peanut butter sandwich, assuming you have to go to the store to get what you need".

I went on for 2 solid minutes and had only JUST made it to the part where I reach the store. lol. She was impressed... all the other newbs were like "First I walk to the store" totally undefining how to walk, and leaving out all sorts of easily overlooked steps. lol.

Too bad I didn't know about methods back then :P
Post Reply