Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Last Sunday in March 20xx

30 views
Skip to first unread message

Swifty

unread,
Feb 15, 2012, 4:26:47 AM2/15/12
to
Does Open Object REXX have any facility that makes it easy to
determine the date of the last Sunday in March, given an arbitrary
year?

It is almost trivial doing this with the date() function in Object
REXX, but I'm curious to know if there is anything better/easier.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk

Rugxulo

unread,
Feb 15, 2012, 11:06:11 AM2/15/12
to
Hi,

On Feb 15, 3:26 am, Swifty <steve.j.sw...@gmail.com> wrote:
>
> Does Open Object REXX have any facility that makes it easy to
> determine the date of the last Sunday in March, given an arbitrary
> year?

Dunno, but ...

> It is almost trivial doing this with the date() function in Object
> REXX,

"Almost" indeed. Even a noob like me can do it, apparently! (Tested
with Regina.)

===========
#!/usr/local/bin/rexx

parse value date() with . . year /* get current year */

mon=03 /* March */
day=0
sundays. = 0

do daydelta=1 to 31
day = translate(format(day,2),'0',' ')
blah = year || mon || translate(format(day + daydelta,2),'0',' ')
if date(w,blah,s) = 'Sunday' then do
sundays.0 = sundays.0 + 1
i = sundays.0 ; sundays.i = blah
end
end

say ; say 'Sundays in March' year ':' ; say
do i=1 to sundays.0
say delstr(sundays.i,1,6)
end
say

/* EOF */
===========

I know this is a lousy version, so suggestions (for beginners)
welcome.

P.S. Beware months with five Sundays (e.g. March 2009).

> but I'm curious to know if there is anything better/easier.

