|
![]() |
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
"I'm not back." - Bill Harding, Twister
Originally posted by Nicholas Jordan:
I hope the absurd variable names are not overly distracting, I have grown weary and leary of trying to pick variable names that are satisfiying to discriminating coders, but may be non-unique in twenty files of several hundred lines typical.
Entia non sunt multiplicanda praeter necessitatem
Originally posted by Jim Yingst:
So, what is the question ?
It looks like you only need the keys in order to get the values.
In that case, you might as well iterate through the values directly:
As for the this.oneSearch_ stuff, ..... I left it out of my code above.
As a matter of fact, yes they're quite distracting.
I can't remember what one random string of gibberish means from one line to the next.
Are you intentionally trying to make your code difficult to read?
I really can't imagine what you might be trying to do with it in the first place.
I use (Big Corp) for my job, I know plenty about (authority verification).
I know they didn't have good security checks.
Now that they do, dealing with them is a (difficulty).
I also know they were bought out by (commercial co) and that they are even worse.
I also know that (commercial co) was founded by (specially trained ops) ....
I also know that they are one of the biggest influencers of Total Information Awareness,...
I know.
If you're going to use long names, you might at least try making them somehow descriptive.
In a language which is understood by the people you're soliciting help from.
Most of these are local variables anyway, so the names don't need to be unique in the file, they just need to be unique in the block they're declared in.
If that's difficult, you really need smaller blocks of code - this can usually be accomplished by refactoring one long method into several smaller methods.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Originally posted by �dne Brunborg:
Variable names can, and should, be descriptive enough to make sense.
they are in a way part of the documentation for the code.
They make it alot easier to understand the code at first glance, and are really not that hard to come up with:
could just as easy becode:
and anyone seeing this variable name will automatically think something like "ok, so here we iterate over the huntersOfEvil keys - that means the huntersOfEvil is a Map - and then ..."
Variable names does not need to be unique across classes or even methods, as I'm sure you know.
OK, now to the question: code:
My understanding of what you want to do here: Iterate over the huntersOfEvil ....
Personally, I always try not to operate on the iterator when I can help it.
I'd remove it from the Map instead (I assume that is what you want to do?)
I wouldn't use any reference to "this.sifter"
it seems to me that it is enough to check the entry in the huntersOfEvil Map, and if it is done, remove it from the Map.
and you can change the Map keys later without having to rewrite this code.
*knock* *knock*- Who's there?- Cthul.- Cthul who?
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Okay, but does this set the originally declared object instance variable to null ? I may accumulate 20,000 - 50,000 instances in an hour of operation ... or may be running on a consumer - grade kernel, with sparse instance counts.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
Short answer: Get as close as you possibly can to Jim's example solution. I believe �dne's suggestion of removing objects from the map will take you right into "undefined" territory. See the doc for Map.keySet() and Map.values().
What is the "originally declared object instance variable"?
(We'd usually just call it a variable or an object reference.)
More importantly, where is it declared ... in a class, static or not, or in a method?
These are the factors that determine its scope or life span.
If the variable has already gone out of scope we have no worries.
If it's still in scope
It would be fine if it is null or references some other object.
I strongly feel you need to back up and start some of this from a simpler point and build it up slowly.
Your problems with unique variable names hint at some larger problems in structure.
You really need to be comfortable with the recommendations to use local variables instead of instance variables and to break code into shorter methods.
Those will be critical skills.
The good news is we love to help with stuff like that.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
The class which contains the main() from which the program is run is approaching 1,000 lines: I cannot think of any reason to be embarrased about any of those 1,000 lines
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Jim Yingst:
[JY]: continue to use the same Iterator to iterate through the other elements in the collection.
This is the intent I am trying to achieve, here, for the purpose of encapsulation of Thread Management. Locally, I want to do something without affecting World-State beyond getting the worker classes .start()'d and then do heap management on them to cycle through the same loop again and again before going on the the next phase of the program without being forced to call CreateProcess() in the platform underlying the JVM. This is for doing testing on consumer-grade platforms without access to a Solaris test bed.
That's the only thing I look to when dealing with eight hundred pound Russian
Feral Hog. My real enemy is much more dangerous, and can only be handled by
Artificial Ants, see docs in cited Alice.zip link above.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Originally posted by Stan James:
.... as given ....
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Thinking more about this, you've still got a busy loop here. Consider what happens if there's just one WordCount, but it's not done yet. This loop just keeps looping and checking, looping and checking, looping and checking, until it's done. Well, that works, but it may waste a lot of processor cycles doing nothing. In many cases a wait-notify protocol would be appropriate here. But after checking your documentation, I see that WordCount is in fact a Thread, which makes this even easier. We can use the join() method, which basically means, wait until this thread is finished:
Originally posted by Jim Yingst:
Thinking more about this, you've still got a busy loop here.
sleep() and yield() are static methods
But how could they possibly remove an element
without removing the reference?
keeping variables in scope longer than necessary just increases the likelihood that garbage collections will be unnecessarily prevented because you've accidentally left a reference somewhere you forgot about.
You've got a number of variables which are used only within this do loop, but for some reason are declared outside the loop: loopFlag, feeds, generalPurposeIterator. Actually I don't know for sure that they're not used outside, but the way they're used inside the loop strongly suggests they're utterly irrelevant outside the loop. By declaring these variables in a larger scope than necessarily, you're just increasing the chance of bugs. In particular since you're concerned about garbage collection: keeping variables in scope longer than necessary just increases the likelihood that garbage collections will be unnecessarily prevented because you've accidentally left a reference somewhere you forgot about. This is especially true if the variable is declared as a class or instance variable; it is very strongly recommended that you use local variables whenever possible.
.... A point that has been made several times in the past as I recall. If you're worried about garbage collection, please try to follow some of the basic advice people have been giving you in this regard.
Synchronizing on generalPurposeIterator serves no purpose, as no other threads should have a reference to the Iterator which you just created with the call to iterator().
(Well I suppose they might have a reference since generalPurposeIterator is needlessly declared in a wider scope than necessary, but let's assume that you eventually fix that.)
However other threads may still have access to the threadJuggler, perhaps?
only reason to use do-while rather than while is if you need the loop to execute at least once before checking the condition. The fact that you've explicitly inserted that same condition in an if statement before the loop indicates that you don't need do-while at all - which is usually the case for most programmers, I find. In fact do-while is considered less readable by many, simply because it's so uncommon that anyone ever needs it, people get used to never seeing it.
I omitted the null check because (a) I would consider it a programmer error rather than a user error, if one of the values is null (why put null in the map at all?), and (b) if a null does occur, the NullPointerException will identify the source of the problem perfectly well.
If you need to synchronize at all, make sure the threads are synchronizing on the same shared object - in this case, probably the threadJuggler. Or perhaps some other shared instance. But in this case it's probably the data in threadJuggler that's shared and needs protecting, so that's what I'd probably sync on.
I believe this should be equivalent to the code you last posted
because of reasons I will P.M. you about.Tomorrow someone may try to invoke otherThread.sleep(), and be confused about why it doesn't work.
"I'm not back." - Bill Harding, Twister
1000-line methods are evil, evil, EVIL.
Originally posted by Jim Yingst:
[JY]:... as posted ....
Yes. Assuming I've parsed what you're saying correctly.
![]()
[JY]: What issues?
[JY]: Yes, unless the thread has already completed prior to the invocation of join().
[JY]: Um... what was? The fact that join() blocks? But your busy loop blocks too - it just takes up more processor cycles while doing so. So why not use join? I don't see what your reasoning is here.
[JY]: Ummm... yes. But again, there's no need to declare someInteger way out in that outer scope. It would be much safer to declare it inside the inner loop:
That way it's even more clear that the value of the variable is only used within the loop.
[JY]: I didn't think it was supposed to be funny. I would expect that just about anyone would complain about that - assuming they don't simply shoot you first.![]()
[JY]:
It sounds like the real problem here is that your individual methods are sometimes thousands of lines long. This creates many problems, one of which is the compiler complaining about redeclarations because you're re-using a variable name. In general I think declaring the variable only once in an outer scope is not the answer - unless you actually need the methods to share data contained in a variable. Instead, please, please, PLEASE try to break those thousand-line methods into many smaller methods. That way when you need a new local variable name, it will be in a scope of its own, and you won't accidentally mix up your data with some other data you worked with 500 lines in the past. Also you can give each small method a nice descriptive name for what it does - with a little practice, you can use these methods to eliminate or at least greatly reduce the need for other explanatory comments. So all these new method names I'm asking for aren't really any extra work, with a little practice, because you just take the time spent making & typing comments, and redirect it into choosing and typing method names. The resulting smaller methods are much more manageable to understand and deal with one at a time.
[JY]: Honestly, it looks very painful to live with now. I don't have time to analyze carefully just what the heck you're doing in all that. I would note that one way threads could be sharing data is through shared class variables or instance variables. You've got a number of these in Alice, and they're final, but in several cases they refer to mutable objects (e.g. arrays). I can't tell offhand if the contents of these actually change, ever, but if they did, then your threads would be sharing data. OK, I think probably this is not an issue in your code, but really, I'm getting a headache just looking at that code. 1000-line methods are evil, evil, EVIL.
[JY]:
OK, I think probably this is not an issue in your code, but really, I'm getting a headache just looking at that code. 1000-line methods are evil, evil, EVIL.
[JY]: Sorry, I don't know what this means.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
BTW - Please re-enable html in my posts, the caliber of work here was unexpected a user-registration.
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|