Skip to content

Instantly share code, notes, and snippets.

@loverdos
Created October 24, 2011 21:16
Show Gist options
  • Select an option

  • Save loverdos/1310344 to your computer and use it in GitHub Desktop.

Select an option

Save loverdos/1310344 to your computer and use it in GitHub Desktop.
Typesafe Scala comments
object Comment {
def comment[T](t: => T): Unit = {}
}
// Usage
comment {
List(1, 2, 3).map(_ * 2)
}
@dcsobral

Copy link
Copy Markdown

Why?

@propensive

Copy link
Copy Markdown

I think the only reasonable answer is "why not?".

@dfreeman

Copy link
Copy Markdown

Nice, but how much will a ton of these slow down Scala's already-tortoisesque compiler?

@yuanw

yuanw commented Oct 25, 2011

Copy link
Copy Markdown

exactly, why?

@missingfaktor

Copy link
Copy Markdown

I have this in my utils too, I call it skip. :-)

@retronym

Copy link
Copy Markdown

Now, rename it example and integrate it into scaladoc.

@pedrofurla

Copy link
Copy Markdown

Wouldn't using @elidable make more sense?

@pedrofurla

Copy link
Copy Markdown

@retronym, interesting you mention that, I wrote a plugin that would allow exact that. The idea was to show the sources of a computation along with the result of the computation for using in presentations. It would make perfect sense to have it Scaladoc.

@loverdos

Copy link
Copy Markdown
Author

Thanx all for commenting. Even the "whys". There is no why when researching :) And as a matter of fact the conversation opened up the possibilities.

@retronym

Copy link
Copy Markdown

@pedrofurla Sounds cool! I get really worried when people add code examples to Scaladoc that will inevitably suffer bit-rot.

@loverdos

Copy link
Copy Markdown
Author

@pedrofurla @retronym

I have actually used it as a documentation tool too (as in: " to remember this algorithm" or "provide an alternative") and not just a throw-away comment.

@dcsobral

Copy link
Copy Markdown

@retronym @pedrofurla Personally, I think all examples tagged with @example should be compilable (ie, all includes necessary) and compiled -- as in, Scaladoc generates errors/warnings if they can't be compiled. I'll accept auto-importing of the class/object/whatever in question, however. :-)

@pedrofurla

Copy link
Copy Markdown

@dcsobral yes, I totally agree. This makes me wonder how hard would it be to make the example taglet inject its contents into the ASTs, and even compile and run it and give back the result to the Scaladoc tool... Feels a lot harder than the plugin approach.

@pedrofurla

Copy link
Copy Markdown

@loverdos And how do get the defined algorithms in outer scope? For the throw away I'd also use the @elidable magic...

@loverdos

Copy link
Copy Markdown
Author

@pedrofurla With the new expression trees that have recently entered the compiler, I think getting any algorithm should be much much easier now.

@pedrofurla

Copy link
Copy Markdown

@loverdos Oh yeah, new doors of all crazy possibilities are now open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment