Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: blmblm@myrealbox.com Newsgroups: comp.lang.java.programmer Subject: Re: The greeting code in Java Date: 22 Jun 2011 20:04:21 GMT Organization: None Lines: 57 Message-ID: <96f064F46aU6@mid.individual.net> References: <3d6aab49-9a4a-4614-af12-bb1c95bebbe7@w4g2000yqm.googlegroups.com> <96ce30Fc6lU4@mid.individual.net> X-Trace: individual.net Q37FDkoaiZFT5jelCxGOrActg1nxn7Agmkh56XjudYBKdJinYt X-Orig-Path: not-for-mail Cancel-Lock: sha1:D2cVn+iqjBmDKGyBRgbrrJP62FQ= X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5546 In article , Tobias Blass wrote: > On 2011-06-21, blmblm myrealbox.com wrote: > > In article , > > Tobias Blass wrote: > >> On 2011-06-20, blmblm myrealbox.com wrote: > >> > In article , > >> > Jeff Higgins wrote: > >> >> > >> >> On 06/19/2011 02:36 PM, Saeed Amrollahi wrote: > >> >> > On Jun 19, 6:31 pm, Jeff Higgins wrote: > >> >> >> On 06/19/2011 09:06 AM, Saeed Amrollahi wrote: > >> >> >> > >> >> >>> What are the problems of my code and how can I write > >> >> >>> a better one. Please throw some light. > >> >> >> > >> >> >> What means better? > >> >> > > >> >> > For example using less abstractions and less involve with Java > >> >> > stream class hierarchy. > >> >> > >> >> For a beginner, learning to write C in Java is unhelpful. > >> > > >> > Even in C one would not be likely to input a string by reading one > >> > charaacter at a time -- in a beginner program at least. [ snip ] > >> Hmm at least in K&R (the inofficial standard C learning book) you often find > >> while((c=getchar())!=EOF) > >> > >> It's less performant than reading whole blocks but in many cases much simpler > >> (And that's what matters in a learning book) > > > > Well, if you say so (my copy of K&R is not easily accessed right > > now). Certainly that style makes sense in examples in which > > the goal is to process a character at a time (to classify/count > > characters, for example, or to copy one file to another). > > > > But is this style used in examples in which the objective is to > > collect one whitespace-delimited "string" and print it? Huh. > > Maybe I need to reread K&R .... > > > > Obviously it is not the right choice for any problem you might encounter (the > K&R examples are copy input to output, count characters, count lines etc.) but > there are situations where getchar() is useful and one should be aware that > it exists. I don't want to say that one should use it everywhere. Well, we agree that there are situations in which reading input a character at a time makes perfect sense, and others in which it doesn't. I claim that the OP's greeting program is in the second category. You might disagree! -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.