L
Lew
Which is fantastic if you're writing a book.
They don't make a typewriter that fast.
Which is fantastic if you're writing a book.
Daniele Futtorovic said:Not even that. Not unless you can simulate all the logical branches
(which, incidentally, means doing your stepping through 2^n times, with
n being the number of branchings),
in which case you'd have written a
unit test and might as well give it a run for itself and see in one go
whether there's a problem in the first place.
If you have logging statements to report that stuff has happened thenSounds cool. But what if you want to have logging statements so as to
affirm that some expected thing happened?
I'm curious what people are using as their IDE to write Java code.
The biggies used to be Eclipse, NetBeans and IntelliJ. What are they
now? What are you using?
Forced to use Eclipse by Android
Sounds cool. But what if you want to have logging statements so as to
affirm that some expected thing happened?
Forced to use Eclipse by Android
Daniele Futtorovic said:It's either one or the other, lad. You can't see the big picture when
you've got to focus on writing the small one.
The main Java IDEs have macros in a true sense of the term. You haven't
found them yet?
I haven't actually tried to build such a thing, but Java logging has
a circular buffer built in (MemoryHandler) as well as the more
standard console and file handlers.
I would probably start by having two handler, one MemoryHandler and
one FileHandler. Set the priority on the FileHandler to "normal"
levels -- Severe, Warning, Config, Info. If you want to "know that
something happened", write it out with one of those levels.
At the same time set the MemoryHandler to a much lower level, say
"Finer" or similar. When something does happen, dump the
MemoryHandler. Then you'll have both standard logs and the recent log
of events just before the event of interest. This seems to be what
Martin is talking about.
Are you admitting you can’t type and think at the same time?
Okay, but this does presuppose that you have one, or some very few, core
places to your application where things are run in some kind of loop and
where you can catch 'interesting events', doesn't it? I mean, you have
to trigger the dump somehow.
Yes. I can think of two ways to do it, off hand. One would be to have
some sort of ad-hoc mechanism. You add some code to a known problem
area to call a "dump" method which triggers the MemoryHandler.
The second way I think would be to have some general mechanism. You
could try a logging Handler that, instead of logging (or in addition
to logging) also triggered the MemoryHandler when it gets a specific
level or type of Exception. You'd have to write such a class
specially, but once you did you'd have some flexibility to attach it
to problem areas wherever they are found, without having to modify
code and recompile.
Yes, this second one is the one I've been thinking about in the
meantime. Extremely neat and powerful.
Single-stepping through newly-written code is an excellent way to determine
whether it's working as designed, or getting what looks like the right
answer for the wrong reason.
Macros are just a quick convenience. For anything more complicated, I want a
proper scripting language. Which Emacs has.
I won't deny that. But let's look at the original terms of reference for
this thread, which I'm trying to stick to: IDE's [sic] for writing Java code.
That context is why, for example, I'm skeptical of the advantage of
being able to squeeze out every last bit of ergonomic speed in typing -
we're writing *code*.
As for scripting of the IDE, the real discussion there is about the
ability to extend the capability of the IDE. In Emacs you do it one way,
in the main Java IDEs you do it other ways (although you can consider
"scripting" languages also).
Eventually you'll change the requirements to the extent that only Emacs
can satisfy them...like "editor must be extensible and customizable with
Emacs Lisp".
Pressing CTRL/S to start a search, typing the search string, then repeating
CTRL/S to step forward through all instances or CTRL/R to step backward.
Press Enter to leave the point at the desired location, or CTRl/G to abandon
the search.
Pressing CTRL-X ( to start defining a macro, CTRL-X ) to finish it, then
CTRL-X e to execute it, e to execute again, repeat, repeat.
Having multiple clipboards with CTRL/X r s 1, CTRL/X r s 2 etc.
Being able to execute a shell command and insert its output directly into a
text buffer.
Basically, being able to type as fast as you can think.
Here's what I came up with. Note that after checking the docs, I noticed
that MemoryHandler will self-push if its pushLevel is met or exceeded.
So if that's all the functionality you need you have it in one class
already.
The code below is completely untested.
package test;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.MemoryHandler;
/**
*
* @author Brenden
*/
public class TriggerHandler extends java.util.logging.Handler {
public TriggerHandler() {
setLevel( Level.SEVERE );
String slevel = LogManager.getLogManager().getProperty(
"logging.config.memorydump.trigger.level");
try {
Level level = Level.parse(slevel);
setLevel( level );
} catch( IllegalArgumentException ex ) {
// bail, log this?
}
}
@Override
public void publish(LogRecord record) {
if( record.getLevel().intValue() >= getLevel().intValue() ) {
String logger = LogManager.getLogManager().getProperty(
"logging.config.memorydump.logger");
if( logger == null ) {
logger = ""; // root logger
}
Handler[] handlers = Logger.getLogger(logger).getHandlers();
for( Handler h : handlers ) {
if( h instanceof MemoryHandler ) {
MemoryHandler mh = (MemoryHandler)h;
mh.push();
mh.flush();
}
}
}
// Assume parent handlers will be invoked.
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
}
Flipping back and forth between what? Emacs runs on Windows and,
with cygwin's bash shell, it's almost a not unpleasant development
environment.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.