Path: news.cs.au.dk!news.net.uni-c.dk!newspeer.ebone.net!newsrouter.euroconnect.net!newsfeed101.telia.com!news101.telia.com!not-for-mail From: "Kasper Osterbye" Newsgroups: comp.lang.beta Subject: Re: Program 'betcat.bet': Comments, please? Date: Wed, 21 Jun 2000 07:28:48 +0200 Organization: Customer at Telia Danmark (http://www.telia.dk/) Lines: 111 Message-ID: <8ipjqh$585$1@news101.telia.com> References: <394D2663.37AB97D4@skynet.be> <394F9A74.3AB6FE7D@skynet.be> NNTP-Posting-Host: pc146131.stofanet.dk X-Trace: news101.telia.com 961565329 5381 212.10.81.131 (21 Jun 2000 05:28:49 GMT) X-Complaints-To: abuse@telia.dk NNTP-Posting-Date: 21 Jun 2000 05:28:49 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Xref: news.cs.au.dk comp.lang.beta:12471 Hi Atle Nice program, fairly direct and easy to follow. I have some comments on style, and I will give an alternative. Mind you though, that it is my personal style, and nothing else. > ORIGIN '~beta/basiclib/betaenv'; > INCLUDE '~beta/basiclib/file'; > > -- Program : Descriptor -- > > (# > i : @integer; You need not declare index's for (for for) loops. The are always integer, and have scope inside the (for for) construct. > showFile : > (# > OK : @Boolean; I would probably have declared the OK boolean inside "fil". Later I would refere it as "fil.OK". In larger programs I would not like to have scattered flags all over the place. > fileName: ^text; > fil: @File (# > accessError:: (# do false -> OK #); > noSuchFileError:: (# do true ->continue ; false -> OK #); > otherError:: (# do false -> OK #) > #); > enter fileName[] > do > TRUE -> OK; > fileName[] -> fil.Name; > fil.openRead; > (if not OK then > 'Can\'t open file ' -> putText; fileName[] -> putLine; > leave showFile > else > 'Contents of ' -> putText; fileName[] -> putLine; > if); > readTheFile: > (# > do (if not fil.eos > then > fil.getline -> putLine; > restart readTheFile > else > fil.Close; '' -> fil.Name; > leave readTheFile > if); > #); > #) The readTheFile should be substituted with the following: fil.scan(# do ch->put#); fil.close; Which is shorter and "scan" is used a lot in Beta programs. > > do (for i:noOfArguments-1 repeat i+1 -> arguments -> showFile for) > #) Now, I do not like your OK solution, and would do the overall program differently, e.g. like this: ORIGIN '~beta/basiclib/betaenv'; INCLUDE '~beta/basiclib/file'; -- Program: Descriptor -- (# showFile: (# FileNotFound:< Exception; fileName: ^text; fil: @File (# noSuchFileError::< (# do FileNotFound#) #) enter fileName[] do fileName[]->fil.Name; fil.openRead; 'Contents of '->putText; fileName[]->putLine; fil.scan (# do ch->put #) #) do (for idx: noOfArguments-1 repeat printOneFile: idx+1->arguments ->showFile (# FileNotFound:: (# do 'Can\'t open file '->putText; fileName[]->putLine; leave PrintOneFile #) #) for) #) The idea is to notice that showFile can go wrong, and declare a new exception to be called when that happens. This makes the main loop somewhat bigger, but I will argue that it makes showFile more general, as it does not decide on how to handle errors, but only to detect them. How to handle the error is described at the calling place, not the detection place. Anyway, its a matter of style. -- Kasper