0

I think the biggest drawback of programming in scala is that, due to large amount code being part of synthetic/anonymous classes, stack traces and default 'toString' logs are often close to useless.

Is there a good reason/obstacle for the compiler generating more helpful class names/toString methods? I feel like methods reified to functions and functions assigned to named vals at least are good candidates to print the name of the method/val instead of 'function'. Would be also great to have the class names of lambdas show the name of the method they were defined in, but again something like '$$lambda' would be an improvement.

Probably can be done with macros - did anyone already do it, or is it a good candidate to delve into scala macros?

Turin
  • 2,208
  • 15
  • 23
  • What is your question? Currently, It seems more like a proposition/rant rather than an actual question. – Yuval Itzchakov Feb 11 '16 at 13:11
  • Macros would only make this worse. You'd need to hack the underlying JVM to fix your stack traces. – bash0r Feb 11 '16 at 14:26
  • "did anyone already do it?" And I believe that macros could at least add a more helpful 'toString' implementation if not affect the name of generated class. I don't know if they work purely locally, or if it would be possible to change inline classes to named entities – Turin Feb 11 '16 at 19:28

1 Answers1

1

There are several problems with this approach.

First of all you would only be able to expand around the context of the macro i.e. directly around where the macro is being applied so in the end your code would have to have each of the functions wrapped up in some method (which then expanded the tree to have a toString method) like below which is fairly ugly.

val test = Macro.addToString((f: Int) => f + 10)

Secondly while you are correct that currently scala functions are anonymous inners that isn't going to be the case with the next release as they are going to be Java 8 compliant. What this means is that functions get expanded slightly differently and I believe that you won't be able to take this approach anyway.

You could try using a scala compiler plugin which I believe would be a good way to do what you want.

Community
  • 1
  • 1
yw3410
  • 228
  • 3
  • 8