Subj : Re: curve for verbosity in a language To : comp.programming From : mwojcik Date : Thu Aug 04 2005 10:49 pm In article <1123006628.001530.96270@f14g2000cwb.googlegroups.com>, "Rob Thorpe" writes: > Jon Harrop wrote: > > Jeff Lanam wrote: > > > COBOL appears at first to be verbose; there's a fair amount of > > > required syntax, and the conventions adopted over the years discourage > > > dense packing of language elements in the program. However, if you > > > look at the power of statements like INSPECT, STRING, or UNSTRING, or > > > the kinds of data transformation implicit in the MOVE statement, > > > you'll see operations that would take many lines of code in other > > > languages. > > > > Would you be so kind as to explain what these things do, so we can have a go > > at translating them? > > They are string matching operations. STRING is a string-concatenating facility, not a string-matching one; its string-matching capability is a secondary feature which only comes into play when finding the lengths of constituent strings. UNSTRING is not simply a string-matching facility. INSPECT is a variety of string-matching facilities. MOVE isn't a string-matching facility at all. I'm not persuaded by the "COBOL statements are very powerful" arguments (which are common among COBOL users), personally, even though COBOL our main business. Little of what's done in the typical STRING, UNSTRING, or INSPECT would require more than a couple of lines of C (conventionally-formatted), except for the automatic data representation conversions provided by the language. However, as descriptions of what those statements do, the following is rather impoverished. > STRING concatenates strings together > UNSTRING splits strings up by delimiters, it has many options to > control it's behaviour. > INSPECT performs two operations on the contents on a string: counting > characters or replacing them. STRING, for example, will concatenate any number of variables or literals into a buffer. Each of the constituents can be separately described as delimited by a given literal character or string, the literal character or string in another variable, a figurative constant (such as SPACES or LOW-VALUES), or the defined size of the source. The programmer can optionally specify a "pointer" variable, which indicates the starting position in the buffer when STRING begins and is updated to the final position when it is finished. (Reference modification can also be used on the destination, or any other variables named in the statement, to specify a subarea of a multi-character area.) There are optional clauses for overflow and non-overflow conditions, each of which take an arbitrary imperative statement. And it's the simplest of the three. INSPECT, for example, has not two but four modes: tallying, replacing, tallying and replacing, and converting. For the first three any number of match targets can be specified, so you can have a single INSPECT that tallies occurrences of three strings and replaces occurrences of four others. There are many options. However, the flexibility of some COBOL statements is usually due to historical accident - the additions of many proprietary extensions to the language before standardization - rather than any concerted effort to produce a highly-expressive syntax. In practice, few programs have any use for complex versions of STRING, INSPECT, and the like, though most do use them in the obvious ways. Consequently they don't do much to make COBOL terse. -- Michael Wojcik michael.wojcik@microfocus.com That's gotta be one of the principles behind reality. Accepting things that are hard to comprehend, and leaving them that way. And bleeding. Shooting and bleeding. -- Haruki Murakami (trans Philip Gabriel) .