inline comments, IDs 
Author Message
 inline comments, IDs

Hi,

How to:

1.
I have a long line of code (I know I know ;) ), and want to comment out
a span.
How to write an inline comment with begin and end?

2.
ID: something (digits and word characters or whatever) that's guaranteed
to be unique for the time the program runs. (random numbers could be
duplicate)

Tobi

--
Tobias Reif
http://www.*-*-*.com/

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.*-*-*.com/



Wed, 21 Apr 2004 07:17:22 GMT  
 inline comments, IDs

Quote:
> Hi,

> How to:

> 1.
> I have a long line of code (I know I know ;) ), and want to comment out
> a span.
> How to write an inline comment with begin and end?

=begin
         comments
         comments
=end
Quote:

> 2.
> ID: something (digits and word characters or whatever) that's guaranteed
> to be unique for the time the program runs. (random numbers could be
> duplicate)

How often do you start the prog.?
The number of s or ms .. that have passed since the Unix big-bang?
(read current time in s since 19..)

or
. if you seed your RNG with the current-time?

unless you write a high-security banking app.. I wouldn't worry
too much about "mathematically guaranteed" uniquness..

Quote:

> Tobi

--
Armin.

-----------------------------------------------
Armin Roehrl, http://www.approximity.com
"The best way to predict the future is to invent it."
                                          --Alan Kay



Wed, 21 Apr 2004 07:26:54 GMT  
 inline comments, IDs

Quote:

> Hi,

> How to:

> 1.
> I have a long line of code (I know I know ;) ), and want to comment out
> a span.
> How to write an inline comment with begin and end?

Do you think of a comment inside one line of code? This is not really
possible. But you could do it as follows:

before:
  3 + 4 + 5 + 5 - 4 - 5

after:
  3 + 4 + (%{5 + 5 - 4}; - 5)

Better is to copy the line and comment the duplicate out. Then modify
the other.

Quote:
> 2.
> ID: something (digits and word characters or whatever) that's guaranteed
> to be unique for the time the program runs. (random numbers could be
> duplicate)

Simply start with a string (or integer) of an arbitrary length (e.g.
"dlkjddfdfd"), then each time you want to generate a new ID, simply call
aString.succ!

Regards,

  Michael

--
Michael Neumann
merlin.zwo InfoDesign GmbH
http://www.merlin-zwo.de



Wed, 21 Apr 2004 07:32:01 GMT  
 inline comments, IDs

Quote:

> Do you think of a comment inside one line of code?

yep

This is not really

Quote:
> possible. But you could do it as follows:

> before:
>   3 + 4 + 5 + 5 - 4 - 5

> after:
>   3 + 4 + (%{5 + 5 - 4}; - 5)

OK

Quote:
> Better is to copy the line and comment the duplicate out.

Why?

Then modify

Quote:
> the other.
> Simply start with a string (or integer) of an arbitrary length (e.g.
> "dlkjddfdfd"), then each time you want to generate a new ID, simply call
> aString.succ!

Just thought of that; a simple counter + ~
format("%09.0f", counter)

..

Thanks for all the good advice. I'm already e{*filter*}d about your book ;)

Tobi

--
Tobias Reif
http://www.*-*-*.com/

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.*-*-*.com/



Wed, 21 Apr 2004 07:37:28 GMT  
 inline comments, IDs

Quote:

> ID: something (digits and word characters or whatever) that's guaranteed
> to be unique for the time the program runs. (random numbers could be
> duplicate)

What about combining (Time.now.to_f * 1000000).to_i and Process.pid?
Including the pid ensures that even if two process start at around the
same time, you get a different pair of numbers.

--
Joel VanderWerf                          California PATH, UC Berkeley

http://www.path.berkeley.edu                       FAX (510) 231-9512



Wed, 21 Apr 2004 07:44:41 GMT  
 inline comments, IDs

Quote:

> What about combining (Time.now.to_f * 1000000).to_i and Process.pid?
> Including the pid ensures that even if two process start at around the
> same time, you get a different pair of numbers.

id = format("%09.0f", counter) works.

Tobi
--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 07:47:24 GMT  
 inline comments, IDs

Quote:


> > Do you think of a comment inside one line of code?

> yep

> This is not really
> > possible. But you could do it as follows:

> > before:
> >   3 + 4 + 5 + 5 - 4 - 5

> > after:
> >   3 + 4 + (%{5 + 5 - 4}; - 5)

> OK

> > Better is to copy the line and comment the duplicate out.

> Why?

It looks nicer and do not confuse the reader (I think my example above would).

Quote:
> Just thought of that; a simple counter + ~
> format("%09.0f", counter)

yes, or

  counter = "0000000000"     # any string
  counter.succ!

would do it, too (but probably slower ;-).

Regards,

  Michael

--
Michael Neumann
merlin.zwo InfoDesign GmbH
http://www.merlin-zwo.de



Wed, 21 Apr 2004 07:54:48 GMT  
 inline comments, IDs

Quote:

> 2.
> ID: something (digits and word characters or whatever) that's guaranteed
> to be unique for the time the program runs. (random numbers could be
> duplicate)

Well, I've proposed once that we have Symbol.new or Symbol.gensym,
which acts like gensym in Lisp or Scheme.  Yes, it is not necessary in
this case since we can make unique IDs in process life long by
something like a counter, but gensym make some works clean.

How do you think?

--

What can't be seen is what can't be there.



Wed, 21 Apr 2004 10:43:08 GMT  
 inline comments, IDs

Quote:

> Well, I've proposed once that we have Symbol.new or Symbol.gensym,
> which acts like gensym in Lisp or Scheme.  Yes, it is not necessary in
> this case since we can make unique IDs in process life long by
> something like a counter, but gensym make some works clean.
> How do you think?

I've had occasional need for something similar.  
The following seemed to suffice:

class Gensym
  def initialize (label=:g, cnt=0)


  end
  def next


    return sym
  end
end  # class Gensym

g = Gensym.new(:foo)
g.next

or

g = Gensym.new("g-%s-" % $$)

Regards,

Raja



Thu, 22 Apr 2004 03:55:04 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. multi-lingual inline comments using rd...

2. Correction/Clarification on my comment on inline PERFORMs

3. Observation on Using // as the COBOL Inline Comment Indicator

4. porting inline Watcom asm to MSVC inline asm

5. FreeTDS vs Inline TDS: Problem with Inline TDS

6. FreeTDS vs Inline TDS: Problem with Inline TDS

7. select count(*) from test_file where id>100 and id<1000

8. Object IDs are good ( was: Object IDs are bad )

9. Testing if ID is a VALID TSO ID

10. expect_after executes for spawn id 1 even if the corresponding expect executes for spawn id 2

11. Counting commented lines (full-line comments only)

12. comments on comments

 

 
Powered by phpBB® Forum Software