Comments

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Comments

Postby EvanED » Wed Dec 05, 2007 5:52 am UTC

There are also other reasons to have some code in comments, for instance "here's something else we tried that looks like it should work, but it doesn't, and here's why", or "if some assumptions change about our environment, this function fails to be correct, and should be replaced by this more general, but somehow worse, version."

(I had one of the latter for a function that averaged two numbers. I currently do it in a short, trivially easy to understand manner, something like ((long long) a + b)/2. However, this breaks if sizeof(a)==sizeof(long long), and this is something that will actually be true some day. So it's accompanied by a STATIC_ASSERT(sizeof(long long) > sizeof(a)) and a comment that says "if this breaks, replace it with this more complex and harder to understand version", with the URL of this thread. ;-))

This is different from having commented-out code though.

User avatar
JamesCFraser
Posts: 32
Joined: Wed Nov 14, 2007 9:47 pm UTC

Re: Comments

Postby JamesCFraser » Thu Dec 06, 2007 1:23 pm UTC

enk wrote:
Spoiler:

Code: Select all

# TITLE:  Approximate Fraction         
# AUTHOR: Karl Ove Hufthammer
# EMAIL:  huftis@bigfoot.com
# WEB:    ?                   
# DATE:   ?
# MAKE:   CASIO
# MODEL:  9850     
# NOTES: 
#
# Just type in a number, and press EXE until you get a accurate enough
# fraction. It's useful with repeating decimal numbers (like 2,715151515...),
# but you can also get good approximations from other numbers (try pi!).

# The program displays the numerator (stored in U), the denominator
# (stored in V), the resulting number, the original number and the
# difference between these two.


@@ Program "APPFRAC"






"Number"?->N
N->B
1->R
Do
  10N->N
  10R->R
LpWhile Frac N<>0
1->S~Y
0->T~X
Do
  N->M
  R->N
  Int (M/N->Q
  M-QN->R
  QY+T->U
  QX+S->V
  U/V->Z
  Locate 2,1,U
  Locate 2,2,V
  Locate 2,3,"-------------"
  Locate 2,4,Z
  Locate 2,5,B
  Locate 2,6,"-------------"
  Locate 2,7,Abs (B-Z
  Do
  LpWhile Getkey<>31
  Y->T
  U->Y
  X->S
  V->X
  LpWhile R>0
Locate 2,7,"Finished"




Ugh, that is horrid :P

If you give me a link to the instruction set available for the Casio 9850, so I can envisage what's being done at each stage, I'm fairly sure I could work out how it works (unless it uses some tricky maths I haven't done before, but, from a glance, it doesn't look like it does). If I were writing something like this, I'd probably write out a version in Pascal, C or any generally readable language first, and then translate it into this rather awful looking code. Though, I did avoid getting a programable calculator purely because I thought the code would be a disappointment.

I probably should have made it more clear that I only work on smaller problems by myself, rather than working on larger problems as part of a team. I also tend to avoid using APIs for engines. I mainly write console applications, where the problems being solved are things like those on IBM's Ponder This site. I have a very consistent style for coding, and know why I gave a variable a certain name. I also tend to remember what I was thinking when I wrote something. For instance, without having to go back to the code for it, I can remember the methods I have used in programming compeititions from years ago. Mainly because they were so shockingly bad that I have wanted to improve them for ages :P

Anyway, I never got into adding comments, and am hoping I'll never have to. I don't like writing the kind of program that needs comments, and loathe working as part of a team.

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Re: Comments

Postby enk » Thu Dec 06, 2007 2:19 pm UTC

JamesCFraser wrote:
enk wrote:
Spoiler:

Code: Select all

# TITLE:  Approximate Fraction         
# AUTHOR: Karl Ove Hufthammer
# EMAIL:  huftis@bigfoot.com
# WEB:    ?                   
# DATE:   ?
# MAKE:   CASIO
# MODEL:  9850     
# NOTES: 
#
# Just type in a number, and press EXE until you get a accurate enough
# fraction. It's useful with repeating decimal numbers (like 2,715151515...),
# but you can also get good approximations from other numbers (try pi!).

# The program displays the numerator (stored in U), the denominator
# (stored in V), the resulting number, the original number and the
# difference between these two.


@@ Program "APPFRAC"






"Number"?->N
N->B
1->R
Do
  10N->N
  10R->R
LpWhile Frac N<>0
1->S~Y
0->T~X
Do
  N->M
  R->N
  Int (M/N->Q
  M-QN->R
  QY+T->U
  QX+S->V
  U/V->Z
  Locate 2,1,U
  Locate 2,2,V
  Locate 2,3,"-------------"
  Locate 2,4,Z
  Locate 2,5,B
  Locate 2,6,"-------------"
  Locate 2,7,Abs (B-Z
  Do
  LpWhile Getkey<>31
  Y->T
  U->Y
  X->S
  V->X
  LpWhile R>0
Locate 2,7,"Finished"




Ugh, that is horrid :P

If you give me a link to the instruction set available for the Casio 9850, so I can envisage what's being done at each stage, I'm fairly sure I could work out how it works (unless it uses some tricky maths I haven't done before, but, from a glance, it doesn't look like it does).

It's been four years since I tried deciphering it, but I'm still casually interested, actually :)
I haven't found an instruction set, but I still know it by heart:

Spoiler:

Code: Select all

"text"?                 asks for input (numbers only)
A->B                    assigns A to B
A->B~E                  assigns A to the range from B to E, both inclusive
Int(                    returns integer part (cuts of decimal part). Functions don't need closing parens
Do:LpWhile Getkey<>31   just means loop while EXE isn't pressed, i.e. wait for EXE to be pressed.
Locate 2,5,B            prints number or string (in "") on line 5, starting in column 2.


When running with Pi, the display will show (on second iteration):

 22                      fraction
 7                       fraction
 -------------
 3.142857143             value of fraction
 3.141592654             original value
 -------------
 0.00126448926           difference



JamesCFraser wrote:If I were writing something like this, I'd probably write out a version in Pascal, C or any generally readable language first, and then translate it into this rather awful looking code. Though, I did avoid getting a programable calculator purely because I thought the code would be a disappointment.

I guess if you knew a real programming language already, going to a programable calculator, would be a drawback. But I think starting on one worked out fine for me. Also, it was nice to be able to program anywhere and anywhen - fits in a large pocket, boots in .1 seconds. Of course, for most of my later projects I had to bring several sheets of hand written pseudo code and design notes, that wasn't too stylish.
phlip wrote:Ha HA! Recycled emacs jokes.

User avatar
Hangar
Posts: 171
Joined: Fri Nov 23, 2007 3:41 am UTC

Re: Comments

Postby Hangar » Thu Jan 10, 2008 9:08 pm UTC

What do you think about the html comments from the other thread? Personally I think I'd like to see my code with comments that look like documentation, with cross-references and such. Would be nice to have a button on the bar like those that expand/close your blocks that would switch a comment back and forth between generated documentation and the original text. (In something like Doxygen format.)

Also, I kinda like having a different, non-fixed-width font for comments. And not in some pastel green so that it's hard to read.

User avatar
segmentation fault
Posts: 1770
Joined: Wed Dec 05, 2007 4:10 pm UTC
Location: Nu Jersey
Contact:

Re: Comments

Postby segmentation fault » Mon Jan 14, 2008 7:24 pm UTC

whatever as long as you include your initials and i can know who wrote the silly comment :)
people are like LDL cholesterol for the internet

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Comments

Postby evilbeanfiend » Thu Jan 17, 2008 3:10 pm UTC

well i'm required to use doxygen comments. so its mostly

Code: Select all

//! Comment.
in ur beanz makin u eveel

User avatar
Benny the Bear
Posts: 146
Joined: Sat Oct 27, 2007 2:44 am UTC
Location: Melbourne, Australia
Contact:

Re: Comments

Postby Benny the Bear » Sun Mar 09, 2008 9:40 am UTC

My style:

Code: Select all

// sentence.

/* Title
*Para
*Graph
*/



Not a fan of # or ' commenting at all.

User avatar
xyzzy
Meta-Titled
Posts: 263
Joined: Sun Mar 18, 2007 10:02 pm UTC
Location: Colossal Cave
Contact:

Re: Comments

Postby xyzzy » Tue Mar 11, 2008 6:33 pm UTC

enk wrote:Ow.. that beats my Casio fx-9750G PLUS. Only six lines of code visible, each line 21 chars long. But I learned the basics of coding on that machine. Of course, most of my programs and games started as pseudo code on paper :)

Comments, however, are possible on the Casio. Just write it between double quotes:

Code: Select all

?->A
"MAIN LOOP"
Do
...
...
...


Hey, we have the same calculator.

It's nasty to get the hang of programming it, because I cut my teeth with scheme, so it's a massive departure. I mostly use it for automating repetitive jobs --- calculating statistical bits and the like.
"Wile E. Coyote was a theoretical mathematician." - Leliel
"Modern life can be so boring without elements of the bizarre or the fantastical. Hence, we have steampunk." - Me

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Re: Comments

Postby enk » Wed Mar 12, 2008 2:44 pm UTC

xyzzy wrote:Hey, we have the same calculator.

It's nasty to get the hang of programming it, because I cut my teeth with scheme, so it's a massive departure. I mostly use it for automating repetitive jobs --- calculating statistical bits and the like.


I can imagine the drop :shock:

I don't use mine for programming now but it had its time of glory :)
phlip wrote:Ha HA! Recycled emacs jokes.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 4 guests