store whole InputStream in a String

G

Gary Labowitz

Mike Schilling said:
.

OK, I get it now. I thought you were being serious. I see now that you're
doing a sort of Mionty Python routine:

You're wrong.

That's not a logical argument, it's simply an assertion:

No it isn't an assertion.

Why not?

Because you're wrong.

Sorry it took me so long to catch on.

And you break me up, too. Could it be the whole ng is a Mionty (sic) Python
routine? [I'm sorry, I'll type that again.]
 
P

Paul Lutus

Gary said:
General answer to all:

You guys break me up. As I recall Arachnophilia is careware. Where is all
your caring?

Read the CareWare page (http://www.arachnoid.com/careware) before you make
the assumption you are making. Also read http://arachnoid.com/freeware for
a reality check.
And it is free. That's means don't be so demanding -- you got
your money's worth. As to OP topic (remember the OP?), as a teacher I find
it easier to teach a while(true) [with break] to get students running with
a valid program (all those usages being valid) and then expand on better
ways to do any given thing.

IMHO, this is a very bad approach to teaching structured programming. For
such a class, I would outlaw while(true), break, and continue, since all
programs can be written without them, and since they are only present in
the language to ease the transition into structured programming for those
with no background or adeptness in it.
In this case it results in code Paul suggests.

Paul: what you say is true, but one can't always impose strict academics
on students who are struggling with a sea of ideas, programming
constructs, and new ways of thinking.

That happens to be the best, and possibly last, opportunity to impose a
necessary discipline, for reasons it is difficult to convey to students,
most of whom think a working program is the ultimate goal (if that were
true, BASIC would have been the ultimate language).

The issue being discussed is at the heart of structured programming. I find
it is best to focus on this issue early on, with great attention paid to
details.
We start them in the wading pool.
Those who don't drown there get to try the deep end later. I'm sure you
wouldn't like my classes, but I'm not sure my students would like yours.
By like, BTW, I mean enjoy the actual learning of programming enough to
spend the time and thought needed to actually understand it.
To you other guys: lighten up. So you did it baby-fashion. So it works.
Okay. But now learn from the master (or at least one of them here) and
move on. Stop defending and attacking on such a dumb question. There are
going to be better ways of doing just about anything you care to mention;
otherwise we CAN close the patent office.

As for me, I don't care how it damned thing is coded -- just that it work.

To put it bluntly, this is why programming is such a mess, and why there is
structured programming.
Optimization comes ... uhh ... last.

This is not about optimization, it is about structure and maintainability.
 
P

Paul Lutus

ak said:
hundreds? thousands? millions?
lol

Over the life of Arachnophilia (1996 to the present), I haver been contacted
personally by at least 20,000 people, most asking a question answered in
the FAQ or documentation. You are in that group.
 
P

Paul Lutus

Mike said:
.

OK, I get it now. I thought you were being serious.

You will either return to the topic, or you will be killfiled. It is your
free choice, and your move.

If you had any knowledge of programming, you would understand what is being
discussed in this thread. If you had an argument, you would present it. I
have already presented mine: Disabling "while" by applying "true", thus
creating an unconditional block not provided by the language, then
repairing the broken result with "break", is a hack, one that violates the
most basic paradigm of structured programming.
 
A

Andrew Thompson

..I have been seeing a number of posts, very random, that have words
concatenated as the "familiarandreadable" above. I am worried as to where it
is coming from (since I'm using OE :)).
My question is to > > (I think Jacob): did you actually write
"familiarandreadable" without spaces for a reason, or did you have spaces
and it came through without?

Don't worry Gary, you are currently at
'a couple of times', but once you have
read familiarandreadable ten thousand
times it will be familiarandreadable and
you will wonder how you ever got by
without the expression. ;-)
 
P

Paul Lutus

Jacob said:
I prefer making code understandable for those that have
*not* read my code 10-thousand times.

I prefer using the language as it was intended to be used, consistent with
the principles of structured programming.

Rule 1. If you use "while", you must test something. If instead you use
"while(true)", you are disabling the clause and creating an unconditional
block, a structure not provided in the language for a reason. After this
mistake, all you can do is add another mistake: a "break" that has no
purpose except to try to repair the earlier mistake.
That's the majority after all.

The what? Science is not a popularity contest. Programming principles are
not based on consensus.
It includes avoiding variable names like "len"
when meaning "length" and so on.

Try to return to the topic.
 
P

Paul Lutus

Chris said:
There really is a serious difference between break/continue (including
labeled break/continue) and goto.

The only difference I see is in behavioral latitude (e.g. a question of
degree, not type). "goto" can go anywhere, "break" and "continue" can only
jump out of the immediate enclosing control structure, unless they are
accompanied by a label, then they can go nearly anywhere, which pretty much
makes them a substitute for "goto".
It can be debated whether that
difference fixes the pitfalls of the goto statement, but it's useless to
deny that the difference exists.

It is true that they (break/continue) are not as open-ended as "goto", but
the distinction is rather academic when they are accompanied by a label.
That difference is that while break/continue can be used to exit a block
of code from an arbitrary point, it cannot be used to enter a block of
code at an arbitrary point.

Not strictly speaking true. You can put destination labels nearly anywhere.
With sufficient malice it is possible using break/continue and a bunch of
labels to create an unreadable mess that rivals BASIC.

This example actually compiled without error:

public class Test {

public static void main(String[] args)
{
labela: {
int x = 3;
labelb: while(true) {
labelc: if (x == 0) {
break labela;
}
else if(x == 1) {
break labelb;
}
else break labelc;
}
}
}
};

The important thing to remember at this point is that any algorithm that can
be created using break/continue and labels can also be created without
them.
There is a very strong case to be made that
it's the latter -- arbitrary entry points to a block -- that is most
threatening to readable code. The former is a natural abstraction in
many programming scenarios, esp. when try/finally is used judiciously as
well.

I personally think the inclusion of break/continue was made after a failure
of nerve at Sun, who wanted Java ot be adopted by people not terribly crazy
about, or particularly adept at, structured programming.
For the record, though, in at least the specific case of reading from an
InputStream, the universal idiom of "while ((len in.read(buf)) != -1)"
is far easier to follow, simply because an average Java programmer will
already know what to expect.

What is surprising is this idiom apparantly doesn't occur to students
naturally. I noticed this in C and C++ programming discussions also, in
years past. It seems to be accepted as a last resort, after every
alternative has been found wanting.
 
P

Paul Lutus

Gary said:
Above is the message as I received it. Checking the source it also reads
as above. I have been seeing a number of posts, very random, that have
words concatenated as the "familiarandreadable" above. I am worried as to
where it is coming from (since I'm using OE :)).
My question is to > > (I think Jacob): did you actually write
"familiarandreadable" without spaces for a reason, or did you have spaces
and it came through without?

I jusrt reviewed the originals, and they are not like your copy. Your
newsareader is broken. To see this for yourself, access the same post in
the groups.google.com archive, which will present it in your browser rather
than your newsreader.

Then get a real newsreader. I was going to suggest getting an real operating
system too, but I think that might be too much for one day.
 
M

Mike Schilling

Paul Lutus said:
You will either return to the topic, or you will be killfiled. It is your
free choice, and your move.

You're threatening me with going away? You do take yourself seriously.
If you had any knowledge of programming, you would understand what is
being
discussed in this thread. If you had an argument, you would present it. I
have already presented mine: Disabling "while" by applying "true", thus
creating an unconditional block not provided by the language, then
repairing the broken result with "break", is a hack, one that violates the
most basic paradigm of structured programming.

So you've said, ad nausem, with no attempt at logic or reasoning. You're
not John Cleese, you're Eliza.
 
P

Paul Lutus

Mike said:
You're threatening me with going away?

Do you understand Usenet's conventions any better than you understand
programming? Clearly not.
You do take yourself seriously.

No, I take the topic seriously, the topic you are desperately trying to
avoid. If you had the most basic grasp of that topic, you might know why I
take it seriously.
So you've said, ad nausem, with no attempt at logic or reasoning.

The above is the argument you pretend to seek. Too bad you flunked logic and
reason.
You're
not John Cleese, you're Eliza.

Post to the topic. If you knew anything about programming, you would have
acknowledged your error by now. But as things stand, you have nothing to
lose, since incompetence is its own excuse.

One sees here a classic case of evasion. Once the error of your position
became obvious, you promptly abandoned the topic in favor of trolling.

Further evidence:

http://www.cs.yorku.ca/eiffel/FAQ/gotos-loops-breaks.htm
 
C

Chris Uppal

Mike said:
[...the usual...]
So you've said, ad nausem, with no attempt at logic or reasoning. You're
not John Cleese, you're Eliza.

"Eliza Lutus", hmm... that might just stick....

-- chris
 
G

Gary Labowitz

Paul Lutus said:
Gary Labowitz wrote:
Then get a real newsreader. I was going to suggest getting an real operating
system too, but I think that might be too much for one day.

Yes, much too much. I've been using the M$ stuff for so many years I've
managed to jump most of the hurdles. And OE has been my reader for too long.
I'm at that point where I am so lazy I put up with all the nonsense and
manage. But this one is real nonsense.
Make me a few suggestions (for the reader, not OS -- I'd go linux for that)
but I have heard good things about Free Agent (?). More research to do, I'm
afraid.
 
C

Chris Smith

Paul said:
The only difference I see is in behavioral latitude (e.g. a question of
degree, not type). "goto" can go anywhere, "break" and "continue" can only
jump out of the immediate enclosing control structure, unless they are
accompanied by a label, then they can go nearly anywhere, which pretty much
makes them a substitute for "goto".

That's not the case, though. It makes their behavior a little more
flexible, but still constrains them to be used only for the purpose of
exiting blocks. For example, the following C code could not be
rewritten in Java with even a labeled break or continue:

int i = 41;
goto insane_location;

for (i = 0; i < 5; i++)
{
j = get_valid_value_for_j();
insane_location:
do_something_with(j);
}
Not strictly speaking true. You can put destination labels nearly anywhere.

Yes, actually, it is strictly true. You can put a label prior to any
statement, but it's not a destination label; it's a name for the
statement (which is probably, though not necessarily, a compound
statement). A labeled break/continue that uses a label must occur
within the statement that's labeled.
This example actually compiled without error:

public class Test {

public static void main(String[] args)
{
labela: {
int x = 3;
labelb: while(true) {
labelc: if (x == 0) {
break labela;
}
else if(x == 1) {
break labelb;
}
else break labelc;
}
}
}
};

There's some confusion going on here because of the scope of the
statements. Remember that an if/else is a single statement, and that
chained if/else statements resolve to:

if (firstCondition)
{
...
}
else
{
if (secondCondition)
{
...
}
else
{
et cetera
}
}

So your 'labelc' actually applies to the entire contents of the while
loop, and the 'break labelc;' just causes you to quite trying to do the
contents of the while loop. If you intended to break only out of the
conditional block of the if statement, then you should put your label
directly prior to the open-brace of that block. In any case, you
haven't written a single break or continue that enters a block at
multiple points or jumps around arbitrarily -- you have instead only
used them to leave a block, which is their purpose.
The important thing to remember at this point is that any algorithm that can
be created using break/continue and labels can also be created without
them.

The same thing is true of loops and conditionals, which could easily be
replaced with recursion and polymorphism. However, I wouldn't want to
program without them. The thing to remember is not whether it's
possible to without break/continue, but rather whether they are
worthwhile tools for programming.

Writing code without break or continue often results in more levels of
nesting, more -- and more visible -- loop and conditional structures,
and the introduction of more local variables to hold temporary flags
that are only there to get the control flow right. These are not
benefits to be aimed for; they increase the complexity of code.
I personally think the inclusion of break/continue was made after a failure
of nerve at Sun, who wanted Java ot be adopted by people not terribly crazy
about, or particularly adept at, structured programming.

Yes, you seem to have a number of strong opinions. This one isn't very
viable, though, and you may be well-advised to drop it. Why would Sun
go out of their way to design and implement a new extension to a
language feature, when they've only included it as a concession to non-
structured programmers? No, it's clear that the engineers at Sun
considered break and continue to be acceptable structured alternatives
to many uses of goto, and strengthened them so that they could handle
more situations than they could before, but still in a structured way.
What is surprising is this idiom apparantly doesn't occur to students
naturally. I noticed this in C and C++ programming discussions also, in
years past. It seems to be accepted as a last resort, after every
alternative has been found wanting.

Yep. The reason for this is that in the course of trying to teach
students to write readable code, many universities have began
promulgating the idea that code should be verbose. Using the expression
result of assignment operators in C-family languages is one of those
things that is under attack -- so even universal idioms that do so are
pressured to be abandoned. Such folks would be much better advised to
spend their time thinking about human factors in reading code, rather
than wasting their time attacking low-level language constructs.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Gary said:
Yes, much too much. I've been using the M$ stuff for so many years I've
managed to jump most of the hurdles. And OE has been my reader for too long.
I'm at that point where I am so lazy I put up with all the nonsense and
manage. But this one is real nonsense.
Make me a few suggestions (for the reader, not OS -- I'd go linux for that)
but I have heard good things about Free Agent (?). More research to do, I'm
afraid.

Though I'm not Paul, I do have a suggestion. MicroPlanet's Gravity is
an excellent and free newsreader.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew Thompson

...
.. MicroPlanet's Gravity is
an excellent and free newsreader.

Just a note that Gravity ends to break long links,
even if they are wrapped in the '<' '>' chars..
I might use it, excepting that.

[ And I am not entirely happy with my current
news-reader, so I cannot recommend it either. :-( ]
 
C

Chris Smith

Andrew said:
Just a note that Gravity ends to break long links,
even if they are wrapped in the '<' '>' chars..
I might use it, excepting that.

Yes, it does. However, it will not break quoted lines. That's why
you'll often see me use a quote character before a long URL.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
P

Paul Lutus

Chris said:
That's not the case, though. It makes their behavior a little more
flexible, but still constrains them to be used only for the purpose of
exiting blocks.

Yes, I agree. My point was that one could create new entry points through a
liberal scattering of labels, as in my example.
For example, the following C code could not be
rewritten in Java with even a labeled break or continue:

int i = 41;
goto insane_location;

for (i = 0; i < 5; i++)
{
j = get_valid_value_for_j();
insane_location:
do_something_with(j);
}

Yes, it cannot be written in Java, because one cannot have forward
references to a label in Java. In any case, I wasn't suggesting that
break/continue and goto are precisely equivalent, only that break/continue
are capable of the same kind of mischief, in an attenuated form.

/ ... snip code example
So your 'labelc' actually applies to the entire contents of the while
loop, and the 'break labelc;' just causes you to quite trying to do the
contents of the while loop. If you intended to break only out of the
conditional block of the if statement, then you should put your label
directly prior to the open-brace of that block.

My sole point was that this ability to scatter labels about, if exercised by
a student or someone in a hurry, would quickly devolve into a jumble of
difficult-to-interpret code.
In any case, you
haven't written a single break or continue that enters a block at
multiple points or jumps around arbitrarily -- you have instead only
used them to leave a block, which is their purpose.

Yes. Since the compiler accepted them, and assuming the compiler won't
accept an irrational label placement, each example exits its associated
block. The problem for the reader is in deciding where the block's
boundaries are.
The same thing is true of loops and conditionals, which could easily be
replaced with recursion and polymorphism. However, I wouldn't want to
program without them. The thing to remember is not whether it's
possible to without break/continue, but rather whether they are
worthwhile tools for programming.

Which brings us back to the original questions: whether break/continue is in
Java what goto is in other languages, in whole or in part, and whether goto
erodes structure and maintainability with little or not compensating
advantage. I think the latter issue has been decided.
Writing code without break or continue often results in more levels of
nesting, more -- and more visible -- loop and conditional structures,
and the introduction of more local variables to hold temporary flags
that are only there to get the control flow right. These are not
benefits to be aimed for; they increase the complexity of code.

I think structured programming purists would argue that it may take longer
to design an algorithm without break/continue, but the resulting code will
be more comprehensible, not less. One often sees college coursework in
which the use of break/continue is simply forbidden, presumably in the hope
that this will produce a lifelong bias against them.
Yes, you seem to have a number of strong opinions.

True about me, but the bias against break/continue I've been putting forward
is not my opinion. I can't take credit for it.
This one isn't very
viable, though, and you may be well-advised to drop it.

To do so, I would have to disregard a lot of technical literature that makes
the same point in varying ways. I think it is viable.
Why would Sun
go out of their way to design and implement a new extension to a
language feature, when they've only included it as a concession to non-
structured programmers?

Why indeed? Since break/continue can be dispensed with and still allow any
algorithm to be designed, since there have been any number of reasoned
objections to arbitrary jumps in otherwise well-structured languages, one
wonders why they did it. I think my explanation is plausible if
hypoerbolic.
No, it's clear that the engineers at Sun
considered break and continue to be acceptable structured alternatives
to many uses of goto, and strengthened them so that they could handle
more situations than they could before, but still in a structured way.

I would describe them as a crippled form of goto, and I would say they erode
the degree to which Java is a language based solely on principles of
structured programming.

Also there is the issue of how they are used. They can easily be misused, as
in my example, so one could argue instead that the circumstances of their
use, not their presence in the language, is the real issue. Naturally
enough this makes me wish they were not present, thus preventing their use,
but I wasn't responsible for meeting a shipping date or answering
objections such a yours.
Yep. The reason for this is that in the course of trying to teach
students to write readable code, many universities have began
promulgating the idea that code should be verbose. Using the expression
result of assignment operators in C-family languages is one of those
things that is under attack -- so even universal idioms that do so are
pressured to be abandoned.

Admirable in principle on the part of the university computer science
departments, but this particular construction seems to be necessary. In
fact, its apparent unreadability has been the main objection in this
thread.
 
A

Alex Hunsley

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.

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

Thanks for that HUGE laugh you just gave me, ak. Do you realise how funny what
you just said was?

So tell me, who are the writers of free software thinking of, if not their users?
I would argue that people selling commerical software are primarily thinking of
themselves - i.e. their profits - and are *less* likely to think of the end user.
Users have to do this and other things instead of one simple click.

Awww, boo for you. I would ask for a refund of the money you paid then.
What? You paid nothing for it? It was free? Well, I'd be thanking Paul for
writing it, instead of whining.
Freeware authors are the first to be interested in feedback on their programs,
but what they *don't* want to hear is feedback encroached in whining from
ungrateful users who think freeware authors *owe* them something.
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.

So I suppose you'd have paul wipe your behind for you? Put a bib on you for
when you eat, in case you spill some food? Hold your hand?

Remember, if it's freeware, that's a big bonus right there - and a little more
reading about and less laziness isn't going to hurt.

The fact that you readily try to blame Paul for messing up the program menus
that *you* reconfigured badly speaks volumes. I suppose you think the program
shouldn't be configurable at all in case you break it?

If you use, and try to configure, a free program, then you do so at your own
risk. No satisfaction is guaranteed at all. If you think something is wrong
with it, you could try telling the author - politely - or you could just stop
using the program.

alex
 
A

Alex Potter

Gary said:
Make me a few suggestions (for the reader, not OS -- I'd go linux for
that) but I have heard good things about Free Agent (?). More research
to do, I'm afraid.

Mozilla Thunderbird?
 

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,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top