Some time ago Julia introduced warnings for re-defining methods. This kind of created havoc in my work because what I do all day is
Edit Julia file.
include(“myfile.jl”)
GOTO 1.
So every time I edit my file I’d get a page of warnings. Being informed that my methods have been redefined is not helpful, since that is exactly what I am trying to do. I’m developing + testing. At the time a kind soul produced a module called ClobberingReload that allowed me to get back to work. The big downside of that module is that it suppresses legitimate warnings too.
Over time I changed the way I write my Julia scripts to avoid using functions at all, so I could get real errors without the noise from the “method overwritten” warnings. Of course, this is a horrible solution. The idea of being pushed by the language warnings to avoid using functions is slightly horrifying.
In some cases it just wasn’t viable to avoid functions. So I was forced to change my workflow to:
Edit file.
Exit Julia.
Start Julia. …
include(“myfile.jl”)
GOTO 1
This of course created a big delay in my workflow, but some times it was better than not using functions at all, or using functions but suppressing all errors.
Anyway, that was some time ago. I am now writing with the hope that a better solution has appeared. I have searched through the forums and I have found this package:
This might be a bit more elegant than ClobberingReload, but it doesn’t help with the underlying issue that it suppresses everything to STDOUT, and not just the “method overwritten” warnings.
Is anyone aware of a more recent alternative that would allow me to suppress the “method overwritten” without suppressing other errors? I would really like to go back to coding sensibly. I want to use functions to organize my code, and I want to be informed about syntax errors and the like, without having to reload Julia after every edit, or having Julia complain about every function in my file.
ClobberingReload author here. Can you give an example of suppressed legitimate warning? In theory, ClobberingReload.sinclude should only filter out warnings that match one of these regexes
redefinition_regexes =
[r"WARNING\: Method definition .* in module .* at .* overwritten at .*\n",
r"WARNING\: Method definition .* in module .* overwritten\.\n",
r"WARNING\: replacing docs for .*\n",
# 0.6 updated its doc warnings with color. Looks like this:
# \e[1m\e[33mWARNING: \e[39m\e[22m\e[33mreplacing
r".*WARNING: .*replacing docs for .*\n",
r"WARNING\: redefining constant .*\n"]
but I suck at regex writing, so it might well filter out some legitimate warnings, too. Suggestions welcome.
cstjean: Hello. Thanks for making ClobberingReload. Oh, I can’t think of an example and now that you say that it shouldn’t suppress legitimate warnings I’m wondering if perhaps I have misunderstood ClobberingReload this whole time.
This is a slightly dangerous workflow. If you accidentally remove a method definition, your code will appear to still work until you restart Julia. So I wouldn’t recommend going back to this, even if you find a way of suppressing warnings.
What I do is:
Edit Julia Files
Pkg.test(“Mypackage”)
GOTO 1
Pkg.test starts up a new Julia process, so there are never any “method overwritten” warnings. (Unless, of course, you accidentally define the same method twice.)
But I am not writing a Julia package. I use Julia as an interactive data-analysis tool. I use it mostly for plotting and post-processing simulation data. I write small programs that load heavy modules like PyPlot and often some of the statistical modules too. It makes no sense to constantly load and reload Julia and all those modules just to fiddle with the line thickness or colours of a plot. Nor is there much risk that I accidentally delete a method.
As others have noted, the issue is resolved in 0.6.0-rc2. I’m using it right now and I’m very happy. But to answer your question, I guess that if the function is a one-liner I could use anonymous functions.