From: Pascal J. Bourguignon on
Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups(a)NTLWorld.COM>
writes:

>>
>>>
>>> Such edicts make one want to write code in the form
>>>
>> x /* The variable x */
>> = /* is assigned */
>> x /* its value * /
>> + /* plus * /
>> 2 /* two */
>> ; /* . */
>>
>> Correction applied. HTH.
>>
> As you now know, you got the correction wrong. This was a
> deliberately subtle point. The discrepancy in the mandatory comment
> prose caused you to overlook another error. I deliberately made it a
> well-known and fairly basic C programming error that most of the
> people participating in this thread from comp.lang.c should all be
> familiar with, and regularly leap upon in posted code, moreover.

Moreover, the original might have been correct actually. For example,
with the following declarations:

enum{ POINTER_TAG=0,
FIXNUM_TAG,
TAG_MASK=1,
BIGNUM_TAG=2,
CHAR_TAG,
STRING_TAG,
CONS_TAG,
ARRAY_TAG
/* ... */ };

typedef int object;

int boxed_tag(object o){
unsigned char* p=(char*)o;
return((int)(*p)); }


object x=((random()&1)==0)?FIXNUM_TAG:fixnum_to_bignum(FIXNUM_TAG);

if((x&TAG_MASK)==FIXNUM_TAG){
x /* The variable x */
= /* is assigned */
x /* its value * /
+ /* plus * /
2 /* ONE */
; /* . */
}else if(boxed_tag(x)==BIGNUM_TAG){
x=bignum_add(x,fixnum_to_bignum(2)); /* still ONE */
}else{
type_error("x must be an integer");
}



--
__Pascal Bourguignon__
From: Larry__Weiss on
Jongware wrote:
> .. and suddenly it makes sense, even to one not used to assembly.
>

Assembly is the one instance where I find comments mandatory to writing good code.

In languages where I'm not constrained in choosing names, I just write readable
code.

- Larry
From: Jonathan de Boyne Pollard on
>
>
> One could avoid the bug in the earlier code by writing it [using C++
> style comments].
>
Don't forget what I wrote about the problems of posting code to Usenet
in text/plain bodyparts. (For best results, compare what your NUA
displays to you with the raw text of the posting.)

x // The variable x
= // is assigned
// FIXME: The spec says:
1.0
/
x // its value
+ // plus
2.0 // one
; // .

From: Scott Lurndal on
Jongware <jongware(a)no-spam.plz> writes:
>On 18-Mar-10 14:01 PM, spinoza1111 wrote:
>> On Mar 17, 2:13 am, gaze...(a)shell.xmission.com (Kenny McCormack)
>> wrote:
>>> In article<IU.D20100316.T165150.P1185...(a)J.de.Boyne.Pollard.localhost>,
>>> Jonathan de Boyne Pollard<J.deBoynePollard-newsgro...(a)NTLWorld.COM> wrote:
>>>
>>>>>> ... which only serve to increase the noise floor.
>>>
>>>>> In our shop, those appeared when we got the idiotic edict that each
>>>>> line had to have a comment.
>>>
>>>> Such edicts make one want to write code in the form
>>>
>>>> x /* The variable x */
>>>> = /* is assigned */
>>>> x /* its value * /
>>>> + /* plus * /
>>>> 2 /* two */
>>>> ; /* . */
>>
>> Nothing wrong with this style of commenting in assembler, at all.
>
>Really? Example: (from a previous discussion on comp.programming)
>
> mov edx,len ; move constant into register edx
> mov ecx,msg ; move address into register ecx
> mov ebx,1 ; move constant into register ebx
> mov eax,4 ; move constant into register eax
> int 0x80 ; call system interrupt
>
> mov eax,1 ; move constant into register eax
> int 0x80 ; call system interrupt
>
>This is Intel 80x86 assembly, and the comments exactly describe what
>each of the opcodes do -- completely comparable to your
>
>+ /* plus */
>
>Now how useful is that? Compare with:
>
> mov edx,len ;message length
> mov ecx,msg ;message to write
> mov ebx,1 ;file descriptor (stdout)
> mov eax,4 ;system call number (sys_write)
> int 0x80 ;call kernel
>
> mov eax,1 ;system call number (sys_exit)
> int 0x80 ;call kernel
>
>.. and suddenly it makes sense, even to one not used to assembly.
>
>[Jw]

Another example (real-world, from data comm module in a Burroughs MCP)

..TEXT BST -HHT Must move text too
..BIGUN LIX IH-1AV X5 IX1 Get first header
CPN NILPTR IX1 End of list?
EQL +NAKU Yes, NAK & Unlock
MVW TP-FWD X1 IH-1AV X5 Set new flink
BST TP-BIG X1 Note large header
..GOTIT UNLK IH-TLK X5 Unlock tag pool
MVW DP-HDR X6 TP-ENT X1 Move header to tag
SIX -TAGP IX1 Save tag pointer

scott
From: Seebs on
On 2010-03-19, jmfbahciv <jmfbahciv(a)aol> wrote:
>> does the name Edward Nilges ring a bell?

> Nope.

Ahh, you're missing... well.

Edward Nilges is this guy. He's spent the last couple of years railing
against the Cruele And Unjust Turns Of Fate by which Herbert Schildt has
acquired a negative reputation. For instance, because every competent
programmer who's ever commented on his books says they're pants.

He recently responded to my posting of a quick one-off solution to a problem
(figure 10-15 lines of code) with a >100 line version which took him a couple
of hours to write, and several hours to debug. To demonstrate by complete
incompetence at choosing variable names, he had variables named ptrIndex0,
ptrIndex1, ptrIndex2, and ptrIndex3.

The amazing thing is that, so far as anyone can tell, he actually believes
himself to be serious. Never mind that he has repeatedly sworn to sue various
people for defamation and never yet gotten to it.

Here's a fairly representative example:
> In particular, Stroustrup had learned about
> object oriented programming using Simula in Denmark before coming to
> the US, because in Denmark labor unions had real power and demanded
> that factory automation be documented for union oversight.

That was on one of his comparatively lucid days.

(Posting in detail just because afc people might find this amusing.)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
First  |  Prev  |  Next  |  Last
Pages: 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prev: System Calls
Next: Warning to newbies