Good luck! (Hope I didn't intrude too badly here, heh.)

bwcherry

unread,
Feb 15, 2012, 12:02:53 PM2/15/12
to
/* find last dayofweek given month and year */
parse arg dayofweek month year

last = .nil
datetime = .datetime~new(year, month, 1)
datetime = .datetime~new(year, month, datetime~daysinmonth)
do datetime~daysinmonth while last == .nil
if datetime~dayname()~lower() == dayofweek~lower() then do
last = datetime
end
else do
datetime = datetime~adddays(-1)
end
end

if .nil == last then do
say 'Could not find date.'
end
else do
say last~standarddate()
end

C:\rexx>test.rex sunday 3 2012
20120325
--
Brandon Cherry

Swifty

unread,
Feb 15, 2012, 12:04:23 PM2/15/12
to
On Wed, 15 Feb 2012 08:06:11 -0800 (PST), Rugxulo <rug...@gmail.com>
wrote:

>Even a noob like me can do it, apparently!

Ah, but I detest a loop when a few simple statements suffice:

B = date('B',year||'0331','S')
Day_Number = B//7
If day_number <> 6 then B = B -day_number-1
Return date('S',B,'B')

Even so, this sequence, without comments, doesn't make it obvious what
it is doing. I'm always on the lookout for simplifications; I was
going to lookup the datetime object (or something like that) at
http://www.oorexx.org/ but I cannot reach it right now.

Swifty

unread,
Feb 15, 2012, 12:08:04 PM2/15/12
to
On Wed, 15 Feb 2012 09:02:53 -0800 (PST), bwcherry
<brandon...@gmail.com> wrote:

>datetime = .datetime~new(year, month, 1)

Ah, that was what I was thinking of. I'll see if I can combine the
.datetime object with the logic in my previous post just above.

Swifty

unread,
Feb 15, 2012, 12:57:57 PM2/15/12
to
On Wed, 15 Feb 2012 17:08:04 +0000, Swifty <steve....@gmail.com>
wrote:

>>datetime = .datetime~new(year, month, 1)
>
>Ah, that was what I was thinking of. I'll see if I can combine the
>.datetime object with the logic in my previous post just above.

My first attempt:

Year = 2012
Month = 3
datetime = .datetime~new(year, month, 1)
datetime = .datetime~new(year, month, datetime~daysinmonth)
Day_No = datetime~basedate//7
If Dayno <> 6 then datetime = datetime~addDays(-Day_No -1)
Say datetime~standardDate

This almost passes the "can see what it's doing without comments"
requirement.

Can this be improved? Surely it can!

Actually, it's already an improvement on my IBM Object REXX code, as
it copes with any month. Mine had a hard-coded "31" so failed on 5 of
the 12 months.

However, with something as flexible as the datatime object, I seem to
be taking a large number of significant steps to achieve something
simple.

It reminds me of the joke about the golfing professional playing a
gorilla. The gorilla teed off and the ball landed 6" from the hole.
The pro conceded the hole. This happened all the way round the course.
What the pro didn't know was that the gorilla *always* hit the ball
that hard.

hex

unread,
Feb 15, 2012, 4:03:41 PM2/15/12
to
/*
Well not more self explaning !
By using the first of next month as reference, instead of last date
in month,
you don't need to keep track of how many days in each month.
Then you have to find the first day of the week(monday) and then
subtract 1 and you will get last Sunday
date of wanted month.
*/
parse arg year
months = .array~of(1,2,3,4,5,6,7,8,9,10,11,12)
monthname = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
do i over months
month = right(i+(i<12),2,'0') -- get next month except for
December
if i=12 then month = '01' -- if december set month =
januari

B = date('B',year + (i=12)||month||'01','S') -- if December we add
1 to year
lastSunday = b - b//7 - 1 -- daynumb - dayofweek
= monday - 1 = sunday
SundayDate = date('N',lastSunday,'B')
say "Last Sunday in" monthname~word(i) year "is" SundayDate
end

Gerard_Schildberger

unread,
Feb 15, 2012, 5:41:42 PM2/15/12
to
I had the same thought, but also expanded it so that the day-of-week
can
be specified. The adjustment line (where the subtractions are done)
are
a bit more complicated for other days (other than Sunday) and maybe
somebody can reduce the computation for the adjustment.

Here is my version, with more error checking than you'll need:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

/**/ parse arg dayOfWeek theMonth theYear .
say lastdow(dayOfWeek,theMonth,theYear)
exit


/*--------------------------------------------------------------------
+
| lastDOW: procedure to return the date of the last day-of-week
|
| of a particular month (of a particular year).
|
|
|
| The day-of-week must be specified (in any case) as an English
|
| spelled day of the week, with a minimum length that doesn't cause
|
| ambiguity. I.E.: W for Wednesday, SA for Saturday, TU for
Tuesday|
|
|
| Sunday sunDAY SU sun sunda SUNday are all allowed.
|
|
|
| The month is specified as a number 1 --> 12
|
| 1=January 2=February 3=March ... 12=December
|
| If omitted [or an asterisk(*)], the current month is used.
|
|
|
| The year is specified as an integer or just the last two digits
|
| (two digit years are assumed to be in the current century, there
|
| is no windowing).
|
| If omitted [or an asterisk(*)], the current year is used.
|
| Years < 100 must be specified with (at least two) leading zeroes.
|
|
|
| The method used is to find the "day number" of the 1st of the next
|
| month, then subtract 1 (this gives the "day number" of the last
|
| day of the month, bypassing the leapday mess). The last day of
|
| the week is then obtained straightforwardly, or via subtraction.
|
+--------------------------------------------------------------------
*/

lastdow: procedure; arg dow .,mm .,yy . /*dow = day of
week*/
if mm=='' | mm=='*' then mm=left(date('U'),2) /*use default
month*/
if yy=='' | yy=='*' then yy=left(date('S'),4) /*use default year
*/
if length(yy)==2 then yy=left(date('S'),2)yy /*append century.
*/
/*Note mandatory leading blank in $
string.*/
$=" MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY"
if arg()==0 then call err 'no arguments specified'
if arg()>3 then call err 'too many arguments specified'
if dow=='S'|dow=='T' then call err 'day-of-week name too short:'
arg(1)
dw=pos(' 'dow,$) /*find the d-o-
week*/
if dw==0 then call err 'invalid day-of-week:' arg(1)
if \datatype(mm,'W') then call err 'month is not an integer:' mm
if \datatype(yy,'W') then call err 'year is an integer:' yy
if mm<1 | mm>12 then call err 'month not in range 1-->12:' mm
if yy<1 | yy>9999 then call err 'invalid year:' yy
tdow=wordpos(word(substr($,dw),1),$)-1 /*target dow, 0--
>6*/
/*day# of last
dom.*/
_=date('B',right(yy+(mm=12),4)||right((mm+1)//12,2,0)"01",'S')-1
!=_//7 /*calc. dow, 0--
>6*/
if !\==tdow then _=_-!-7+tdow+7*(!>tdow) /*not dow?
Adjust.*/
return date(,_,'B') /*return the
answer*/


err: say; say '***error!*** (in LASTDOW)'; say; say arg(1); say; exit
13

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

I was pleased to find out that other programmers used the same
construct
[in adding 1 to the year (and month).

It would take two more lines to allow the user to specify the month
in (English) abbreviated spellings, but it's verbose enough already.

Adding the names of days of the week and the names of the months in
other languages is a trivial coding task (I have done so, as a matter
of fact, 99 languages).

I was thinking about explaining the adjustment calculation, but the
statment speaks for itself. ________________________ Gerard
Schildberger

hex

unread,
Feb 16, 2012, 4:51:20 AM2/16/12
to
/*
Slighly modified to allow for any lastday(monday to sunday) of month
By using the first of next month as reference, instead of last date
in month,
you don't need to keep track of how many days in each month.
Then find lastday of month and also find first day(monday) of that
week
If lastday of month - firstday of week is less than the weekdaynumber
in array of weekdays
the wanted day must be in week before
else
it's in same week so we add the weekdaynumber in weekdays array to
firstday(monday) of week

Now we got the last of wanted day in month

*/

parse arg year day
months = .array~of(1,2,3,4,5,6,7,8,9,10,11,12)
monthname = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
weekdays = "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
wday = weekdays~wordpos(day) - 1 -- daynumber of day
array

do i over months
month = right(i+(i<12),2,'0') -- get next month except for
December
if i=12 then month = '01' -- if december set month =
januari

B = date('B',year + (i=12)||month||'01','S') -- if December we
add 1 to year

lastdayMonth = b - 1
monday = b - b//7

if lastdayMonth - monday < wday then
lastDate = monday - (words(weekdays) - wday)
else
lastDate = monday + wday

WeekDate = date('N',lastDate,'B')
say "Last" day "in" monthname~word(i) year "is" WeekDate
end

hex

unread,
Feb 16, 2012, 11:57:24 AM2/16/12
to
Made some simplifications
/*
Slighly modified to allow for any lastday(monday to sunday) of month
By using the first of next month as reference, instead of last date
in month,
you don't need to keep track of how many days in each month.
Then find lastday of month and also find first day(monday) of that
week
If lastday of month - firstday of week is less than the weekdaynumber
in array of weekdays
the wanted day must be in week before
else
it's in same week so we add the weekdaynumber in weekdays array to
firstday(monday) of week

Now we got the last of wanted day in month

*/

parse arg year day
months = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
weekdays = "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
wday = weekdays~wordpos(day) - 1 -- daynumber of day
array

do i = 1 to words(months)

month = right(i+(i<12)-((i=12)*11),2,'0') -- if 12
set to 01
b = date('B',year + (i=12)||month||'01','S') -- if
December (12) we add 1 to year
lastdayMonth = b - 1
monday = b - b//7
lastdate = monday + ((lastdayMonth - monday < wday)*-
((words(weekdays) - wday)))+((lastdayMonth - monday >= wday)*wday)
WeekDate = date('N',lastDate,'B')
say "Last" day "in" months~word(i) year "is" WeekDate

end

danfan46

unread,
Feb 16, 2012, 12:57:04 PM2/16/12
to
On 2012-02-15 10:26, Swifty wrote:
> Does Open Object REXX have any facility that makes it easy to
> determine the date of the last Sunday in March, given an arbitrary
> year?
>
> It is almost trivial doing this with the date() function in Object
> REXX, but I'm curious to know if there is anything better/easier.
>
Using the datetime Class:

#!/usr/bin/rexx
trace O
signal on novalue

say lsim(2012, 9)

exit

lsim: procedure

use arg year, month
this_month = .datetime~New(year,month,1) -- first day in month
this_month = this_month~addDays(this_month~daysInMonth -1 ) -- last day inmonth
if this_month~weekday == 7 then return this_month~standarddate("-")
this_month = this_month~addDays( -this_month~weekday ) -- back to prev Sunday
return this_month~standarddate("-")

LesK

unread,
Feb 16, 2012, 6:43:41 PM2/16/12
to
Swifty wrote:
> On Wed, 15 Feb 2012 08:06:11 -0800 (PST), Rugxulo <rug...@gmail.com>
> wrote:
>
>> Even a noob like me can do it, apparently!
>
> Ah, but I detest a loop when a few simple statements suffice:
>
> B = date('B',year||'0331','S')
> Day_Number = B//7
> If day_number <> 6 then B = B -day_number-1
> Return date('S',B,'B')
>
> Even so, this sequence, without comments, doesn't make it obvious what
> it is doing. I'm always on the lookout for simplifications; I was
> going to lookup the datetime object (or something like that) at
> http://www.oorexx.org/ but I cannot reach it right now.
>
The pdf should be in your oorexx\doc folder. You can also download all the html
files from SF to a local folder and use them from there.

--

Les (Change Arabic to Roman to email me)

Swifty

unread,
Feb 17, 2012, 3:10:46 AM2/17/12
to
On Thu, 16 Feb 2012 18:43:41 -0500, LesK <5mr...@tampabay.rr.com>
wrote:

>The pdf should be in your oorexx\doc folder. You can also download all the html
>files from SF to a local folder and use them from there.

Well, the usual method of stating publicly "It's broken" was (as
usual) sufficient to have it working within a few minutes. :-)

On my workaday PC, I have IBM Object REXX (no oorexx due to lethargy),
so I'd have to grub around on my office server for the OORexx pdf.
Downloading the html files is a good idea though. Thanks!

Swifty

unread,
Feb 17, 2012, 9:19:23 AM2/17/12
to
On Thu, 16 Feb 2012 18:57:04 +0100, danfan46 <danf...@hotmail.com>
wrote:

>lsim: procedure
>
> use arg year, month
> this_month = .datetime~New(year,month,1) -- first day in month
> this_month = this_month~addDays(this_month~daysInMonth -1 ) -- last day inmonth
> if this_month~weekday == 7 then return this_month~standarddate("-")
> this_month = this_month~addDays( -this_month~weekday ) -- back to prev Sunday
>return this_month~standarddate("-")

Thanks, that's neater than my version. I've compressed yours just a
little, but I think the logic remains quite plain:

lsim: procedure
arg year,month
this_month = .datetime~New(year,month,1) -- Start from 1st of month
this_month = this_month~addDays(this_month~daysInMonth-1) --Hop to end
if this_month~weekday == 7 then return this_month~standarddate("-")
return this_month~addDays(-this_month~weekday)~standarddate('-')
I removed some of the comments, so it would fit within the line length
limit here.

Dave Saville

unread,
Feb 17, 2012, 10:17:22 AM2/17/12
to
On Fri, 17 Feb 2012 14:19:23 UTC, Swifty <steve....@gmail.com>
wrote:
I had a related problem solved much the same way. I and a group of ex
workmates have a monthly lunch on the first Thursday. A reminder email
was sent one week before. I rashly said it would be easy to
automate........

--
Regards
Dave Saville

Glenn Knickerbocker

unread,
Feb 17, 2012, 10:29:30 AM2/17/12
to
On 2/17/2012 9:19 AM, Swifty wrote:
> this_month = this_month~addDays(this_month~daysInMonth-1) --Hop to end
> if this_month~weekday == 7 then return this_month~standarddate("-")
> return this_month~addDays(-this_month~weekday)~standarddate('-')

You could simplify even more by skipping ahead to the first of the month
and then subtracting unconditionally:

this_month = this_month~addDays(this_month~daysInMonth) --next month
return this_month~addDays(-this_month~weekday)~standarddate('-')

Then you can decide whether that first AddDays is any simpler or clearer
than just adding one to the month and year:

month = month // 12 + 1 -- next month
year = year + (month = 1) -- next year if January
next_month = .dateTime~New(year, month, 1) -- first of month
return next_month~addDays(-next_month~weekday)~standarddate('-')

ŹR

Swifty

unread,
Feb 17, 2012, 10:59:32 AM2/17/12
to
On Fri, 17 Feb 2012 10:29:30 -0500, Glenn Knickerbocker
<No...@bestweb.net> wrote:

>You could simplify even more by skipping ahead to the first of the month
>and then subtracting unconditionally:
>
> this_month = this_month~addDays(this_month~daysInMonth) --next month
> return this_month~addDays(-this_month~weekday)~standarddate('-')

I can stand only so much excitement in one day! If we simplify this
much more then we might as well code it in APL. :-)

Gerard_Schildberger

unread,
Feb 17, 2012, 3:03:16 PM2/17/12
to
> I had a related problem solved much the same way. I and a group of ex
> workmates have a monthly lunch on the first Thursday. A reminder email
> was sent one week before. I rashly said it would be easy to
> automate........
> --
> Regards
> Dave Saville

Yes, I originally wrote such a routine (to find 1st-, 2nd-, 3rd-,
4th-, 5th-, last-, next-, prev- any-day-of-the-week for any
month or year), and I wrote the code in "older" classic REXX,
before the fancy-dancy multiple-arg DATE function. It wasn't
that difficult of a subroutine to code and not as verbose as one
would think. I eluded to part of its functionality earlier in a
previous post about supporting 99 different languages for the
day-of-week and month names. It was a lot of linguistic fun in
researching the various languages. _________ Gerard Schildberger

Gerard_Schildberger

unread,
Feb 17, 2012, 4:03:09 PM2/17/12
to
> I can stand only so much excitement in one day! If we simplify this
> much more then we might as well code it in APL. :-)
> --
> Steve Swifthttp://www.swiftys.org.uk/swifty.htmlhttp://www.ringers.org.uk

Yuppers, almost all code can be simplified (or at least compacted),
but it would almost assuredly be less readable. I recoded my original
routine (which has a small pesky error in it) and I'm re-posting the
corrected and enhanced version. This version allows for an Engliah-
spelled name of the month (as well as an integer specification), and
more error checking. Most of the this REXX code is spent in error
checking and the handling of defaults. By the way, in the original
specification, it was to handle any year, and I took that to mean
years that don't necessarily have four digits. None of the other
examples handled that case correctly (as far as I could tell). The
"meat" of the REXX code is between the row of tildes (~~~~~~~~~~~~):


/**/ parse arg dayOfWeek theMonth theYear .
say lastdow(dayOfWeek,theMonth,theYear)
exit

/*-----------------------------------------------------------------+
| lastDOW: procedure to return the date of the last day-of-week |
| of any particular month (of any particular year). |
| |
| The day-of-week must be specified (it can be in any case, |
| (lower-/mixed-/upper-case) as en English name of spelled day |
| of the week, with a minimum length that causes no ambiguity. |
| I.E.: W for Wednesday, Sa for Saturday, Su for Sunday |
| |
| The month can be specified as an integer 1 --> 12 |
| 1=January 2=February 3=March ... 12=December |
| or the English name of the month, with a minimum length that |
| causes no ambiguity. I.E.: Jun for June, D for December.|
| If omitted [or an asterisk(*)], the current month is used. |
| |
| The year is specified as an integer or just the last two digits |
| (two digit years are assumed to be in the current century, and |
| there is no windowing for a two-digit year). |
| If omitted [or an asterisk(*)], the current year is used. |
| Years < 100 must be specified with (at least 2) leading zeroes.|
| |
| Method used: find the "day number" of the 1st of the next month,|
| then subtract 1 (this gives the "day number" of the last day of |
| the month, bypassing the leapday mess). The last day-of-week |
| is then obtained straightforwardly, or via subtraction. |
+-----------------------------------------------------------------*/

lastdow: procedure; arg dow .,mm .,yy . /*dow = day of week*/
parse arg a.1,a.2,a.3 /*orig args, errmsg*/
if mm=='' | mm=='*' then mm=left(date('U'),2) /*use default month*/
if yy=='' | yy=='*' then yy=left(date('S'),4) /*use default year */
if length(yy)==2 then yy=left(date('S'),2)yy /*append century. */
/*Note mandatory leading blank in strings below.*/
$=" Monday TUesday Wednesday THursday Friday SAturday SUnday"
!=" JAnuary February MARch APril MAY JUNe JULy AUgust September",
" October November December"
upper $ ! /*uppercase strings*/
if dow=='' then call .er "wasn't specified",1
if arg()>3 then call .er 'arguments specified',9

do j=1 for 3 /*any plural args ?*/
if words(arg(j))>1 then call .er 'is illegal:',j
end

dw=pos(' 'dow,$) /*find day-of-week*/
if dw==0 then call .er 'is invalid:',1
if dw\==lastpos(' 'dow,$) then call .er 'is ambigious:',1
if datatype(mm,'month') then /*if MM is alpha...*/
do
m=pos(' 'mm,!) /*maybe its good...*/
if m==0 then call .er 'is invalid:',1
if m\==lastpos(' 'mm,!) then call .er 'is ambigious:',2
mm=wordpos(word(substr(!,m),1),!)-1 /*now, use true Mon*/
end
if \datatype(mm,'W') then call .er "isn't an integer:",2
if \datatype(yy,'W') then call .er "isn't an integer:",3
if mm<1 | mm>12 then call .er "isn't in range 1-->12:",2
if yy=0 then call .er "can't be 0 (zero):",3
if yy<0 then call .er "can't be negative:",3
if yy>9999 then call .er "can't be > 9999:",3

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
tdow=wordpos(word(substr($,dw),1),$)-1 /*target dow, 0-->6*/
/*day# of last dom.*/
_=date('B',right(yy+(mm=12),4)right(mm//12+1,2,0)"01",'S')-1
?=_//7 /*calc. dow, 0-->6*/
if ?\==tdow then _=_-?-7+tdow+7*(?>tdow) /*not dow? Adjust.*/
return date('weekday',_,"B") date(,_,'B') /*return the answer*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

.er: arg ,_;say; say '***error!*** (in LASTDOW)';say /*tell error,*/
say word('day-of-week month year excess',arg(2)) arg(1) a._
say; exit 13 /*... and then
exit.*/

________________________________________________ Gerard Schildberger


Gerard_Schildberger

unread,
Feb 17, 2012, 3:38:38 PM2/17/12
to
> I can stand only so much excitement in one day! If we simplify this
> much more then we might as well code it in APL. :-)
> --
> Steve Swifthttp://www.swiftys.org.uk/swifty.htmlhttp://www.ringers.org.uk

Yuppers, you could make almost any code more compact (but not
most assurdly, not necessarily simpler). The majority of the
REXX code below is in checking for errors and defaults.

I posted the improved code here again, with the allowing of
specification of the month either as a decimal number or
(minimal) English name of the month. By the way, the
original specification was to allow any year, and I took that
to mean even those years that aren't four digits, which every
other example code fails to handle. I've also added a few
more error checks. I normally use more descriptive REXX
variable names, but you can only pack so much info into one
line of code that posts well. I'm surprised that anybody
didn't ask/comment about the [not] superflous periods in the
procedure's ARG statement. The "meat" of the code is
between a row of tildes (~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~):
_______________________________________________ Gerard Schildberger


Swifty

unread,
Feb 18, 2012, 3:02:33 AM2/18/12
to
On Fri, 17 Feb 2012 12:38:38 -0800 (PST), Gerard_Schildberger
<gera...@rrt.net> wrote:

>The majority of the
>REXX code below is in checking for errors and defaults.

This is my natural environment. I took a course in "Computer Science"
at school in 1967, and in that era almost anything you did would go
wrong eventually. So I was taught the imperative of error checking and
reporting. It has stuck with me ever since, and served me well. But it
does explain why it takes me about 5 minutes to write a proposed "one
line program". Consequently, I'm often seen as un-productive.

Now, 90%+ of my code is CGI scripts (interactions with Browser users),
so I have to check almost every character of my data.

I once encountered a programmer whose rules seemed to be based on:

1. Never check a return code; it will only depress you.
2. If something goes wrong in the code, keep quiet.
3. Never write something in 5 lines if 10 lines will do.
4. Never comment your code.

Shmuel Metz

unread,
Feb 18, 2012, 6:37:57 PM2/18/12
to
In <48muj7dgerccpk79u...@4ax.com>, on 02/18/2012
at 08:02 AM, Swifty <steve....@gmail.com> said:

>This is my natural environment. I took a course in "Computer Science"
>at school in 1967, and in that era almost anything you did would go
>wrong eventually.

That hasn't changed.

>So I was taught the imperative of error checking and reporting.

That seems to have changed.

>But it does explain why it takes me about 5 minutes to write a
>proposed "one line program". Consequently, I'm often seen as
>un-productive.

IMHO, doing your homework up front saves time in the long run, as does
doing your documentation.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spam...@library.lspace.org

LesK

unread,
Feb 18, 2012, 9:42:49 PM2/18/12
to
Shmuel (Seymour J.) Metz wrote:
> In <48muj7dgerccpk79u...@4ax.com>, on 02/18/2012
> at 08:02 AM, Swifty <steve....@gmail.com> said:
>
>> This is my natural environment. I took a course in "Computer Science"
>> at school in 1967, and in that era almost anything you did would go
>> wrong eventually.
>
> That hasn't changed.
>
>> So I was taught the imperative of error checking and reporting.
>
> That seems to have changed.
>
>> But it does explain why it takes me about 5 minutes to write a
>> proposed "one line program". Consequently, I'm often seen as
>> un-productive.
>
> IMHO, doing your homework up front saves time in the long run, as does
> doing your documentation.
>
You're both right on all points! Trouble is that in most places you don't get
rewarded/punished for the *totality* of the lifetime of your work. I've always
been of the opinion that the Program Maintenance Department should only have to
work on programs when the original programmer has left the company or the
hardware or OS has changed. If s/he hasn't, they should have to fix their
program on there own non-company time. After all, they've already been paid for
it. They should also get a percentage of the profit (or savings) the company
makes from the program.

Swifty

unread,
Feb 19, 2012, 2:19:20 AM2/19/12
to
On Sat, 18 Feb 2012 21:42:49 -0500, LesK <5mr...@tampabay.rr.com>
wrote:

>the Program Maintenance Department should only have to
>work on programs when the original programmer has left the company or the
>hardware or OS has changed. If s/he hasn't, they should have to fix their
>program on there own non-company time.

For a long time I used to keep a tally on who had reported bugs in my
code (or fallen foul of my "Signal on Failure/Novalue/Syntax"). At the
end of each month, I'd sort the list by count and send a £5 Amazon
voucher to the winner of "Swifty's bug finder of the month".

I firmly believe that bug reporters should be rewarded (I once got a
free S/W upgrade for having reported bugs, for example). Also, having
to pay that blasted £5 per month made me redouble my effort to get it
right the first time (or right enough!).

I withdrew my scheme when my employers made a petty reduction in my
benefits, and I've noticed a slight degradation in the quality of my
code, but maybe that's just age-related degradation. I may resurrect
the process.
0 new messages