Actually writing code question; Turing
Author |
Message |
Flikerator
|
Posted: Wed Oct 25, 2006 3:30 pm Post subject: Actually writing code question; Turing |
|
|
I have data declaration for lines. I want to declared all the four points (x1,y1,x2,y2) on one line. I thought about using the semi colin.
This ";"
It worked. BUT when I hit F2 it puts it on the next line x__x
Is there a way to keep it all on the same line?
This
code: |
Lines (1).x1 := 20; Lines (1).y1 := 20; Lines (1).x2 := maxx - 20; Lines (1).y2 := maxy - 20;
|
Becomes
code: |
Lines (1).x1 := 20;
Lines (1).y1 := 20;
Lines (1).x2 := maxx - 20;
Lines (1).y2 := maxy - 20;
|
I want it to stay as the first one |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Wed Oct 25, 2006 4:13 pm Post subject: (No subject) |
|
|
what's wrong with it all being on seperate lines? all it does when it is on one line is make your code harder to read. |
|
|
|
|
|
iamcow
|
Posted: Wed Oct 25, 2006 4:34 pm Post subject: (No subject) |
|
|
if you're doing that for the sake of shortening your program, you might as well not do it. It's till the same amount of optimization as the one lined thing |
|
|
|
|
|
Flikerator
|
Posted: Wed Oct 25, 2006 5:08 pm Post subject: (No subject) |
|
|
Its not hard to read for me.
I have many "Lines" and each one has 9 different pieces of information (I included the basic 4). It wastes room; I hate scrolling around to go around changing things if there is a better way. If I could do it in 1, that saves me 8 lines. Then I don't need to white space it.
If there isn't a way Ill simple use files.
If there is a way I would like to know; even if I'm not going to use it. Why deny information simply because you 'think' at this moment it isn't as good? Catalogue it; you may find a use for it later that you never thought of before. |
|
|
|
|
|
ericfourfour
|
Posted: Wed Oct 25, 2006 5:28 pm Post subject: (No subject) |
|
|
How about having your line as an object?
Hasn't been tested.
code: |
class Line
export initialize, draw
var x, y : array 0 .. 1 of real
proc initialize (x1, y1, x2, y2 : real)
x (0) := x1
y (0) := y1
x (1) := x2
y (1) := y2
end initialize
proc draw(clr : int)
Draw.Line (round (x (0)), round (y (0)), round (x (1)), round (y (1)), clr)
end draw
end Line
var line : ^Line
new Line, line
line -> initialize (10, 10, 100, 100)
line -> draw (black)
|
|
|
|
|
|
|
[Gandalf]
|
Posted: Wed Oct 25, 2006 9:40 pm Post subject: (No subject) |
|
|
Or more generally you could create something like so:
code: | type Line :
record
x1, y1, x2, y2 : int
end record
var lines : array 1 .. 4 of Line
proc initLine(var l : Line, x1, y1, x2, y2 : int)
l.x1 := x1
l.y1 := y1
l.x2 := x2
l.y2 := y2
end initLine
initLine (lines (1), 12, 12, 50, 50)
initLine (lines (2), 43, 43, 65, 65)
%etc... |
|
|
|
|
|
|
Clayton
|
Posted: Thu Oct 26, 2006 9:08 am Post subject: (No subject) |
|
|
or better yet, instead of making a procedure that mercilessly changes the value of lines(x), make it a function which creates a new value to assign to lines(x)
Turing: |
type Line :
record
x1, y1, x2, y2 : int
end record
function initLine (x1, y1, x2, y2 : int) : Line
var tempLine : Line
tempLine.x1 := x1
tempLine.x2 := x2
tempLine.y1 := y1
tempLine.y2 := y2
result tempLine
end initLine
var lines : array 1 .. 2 of Line
lines (1) := initLine (maxx div 2, maxy div 2, maxx, maxy)
lines (2) := initLine (0, maxy, maxx div 2, maxy div 2)
for i : 1 .. 2
Draw.Line (lines (i ).x1, lines (i ).y1, lines (i ).x2, lines (i ).y2, black)
end for
|
|
|
|
|
|
|
Flikerator
|
Posted: Thu Oct 26, 2006 11:08 am Post subject: (No subject) |
|
|
I never thought of it that way. Thanks for the help.
If anyone knows how to knows how to make it so you can write the code on one line let me know, im still interested in that ^_^ |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Thu Oct 26, 2006 1:04 pm Post subject: (No subject) |
|
|
like i said before, it is bad coding practice, makes your code harder to read, and generally just doesnt look good anyway. The way you had it at the start "works", its just that when you hit F2, it indents the code to its standards, ie, only one declaration per line (ie linex1 := 2), using something like [Gandalf]'s procedure, or better yet my function is going to be your best bet. |
|
|
|
|
|
|
|