?

Log in

No account? Create an account
Programming question, with tedious preamble - B. Henderson Asher's Moments of Mirth [entries|archive|friends|userinfo]
Listen in, listen Ian!

[ website | Flickr ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Programming question, with tedious preamble [Nov. 15th, 2007|03:24 pm]
Listen in, listen Ian!
The language I mainly use at work, RPG is
very old skool. So much so, that in all but the most modern versions, you
still have to put specific bits in particular columns of the screen, as a
throwback to the days of punchcards.

The assignment command is MOVE. For example, to assign a value
to a 10 character field you might say:

MOVE 'MUFCRULEOK' CHAR10

It is possible to move a value from one field to another thus:

MOVE FLD1 FLD2

but if the fields are different lengths, care is required. Suppose FLD1 is
a 10 character field with a value of '0123456789', and FLD2 is an empty 15
character field. Intuitively you might think that

MOVE FLD1 FLD2

would leave the value of FLD2 as '0123456789 ' but you'd be wrong - the
MOVE command proceeds from the right, so that the value of FLD2 turns out
to be ' 0123456789'. To get the expected effect, you'd use the MOVEL
command.

Probably 95% of times the effect I want to achieve when moving strings
around is the MOVEL effect. Would there be some historical performace
reason - bearing in mind this language dates from the days when the effect
of this kind of thing on execution times could be measured in hours - why
the default would be to move from the right? Is that more efficient?
linkReply

Comments:
[User Picture]From: caramel_betty
2007-11-15 03:51 pm (UTC)
When dumping out information to (mono-spaced, line-printed) reports, would it get all your numbers to right align? So you get:
   1234
9876543
  51230

and not
1234
9876543
51230

(Reply) (Thread)
[User Picture]From: oldbloke
2007-11-15 03:53 pm (UTC)
It's the obvious thing. Dunno about efficiency, wot Tim arsked abaht.
But if r-align is your first shot, you need a new name for l-align.
I think Tim should benchmark the two ops and see.
(Reply) (Parent) (Thread)
[User Picture]From: caramel_betty
2007-11-15 03:57 pm (UTC)
The only thing I could think of re: efficiency is that - assuming you can do everything with MOVE and don't need to MOVEL - it strips out a layer of reformating when you dump out the report. Which, thousands of numbers, hundreds of pages, could be a saving when your computing power is measured in how much coal it consumes.
(Reply) (Parent) (Thread)
[User Picture]From: ruudboy
2007-11-15 07:24 pm (UTC)
You'd use numeric fields for those though. This is just strings.
(Reply) (Parent) (Thread)
[User Picture]From: oldbloke
2007-11-15 03:55 pm (UTC)
You're implying the char*N fields are actually arrays of chars, which though common isn't always the case. Do you know that they are?
If they're statically sized, I don't see that there'd be any necessary inherent performance difference.
(Reply) (Thread)
[User Picture]From: amuchmoreexotic
2007-11-15 04:00 pm (UTC)
Do you use fields to store integers or is there a separate type for that? If you had an integer in a field, maybe using the default MOVE behaviour makes it easier to tell if a digit represents tens, hundreds or whatever?
(Reply) (Thread)
[User Picture]From: amuchmoreexotic
2007-11-15 04:01 pm (UTC)
ie what caramel_betty said.
(Reply) (Parent) (Thread)
[User Picture]From: ruudboy
2007-11-15 07:25 pm (UTC)
It's a different type for numbers. This is just strings.
(Reply) (Parent) (Thread)
[User Picture]From: amuchmoreexotic
2007-11-16 10:17 am (UTC)
It must to be to make things more human-readable without extra processing.
(Reply) (Parent) (Thread)
[User Picture]From: spoonrefuter
2007-11-15 04:14 pm (UTC)
I have a (very) vague recollection that comparing a number to zero is quicker than comparing it anything else.

If that is true, a loop counting down to move the corresponding bytes/characters is theoretically quicker than a loop counting up - i.e. it might be more efficicent to copy from right to left.

Of course, this may well be complete sh!te.
(Reply) (Thread)
[User Picture]From: oldbloke
2007-11-15 04:20 pm (UTC)
The loop could count down in both cases, you just change the formula for choosing where in the array to stick a character.
Where's hoiho? He knows what goes on inside these languages.
Tim, are you using an implicit cast from Int to Char here? THAT might make a diff, if you do it with modulo arith, you get the right most chars out first.
(Reply) (Parent) (Thread)
[User Picture]From: ruudboy
2007-11-15 07:25 pm (UTC)
Nope, this is all strings.
(Reply) (Parent) (Thread)
[User Picture]From: mr_tom
2007-11-15 04:51 pm (UTC)
Could be a big/little-endian thing?
(Reply) (Thread)
[User Picture]From: jtemperance
2007-11-15 04:53 pm (UTC)
The first thing that occurs to me is filling in zeros. Someone or some application might come along and fill in zeros for the blank spaces. You would want the extra zeros to be on the left rather than the right, so as not to change the values.
(Reply) (Thread)
[User Picture]From: jtemperance
2007-11-16 08:11 am (UTC)
Yeah, now I see I totally misunderstood what you were asking. It must be something to do with the architecture of the machines the language was originally designed for.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: ruudboy
2007-11-15 07:26 pm (UTC)
I refer the honourable gentleman to my earlier reply.
(Reply) (Parent) (Thread)