HDTenEightyP/NetNews huggingface dataset:
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.programming
Subject: functions & return values (was Re: Reinventing the wheel)
Date: 10 Apr 92 21:35:58 GMT
Organization: U of Arizona CS Dept, Tucson

In article <sc5H&#7m6@cs.psu.edu> schwartz@roke.cs.psu.edu (Scott Schwartz) writes:
>dave@cs.arizona.edu (Dave Schaumann) writes:
>   I think that far more often than not, when you wish you could
>   return two values from a function, what you really need to do is
>   re-examine your data structures, and not redesign the language.
>
>You argue that returning multiple values is not as nice as returning a
>single structure.  Do you also think that passing multiple values is
>bad, and that one should just pass a structure? 

No, not necessarily.  The idea of subroutine-as-function works well
in many cases, but I think this paradigm breaks down when you attemt
to have a `function' that returns more than one value.

Given a language like C, in which structs and the & operator (for call-by
reference parameters), a superior solution is already in place.  There is
simply no need to add the extra ambiguity that multiple return values
would introduce.

To bring up a specific example, which would you rather have to debug --
a program supporting this language construct:

  foo a ; bar b ;

  . . .

  { a, b } = quux() ;

or something like this:

  struct foobar{ foo a ; bar b ; } ;

  foo a, bar b ; foobar baz ;

  . . .

  baz = quux() ; a = baz.a ; b = baz.b ;
  /* may not even be necessary to have explicit a and b vars now... */

The same programming power is available with both constructs; but in the
second, the programmer doesn't have to remember that the first value
returned is a foo and the second is a bar; the compiler takes care of
it instead.

This, IMHO, is one of the great strenths of OO programming, since many
of the operand values are encapsulated in the class, and so the method
calls are less complicated (at least syntactically) since all these
values are implicit parameters to the method (of course, OO also encourages
such encapsulation anyway).


>On the other hand, allowing functions to take multiple
>values as parameters, but not to return them is needlessly inconsistent.

As I indicated above, I view the function as a minor extension of the
procedure.  I really think that adding multiple return values to functions
needlessly clutters the language, especially when you consider that structs
and call-by-reference parameters offer a superior (and in most languages)
an already-existing option.

-- 
Dave Schaumann			dave@cs.arizona.edu
Newsgroups: comp.programming
From: jsteele@netcom.com (John Steele)
Subject: Re: Multi-tasking kernel
Date: Sun, 12 Apr 92 08:38:21 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 

In <STEPHEN.92Apr11210424@estragon.uchicago.edu> stephen@estragon.uchicago.edu (Stephen P Spackman) writes:

>In article <1992Apr11.122628.2131@nuscc.nus.sg> eletanjm@nuscc.nus.sg (Tan Jin Meng @ NUS) writes:
>|Why don't you write one yourself? You can in fact write a simple and
>|completely portable non preemptive multitasking kernel by just using the
>|standard C routines setjmp() and longjmp().

>How? Where are the stacks stored? Suddenly you have more than one....

Although this probably belongs in comp.lang.c, a good reference to your
question can be found in _Born to Code in C_ by Herbert Schildt.  Published
by Osborne McGraw-Hill, ISBN 0-07-881468-5.

He covers this well in Chapter 4 - A Multitasking Kernal for DOS, both in 
concept and code.

I mention this here only for the fact that this in fact *might not be* C
specific, and the concepts are solid and useable in any language that can
support the longjmp/setjmp functionality (flamers, see below :)

John
-- 
#include <disclaimer.h>			/* route all flames to /dev/null  */
/**************************************************************************/
/*   Systems Analyst      | John Steele     email: jsteele@netcom.com     */
/* Video Business Systems |                                               */
/*   1-800-255-3088       |    Most people spell COBOLSUX incorrectly...  */
/**************************************************************************/
From: koontz@iasdv1.iasd.honeywell.com (Sean C. Koontz)
Subject: Programming Standards Question
Reply-To: koontz@iasdv1.iasd.honeywell.com
Organization: Honeywell,Phoenix,AZ
Date: Tue, 14 Apr 1992 17:32:48 GMT

Hi, I hope this is relevant to this newsgroup (I think it is).

Some colleagues and I were recently discussing proposed coding
standards that should be checked for when doing code reviews.
As a reference, we were using a list that someone had obtained
from some book on Software Engineering.  One of the items on
the list said that for code reviews one thing that should be 
checked is the use of "negative Boolean logic".  It was stated
that "negative Boolean logic" should not be used in order to 
aid maintainability.  At this point, the group was divided on
what was exactly meant by "No negative Boolean logic".  Does
anyone have any idea what this means and how it applies to 
increased maintainability?

Sean

"koontz@iasdv1.iasd.honeywell.com"
From: ahernsd@expert.cc.purdue.edu (Sean Ahern)
Newsgroups: comp.programming
Subject: Random numbers in C
Date: 7 Apr 92 20:07:41 GMT

I was writing a piece of C code in which I was generating random numbers.
The thing was, I wanted to generate DIFFERENT random numbers every time I
execute the binary.  I tried to use the following lines to seed the random
number generator:

#include <time.h>
main(argv,argc)
int argv;
char *argc[];
{
	/* stuff deleted */
	struct tm t;

	/* stuff deleted */

	srandom(time(&t));

	/* more stuff deleted */
}

Unfortunately, this didn't work.  But when I do this, it works:

srandom(time(NULL));

***********************
Can anyone tell me why?
***********************
-- 
Sean Ahern-----------------Rollerblade!-----------ahernsd@expert.cc.purdue.edu
Any sufficiently advanced bug is indistinguishable from a feature.
Newsgroups: comp.programming
From: tom@dtint.uucp (Thomas R. Kimpton)
Subject: Re: Reinventing the wheel
Organization: Digital Technology, International
Date: Sat, 11 Apr 92 00:20:56 GMT

In article <1992Apr08.115757.10212@ibmpcug.co.uk> dylan@ibmpcug.co.uk (Matthew Farwell) writes:
>In article <PDS.92Apr2170934@lemming.webo.dg.com> pds@lemming.webo.dg.com (Paul D. Smith) writes:
>>The goal of "code reuse" is simply to allow more reliable programs to
>>be developed more quickly.  Then you go back and make it better!
>>That's the interesting part of coding anyway... :-)  Here're the keys
>>to software engineering, as I see them:
>>

I'm not a member of CACM, but I've heard that they have a collection
of algorithms (Collected Algorithms of the ACM?).  Does anyone
have this, use this, find it useful?  I've never seen it, and I
was wondering if it's worthwhile.

-- 
---
Tom Kimpton                            tom@dtint.dtint.com
Digital Technology Int.                (801)226-2984	
500 W. 1200 South, Orem UT, 84057      FAX (801) 226-8438
From: mrt@ems.cdc.com (Mike Tiller)
Newsgroups: comp.programming
Subject: Re: Programming Standards Question
Date: 14 Apr 92 23:13:20 GMT
Reply-To: mrt@ems.cdc.com
Distribution: na
Organization: Empros Systems International, a division of CDC

In article <1992Apr14.173248.9363@src.honeywell.com>, koontz@iasdv1.iasd.honeywell.com (Sean C. Koontz) writes:
|> Hi, I hope this is relevant to this newsgroup (I think it is).
|> 
|> Some colleagues and I were recently discussing proposed coding
|> standards that should be checked for when doing code reviews.
|> As a reference, we were using a list that someone had obtained
|> from some book on Software Engineering.  One of the items on
|> the list said that for code reviews one thing that should be 
|> checked is the use of "negative Boolean logic".  It was stated
|> that "negative Boolean logic" should not be used in order to 
|> aid maintainability.  At this point, the group was divided on
|> what was exactly meant by "No negative Boolean logic".  Does
|> anyone have any idea what this means and how it applies to 
|> increased maintainability?
|> 
|> Sean
|> 
|> "koontz@iasdv1.iasd.honeywell.com"

Here's my interpretation.  One example of negative logic would be:

	if (i < 3 && j > 5)
		;
	else
		statement;

The programmer wanted to do something when the condition was not true.  One
might be tempted to fix this by changing it to:

	if (!(i < 3 && j > 5))
		statement;

However, this is still hard to read and is still negative logic.  So we
apply DeMorgan's laws:

	!(A || B || C ...) = !A && !B && !C ...
			and
	!(A && B && C ...) = !A || !B || !C ...

Applying these to the above we have:

	if (!(i < 3) || !(j > 5))
		statement;

Which can be further simplified to:

	if (i >= 3 || j <= 5)
		statement;


BTW, Straker has an excellent book on coding standards.
-- 
Mike Tiller
mrt@ems.cdc.com
-- 
Mike Tiller
mrt@ems.cdc.com
Newsgroups: comp.programming
From: eggert@twinsun.com (Paul Eggert)
Subject: Re: Difference between SCCS and RCS
Organization: Twin Sun, Inc
Date: Fri, 10 Apr 1992 22:25:02 GMT

lowry@watson.ibm.com (Andy Lowry) writes:

>SCCS maintains forward diffs from a base consisting of the original text,
>while RCS maintains the latest text as a base and has reverse diffs to
>reconstruct prior versions.

This is correct for RCS, but SCCS does not use forward diffs: it
uses an interleaved format such that any version can be retrieved by
selecting a (typically noncontiguous) subsequence of lines from the
history file in a single pass.

Recent versions of RCS are usually faster than SCCS on real examples,
even when retrieving old versions, but the full story is more complicated
than just the issue of reverse vs interleaved diffs.
From: stephen@estragon.uchicago.edu (Stephen P Spackman)
Newsgroups: comp.programming
Subject: Re: Names
Date: 12 Apr 92 13:53:37 GMT
Article-I.D.: estragon.STEPHEN.92Apr12085346
Distribution: comp
Organization: University of Chicago CILS

In article <_tvj_qk.mdg@netcom.com> mdg@netcom.com (Mark Grand) writes:
|I wish I had an answer for you.  The ideal naming convention would
|descriptive allow entities to be classifed in such a way as to promote
|reuse of code.  Using such a scheme, if confronted with a large mass
|of unfamiliar code, it would be possible to find what you were looking
|for by by constructing a name for it.  Since the names would be
|descriptive, I should be able to find what I was looking for in just a
|few tries.

Good point; a controlled vocabulary is as important in the long term
as a fixed morphosyntax. A friend of mine satisfies this through the
bizarre (are you listening Sti? :-) expedient of maintaining a code
book of three letter abbreviations, and using them to construct ALL
identifiers. I don't find his code very readable but it certainly has
the property of unambiguity: given an identifier you know what it
means, and given a meaning you have an excellent chance of guessing
the identifier the first time.... (-: but it takes a strong stomach to
deal with "UPP" for "up" and a good memory to distinguish block from
black :-).
----------------------------------------------------------------------
stephen p spackman         Center for Information and Language Studies
stephen@estragon.uchicago.edu                    University of Chicago
----------------------------------------------------------------------
Newsgroups: comp.programming
From: allan@cs.cornell.edu (James Allan)
Subject: Re: Programming Standards Question
Organization: Cornell Univ. CS Dept, Ithaca NY 14853
Date: Tue, 14 Apr 1992 19:53:17 GMT

koontz@iasdv1.iasd.honeywell.com (Sean C. Koontz) writes:
>Some colleagues and I were recently discussing proposed coding
>standards that should be checked for when doing code reviews.
>As a reference, we were using a list that someone had obtained
>from some book on Software Engineering.  One of the items on
>the list said that for code reviews one thing that should be 
>checked is the use of "negative Boolean logic".  It was stated
>that "negative Boolean logic" should not be used in order to 
>aid maintainability.  At this point, the group was divided on
>what was exactly meant by "No negative Boolean logic".  Does
>anyone have any idea what this means and how it applies to 
>increased maintainability?

Heh.  I have a friend who worked at a COBOL (gasp!) shop that
interpreted it to mean that you should never have a negative in the
the IF clause.  So instead of,

	IF A NOT = B
		do something.

you had to write,

	IF A = B
		NEXT SENTENCE
	ELSE
		do something.

The convoluted code they ended up with was so amusing it almost made
COBOL enjoyable!
Newsgroups: comp.programming
From: stephen@estragon.uchicago.edu (Stephen P Spackman)
Subject: Re: Perfect hash summary....
Organization: University of Chicago CILS
	<STEPHEN.92Apr5190701@estragon.uchicago.edu>
	<1992Apr7.041826.23365@uxa.ecn.bgu.edu>
Date: Tue, 7 Apr 1992 06:39:47 GMT

In article <1992Apr7.041826.23365@uxa.ecn.bgu.edu> miss059@uxa.ecn.bgu.edu (Pug) writes:
|In article <STEPHEN.92Apr5190701@estragon.uchicago.edu> stephen@estragon.uchicago.edu (Stephen P Spackman) writes:
|>This may seem like an odd question, but does anyone have a USE for
|>minimal perfect hashing? The "obvious" one, in programming languages,
|>is somewhat bogus, since in that case you have a symbol table anyway,
|>and it's faster and easier just to treat keywords like identifiers
|>through until the parser (unless, I suppose, your language has really
|>different rules for the two classes so that the lexer is better off
|>making the discimination).
|
|The place where I was using it was the OpCode table for an Assembler I
|was writing for a class. It only called for a linear search, but I just
|wanted to experiment with perfect hashes so I wrote one. Admittedly you
|can usually find any opcode with a linear search in 6 probes or so, but
|one is awefully nice. If the function for the hash has less overhead
|than 5 linear probes, then it pays off when there are lots of them. When
|comparing my code against the same code with a linear search, there was
|a visible difference in runtime.

But this actually makes my point nicely. If this were not a class
project (for which, as you say, linear search is the method of choice)
but a real-world programme, you would in all probability be
implementing a MACRO-assembler, and you would therefore have a dynamic
set of identifiers to look up, and perfect hashing would be
inappropriate, because you will either get collisions or need a second
hash table for the macros, which is dumb because (modulo, perhaps,
redefinition rules) they're in the same namespace....
----------------------------------------------------------------------
stephen p spackman         Center for Information and Language Studies
stephen@estragon.uchicago.edu                    University of Chicago
----------------------------------------------------------------------
From: tt@remus.jyu.fi (Tapani Tarvainen)
Newsgroups: comp.programming
Subject: Re: need a HINT on a C code parsing name-strings
Summary: there are longer names than are dreamt of in your philosophy
Date: 6 Apr 92 06:53:02 GMT
Organization: University of Jyvaskyla
Originator: tt@remus.jyu.fi

In article <92096.184215DECBC@CUNYVM.BITNET> DECBC@CUNYVM.BITNET writes:

>I am writing a C code to parse an input string formatted in
>'lastname,firstname,middle-initial' of each field is varying
>length and total length is 30 bytes, into three separate
>strings, 'lastname,' 'firstname,' and 'middle-initial.'

I just feel like quibbling: it is not generally safe to assume the
above information fits in 30 characters.  Better make it 40 at least,
preferably 50, lest your program crash on that fateful day it
encounters Mr. Itsaraphong V. Intharawithayaanan (yup, that's a real
name).  I have seen at least 14-character first names and 30-character
last names, so though I can't remember any over 40-character
combination, it isn't impossible.  (Middle initial is less likely to
vary ... except that there might be none, even if US laws require it.)

Or, to quote The 10 Commandments for C Programmers by Henry Spencer:

	surely where thou typest ``foo'' someone someday shall
	type ``supercalifragilisticexpialidocious''.

--
Tapani Tarvainen    (tarvaine@jyu.fi, tarvainen@finjyu.bitnet)
From: andrew@highland.oz.au (Andrew Morton)
Newsgroups: comp.programming
Subject: comp.programming is broken
Date: 16 Apr 92 01:21:27 GMT
Organization: Highland Logic, Moss Vale, Australia

Well, Dan, it didn't take long. The signal to noise ratio
here is about 10%.  In retrospect the problem is
in the name.  'comp.programming' is the first thing
that people are going to reach for for a whole
range of questions.

It should have been comp.algorithms.  Ah well.
From: rbe@yrloc.ipsa.reuter.COM (Robert Bernecky)
Newsgroups: comp.programming
Subject: Re: Engineering philosophy in programming (was: Re: Editor theory?)
Date: 8 Apr 92 18:12:29 GMT
Reply-To: rbe@yrloc.ipsa.reuter.COM (Robert Bernecky)
Organization: Snake Island Research Inc, Toronto

In article <407@idtg.UUCP> dow@idtg.UUCP (Keith Dow) writes:
>>"They see as giants, those who stand on the shoulders of those who have
>>  gone before them."
>>
>>  Original quotation and author forgotten. The thought is applicable.
>
>"If have have seen farther, it is because I have stood on the sholders
>of giants."
>
>
>More accurate quote.
>
>		Isaac Newton to Robert Hook
>
>Hook was a hunch back who tried to claim credit for the law of universal
>gravitation.  What most people regard as a profound quote may have 
>started as a big insult.

If I may be permitted the USENET sin of A Real Reference, and 
(worse yet), A Citation:

If I have seen further (than you and Descartes) it is by standing on
the shoulders of Giants.
  Letter to RObert Hooke, February 5, 1675/1676.
 See Lucan 118:7 and Burton 258:7

This from Bartlett's Familiar Quotations, Fifteenth Edition, 1980.

Also: 
 Lucan (A.D. 39-65):
Pigmies placed on the shoulders of giants see more than the giants themselves.
  The Civil War, Bk. II, 10. (Didacus Stella)

 Robert Burton (1577-1640):
 I say with Didacus Stella, a dwarf standing on the shoulders of a giant
 may see farther than a giant himself.
  The Anatomy of Melancholy, Democritus to the Reader.





Robert Bernecky      rbe@yrloc.ipsa.reuter.com  bernecky@itrchq.itrc.on.ca 
Snake Island Research Inc  (416) 368-6944   FAX: (416) 360-4694 
18 Fifth Street, Ward's Island
Toronto, Ontario M5J 2B9 
Canada
From: stephen@estragon.uchicago.edu (Stephen P Spackman)
Newsgroups: comp.programming
Subject: Re: Recursive structure copying
Date: 16 Apr 92 14:01:49 GMT
Distribution: comp
Organization: University of Chicago CILS

Copying cyclic structures:

You're writing a garbage collector here. Consider:

(1) using an is-copied-yet state bit in ecah object (if you want to
avoid resetting it, you could use a number, but that will overflow in
the end).

(2) use pointer-reversal.

I'm not sure what else works in honest pure C. I'm sure there ARE
several more.

Making such things work in a general setting was what my thesis work
was about, and I have to admit that this aspect was a problem I didn't
solve.
----------------------------------------------------------------------
stephen p spackman         Center for Information and Language Studies
stephen@estragon.uchicago.edu                    University of Chicago
----------------------------------------------------------------------
From: mpl@maths.tcd.ie (Micheal Lunny)
Newsgroups: comp.programming
Subject: Re: Programming Standards Question
Date: 16 Apr 92 18:38:27 GMT
Organization: Dept. of Maths, Trinity College, Dublin, Ireland.

In <1992Apr16.001019.25079@rlgvax.Reston.ICL.COM> scc@rlgvax.Reston.ICL.COM (Stephen Carlson) writes:

>Basically, negative logic is the convention of setting 0 for truth and 1 (or
>non-zero) for falsehood.  It is used in computer engineering to simplify the
>logic of digital circuits.

Hmm.  I always got the impression that the number returned from
access (and indeed x other system calls and utilities) was an
error number rather than a success code.  Hence 0 is quite logical
as a return value indicating zero errors.  Allowing the use of all
non zero numbers as error codes should also allow a variety of
errors to be indicated.  A program typically suceeds in only one way
but can bomb out in n different ones. ( where n < 255 8-} )

>This occasionally crops up in UN*X programming, too.  For example, the
>access(2) system call returns 0 if it works and -1 if it fails.  Negative
>logic.  It is most confusing when used in conjunction with an if statement:

>	if (access("filename", 001))
>		...;

>The casual reader would likely get the wrong sense, causing him to overlook
>a bug in the code or "fix" something that works.  Certainly both these cases
>decrease maintainability.

In my opinion casual readers shouldn't be allowed to modify 
existing code anyway, especially if you haven't even bothered
to comment it.

>P.S.  Explicitly testing those sytems calls against ERR (-1) converts them to
>positive logic and is quite readable:

Positive logic has no implicit advantage over negative logic in
decision structures.  Programmers are not under the same restraints
as engineers in that positive and negative logic have the same "cost"
so there is  no need whatsoever to stick to using exclusively one type.

>	if (access("filename", 001) != ERR)
>		...;

Why bother?  Just comment the damn thing so its function is
obvious.

>-- 
>Stephen Carlson           | ICL OFFICEPOWER Center    | In theory, theory and
>scc@rlgvax.reston.icl.com | 11490 Commerce Park Drive | practice are the same.
>..!uunet!rlgvax!scc       | Reston, VA  22091         |    (703) 648-3300


--

| mplunny@vax1.tcd.ie |  Today you achieved nothing.
|      ,              |  So today you achieved as much as most people do
| Micheal Lunny       |  in their entire lives.  Satisfied?
Newsgroups: comp.programming
From: jpenne@ee.ualberta.ca (Jerry Penner)
Subject: Re: How To Calculate Logarithm?
Organization: University Of Alberta, Edmonton Canada
Distribution: comp
Date: Sat, 11 Apr 1992 01:14:06 GMT

markh@csd4.csd.uwm.edu (Mark William Hopkins) writes:

>In article <PAUL.92Apr10104516@nsx.kagaku.se.fujitsu.co.jp> paul@kagaku.se.fujitsu.co.jp (Paul Donnelly) writes:
>>Can anyone help me with calculating logarithms - either natural
>>logarithms or base 2 logarithms? I wish to implement these functions
>>for *fixed* precision numbers in machine code for use in a data
>>compression algorithm...

>If you can find a good way to do square roots, especially of numbers near
>1 (where sqrt(1 + d) ~~ 1 + d/2), then the following will work for large
>enough N:

>Y = ln(X):
>----------
>for (Y = X, I = 0; I < N; I++) Y = sqrt(Y);
>Y--; Y <<= N;

Actually, the easiest way to compute logarithms is to use CORDIC
hyperbolic algorithms.  They were described in Dr. Dobbs Journal in
1989 or 1990 (can't remember which month).  The article supplied
source code in C to perform CORDIC manipulations on 32-bit fixed point
numbers so that all trigonometric and hyperbolic functions (including
LOG) could be done.  All these algorithms are very fast since they
only do adds, subtracts, shifts and comparisons.  Most hardware math
chips use some variant of these CORDIC routines.  The Dr. Dobbs
article is basically a review and analysis of the CORDIC algorithm
which was originally published in 1959 if I remember correctly.

If you can't find the article, e-mail me and I'll dig up where exactly
the article was and maybe even the source of the original 1959
article.
-- 
Jerry Penner | jpenne@ee.ualberta.ca |   Two-line signatures are   |
Edmonton, AB |  alberta!bode!jpenne  | eye-nvironmentally friendly.|