store whole InputStream in a String

P

Paul Lutus

Vincent said:
In fact, those two codes look pretty much the same. This is a good
demonstration that while and for can be interchanged.
Since you can do that every time (use a for instead of a while, and a
while instead of a for),

But you can't do it every time. A for-loop has three clauses that are
carried out in a specific way. You can dispense with the three clauses,
making "for" resemble "while," but the reverse isn't true.
we need a "rule" to say when use which. I say
that in this case, since there is no incrementation part in the for loop,
we should use the while.

Seems reasonable, unless a case arises in which the control variable needs
to be kept local. In that case, it is the *effect* of using a for-loop, not
its appearance, that is more important.

Also, there are plenty of cases where a while-loop also involves
incrementation. I think the more basic difference is the for-loop's three
clauses, and times where this is the obvious choice.
I make one exception to this rule (but hell... if there were no exception,
it wouldnt be a rule, would it? ;)) for iterators: in java, the
incrementation is done in the first line of the body part of the loop, but
I still use for because I'm used to iterating data structures with a for
loop


I can't agree more with you.


I would not say that... I understand the necessity to have a loop that
decides to exit in the middle of its body.

It is best avoided, replaced by something that exits in a way easy to
visualize, otherwise the programmer may picture the algorithm in a way at
odds with reality.
The condition of your solution
(which is also mine since I do use the same construction when this problem
arise) is not a pure condition: it actually does things, and this may also
be considered as a hack.

Only if it can be replaced with something better. But it can't. In any case,
there is no reason to avoid actions along with tests if that is the most
efficient arrangement.
What if the code we had to launch before the test
was two lines long?

In that case I would call a method in order to maintain the structure of the
while loop.
I don't know what I prefer between writing a small function to handle that
(that does the code and return whether there is something to be treated)
or the while(true)/break solution...

The former meets the requirement to break actions up into logical units. The
latter IMHO is an acknowledgment of defeat. :)
 
A

ak

code you write are may be ok, but comments you write are not ok.
If you download the current version of Arachnophilia and use it with the
current JVM, and unless you have mucked up the menus (possible because
Arachnophilia allows the user to modify the menus), your statement is
false.

if you would read what I wrote, you could see that I wrote "your last
Arachnofillia".
"last" means I just downloaded it.
And yes I use java 1.4
and unless you have mucked up the menus (possible because
Arachnophilia allows the user to modify the menus).

yup, I modified the menu some time ago.
Sorry - I tried to modify menu.
That was a bit a disaster (another bugs in your code?)

And sorry, but I didn't found the way to reset menu.
 
P

Paul Lutus

ak said:
File menu behavior it pretty strange:
File ist is not not below, it is above.

As I expected, you have mucked up your menus. Re-install Arachnophilia, and
use the customization features more carefully.
 
P

Paul Lutus

ak said:
We spoke abot reliable code.
He mean my code are wrong and his code ok.
I brought counter-example.

It is not a counterexample. You have managed to screw up your Arachnophilia
menus. To see how severely, re-install Arachnophilia using the provided
instructions to assure that your menus are recreated.

If you do this, suddenly everything will work correctly, until you play with
the menu structure again.
 
A

ak

Paul Lutus said:
As I expected, you have mucked up your menus. Re-install Arachnophilia, and
use the customization features more carefully.

I found the error, file list was at top position in menu.
Indeed it is error in code.
User may want to have file list anywhere...
Why should clearing file list also clear complete File menu just because
file list is in wrong place?
 
A

ak

code you write are may be ok, but comments you write are not ok.
As I expected, you have mucked up your menus. Re-install Arachnophilia, and
use the customization features more carefully.

consider to provide "Reset menus" button
 
P

Paul Lutus

ak said:
if you would read what I wrote, you could see that I wrote "your last
Arachnofillia".
"last" means I just downloaded it.

No, "last" does not mean "I just downloaded it."
And yes I use java 1.4

That is not the most recent version. We have a perfect score of zero.
yup, I modified the menu some time ago.
Sorry - I tried to modify menu.
That was a bit a disaster (another bugs in your code?)

If you write a bad novel, do you then blame the typewriter manufacturer?

You are the sort of person for whom advanced features are a constant danger.
And sorry, but I didn't found the way to reset menu.

Try reading the instructions.

http://www.arachnoid.com/arachnophilia/Documentation/arachnofaq.html#link1
 
T

Tor Iver Wilhelmsen

Vincent Lascaux said:
for(Iterator i = start; i.hasNext(); i.next()) {
something q = i.current();
}

The C# and C++ STL iterators work like that (well, same idea), and I am more
used to reading a for statement with an "inc" as a third "parameter"

Java also has an iterator that works like that: java.sql.ResultSet.

But then java.sql.* generally breaks with a few "Javaisms" (like
indexes starting with 1 instead of 0) anyway.

In JRE 5.0 (1.5.0) you can do

for (Sometype i: someList) {
//...
}

whether someList is a (typed) List or an array. Makes life simpler.
 
V

Vincent Lascaux

But you can't do it every time. A for-loop has three clauses that are
carried out in a specific way. You can dispense with the three clauses,
making "for" resemble "while," but the reverse isn't true.

for(Init; Cond; Inc) { Body; } <=> { Init; while(Cond) { Body; Inc; } }
while(Cond) { Body; } said:
Seems reasonable, unless a case arises in which the control variable needs
to be kept local. In that case, it is the *effect* of using a for-loop,
not
its appearance, that is more important.

I agree. But this case is (or at least should be) rare: if you use several
loops in one function, chances are that you should split it in several
functions.
 
P

Paul Lutus

ak said:
I found the error, file list was at top position in menu.
Indeed it is error in code.

No, it was error in user. You moved it into that position.
User may want to have file list anywhere...

User needs reboot.
Why should clearing file list also clear complete File menu just because
file list is in wrong place?

I am now considering a version of Arachnophilia without the advanced
features, specifically for rocket-scientist users like this one.
 
A

ak

Vincent Lascaux said:
Hey! But what does it have to do with the topic?
Are you so out of arguments on the subject that you have to look for
mistakes/problems in Paul's code?

you are right of course, I was a little bit childish ;-)
 
T

Timo Kinnunen

for(Init; Cond; Inc) { Body; } <=> { Init; while(Cond) { Body; Inc; } }

Calling { Init; while(Cond) { Body; Inc; } } a while-construct and not a
block-construct with a while has a few problems. First, when reading the
first brace it's not possible to determine that what you're reading is this
construct without looking ahead. Second, I find it unnatural to initialize
multiple variables in a single statement except in a for-loop, so I'd
rather write them out, which, while semantically identical, can't be
converted to a corresponding for-construct.

I guess I could train myself to consider this one

{ int i = 0, n = array.length; while(i < n) {
//process
i++;
}}

on par with

for(int i = 0, n = array.length; i < n; i++) {
//process
}

but I just find it ugly.
 
A

ak

code you write are may be ok, but comments you write are not ok.
Already true! How long is this going to take, exactly? Please read the
documentation.

no, [GetRescueMacroSet] is not the same thing as "Reset menus" button.

This is the biggest problem of free software - programmers does not think
about user.
Users have to do this and other things instead of one simple click.

Just because programmers does not become money for their products,
they build a big wall between GREAT programmers and LAZY users.
Stupid users have to read here and there and possibly don't ask any
questions.
 
T

Tony Morris

This is the biggest problem of free software - programmers does not think
about user.

Call me sick for my sense of humour, but naive statements like that tend to
tickle me a tad.
LOL!
 
A

ak

This is the biggest problem of free software - programmers does not
think
Call me sick for my sense of humour, but naive statements like that tend to
tickle me a tad.

yup, go to doctor, may be he can help you

However most people use Windows, just because it is more comfortable.
 
T

Tor Iver Wilhelmsen

Jacob said:
The while(true) construct for reading streams is
the natural choice and it is so common I'd classify
it as a pattern.

We canb call it the "Goto Pattern", then, because that's what
"while(true)... break" really is.
 
J

Jacob

Paul said:
int len;

while((len = inputStream.read(buffer)) > 0) {
bout.write(buffer, 0, len);
}

This approach fails seriously on readability.

The while(true) construct for reading streams is
the natural choice and it is so common I'd classify
it as a pattern.

A "stream" is, conceptually speaking, endless!
Reading it using an endless loop is quite natural.
If the stream for some reason stops, then break
the endless processing.
 
S

Sudsy

Jacob said:
This approach fails seriously on readability.

I can't let this comment pass. The construct above is rife in
professionally written code. In point of fact, the braces are
frequently omitted as well. Take a look at some kernel code
and you'll see what I mean. It's emminently readable if you've
spent any time looking at the code of others.
 
P

Paul Lutus

ak said:
Already true! How long is this going to take, exactly? Please read the
documentation.

no, [GetRescueMacroSet] is not the same thing as "Reset menus" button.

Try following the instructions I provided. I posted a link to the correct
Web page, paragraph and section.
This is the biggest problem of free software - programmers does not think
about user.

This is the funniest line I have ever read on this topic. Programmers of
free software do not think of anything else but the user. Were this not
true, they would charge for their programs.
Users have to do this and other things instead of one simple click.

Yes, and if "one simple click" is your goal, you should definitely avoid
sitting at a computer.
Just because programmers does not become money for their products,
they build a big wall between GREAT programmers and LAZY users.

That wall is built by users, not programmers. You just complained about a
problem you yourself created, trying to assert that it was a flaw in my
program. Then, after I posted the solution, you complained about that.

Next you will demand your money back.
Stupid users have to read here and there and possibly don't ask any
questions.

Yes, I know. Meanwhile, intelligent users can read the instructions,
available on their machines and online at
http://www.arachnoid.com/arachnophilia

Now that you are done complaining about my free program, read this:

http://arachnoid.com/freeware/index.html
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top