Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #5757 > unrolled thread

StringBuilder Difficulties

Started byGene Wirchenko <genew@ocis.net>
First post2011-06-28 17:54 -0700
Last post2011-06-29 18:32 -0700
Articles 20 on this page of 98 — 25 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-28 17:54 -0700
    Re: StringBuilder Difficulties Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-28 21:29 -0400
      Re: StringBuilder Difficulties Lew <noone@lewscanon.com> - 2011-06-29 00:48 -0400
        Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-29 12:19 -0700
      Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-29 12:11 -0700
        Re: StringBuilder Difficulties Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-29 22:06 -0400
    Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-29 20:17 +0000
      Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-29 18:55 -0700
        Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-30 20:30 +0000
          Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-06-30 14:17 -0700
            Re: StringBuilder Difficulties Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-30 21:36 -0400
              Re: StringBuilder Difficulties "John B. Matthews" <nospam@nospam.invalid> - 2011-07-01 01:41 -0400
          Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-30 14:26 -0700
            Re: StringBuilder Difficulties Steve Sobol <sjsobol@JustThe.net> - 2011-06-30 17:33 -0700
            Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-01 20:47 +0000
              Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-01 17:29 -0700
                Re: StringBuilder Difficulties rossum <rossum48@coldmail.com> - 2011-07-02 11:36 +0100
                Re: StringBuilder Difficulties Robert Klemme <shortcutter@googlemail.com> - 2011-07-02 12:58 +0200
                  Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-04 07:52 -0700
                    Re: StringBuilder Difficulties Robert Klemme <shortcutter@googlemail.com> - 2011-07-04 21:45 +0200
                      Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-05 02:06 -0400
                        Re: StringBuilder Difficulties markspace <-@.> - 2011-07-05 09:32 -0700
                          Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-05 14:13 -0400
                            Re: StringBuilder Difficulties markspace <-@.> - 2011-07-05 12:51 -0700
                              Re: StringBuilder Difficulties Silvio <silvio@moc.com> - 2011-07-05 23:16 +0200
                                Re: StringBuilder Difficulties markspace <-@.> - 2011-07-05 15:08 -0700
                                  Re: StringBuilder Difficulties Silvio <silvio@moc.com> - 2011-07-06 09:41 +0200
                                    Re: StringBuilder Difficulties "eye" <eye@mocka.com> - 2011-07-06 09:55 +0000
                                      Re: StringBuilder Difficulties thoolen <thoolen@tholenbot.thorium> - 2011-07-06 05:37 -0400
                                      Re: StringBuilder Difficulties "thoolen" <thoolen@tholenbot.thorium> - 2011-07-06 08:43 -0400
                                        Re: StringBuilder Difficulties thoolen <thoolen@tholenbot.thorium> - 2011-07-06 22:30 -0400
                              Re: StringBuilder Difficulties "Stefan Robacki" <noemail@noemail.foobar> - 2011-07-06 00:04 -0400
                                Re: StringBuilder Difficulties thoolen <thoolen@tholenbot.thorium> - 2011-07-06 05:45 -0400
                                Re: StringBuilder Difficulties thoolen <thoolen@tholenbot.thorium> - 2011-07-06 08:26 -0400
                                  Re: StringBuilder Difficulties thoolen <thoolen@tholenbot.thorium> - 2011-07-06 22:36 -0400
                                Re: StringBuilder Difficulties "tholen@antispam.ham" <tholen@ifa.hawaii.edu> - 2011-07-06 06:09 -0700
                                  Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 22:40 -0400
                                    Re: StringBuilder Difficulties John Doe <jdoe@usenetlove.invalid> - 2011-07-14 06:50 +0000
                                      Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-14 02:58 -0400
                                        Re: StringBuilder Difficulties Jane Doe <jdoe@love.in.d.jungle.invalid> - 2011-07-14 10:20 -0400
                                          Re: StringBuilder Difficulties thoolen <tholen01@gmail.com> - 2011-07-14 07:33 -0700
                          Re: StringBuilder Difficulties Stanimir Stamenkov <s7an10@netscape.net> - 2011-07-05 23:44 +0300
                            Re: StringBuilder Difficulties markspace <-@.> - 2011-07-05 14:08 -0700
                Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-02 18:33 +0000
                  Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-02 16:56 -0400
                  Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-03 01:34 +0000
                    Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-07-02 19:55 -0700
                      Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-04 03:32 +0000
                    Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-04 08:04 -0700
                      Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 19:12 +0000
                        Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-05 14:06 -0700
                          Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 21:16 +0000
                            Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-05 17:29 -0700
                              Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-06 16:59 +0000
                                Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 19:52 -0400
                                  Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-07-06 16:58 -0700
                                    Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 19:52 -0400
                                      Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 21:54 -0400
                                        Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 22:18 -0400
                                          Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 22:41 -0400
                                    Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-08 17:45 +0000
                            Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 05:48 -0400
                              Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-06 16:59 +0000
                                Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-06 10:56 -0700
                                  Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-08 17:44 +0000
                                    Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-08 11:51 -0700
                                      Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-10 19:08 +0000
                                        Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-11 07:54 -0700
                                          Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-11 22:37 +0000
                                            Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-11 15:52 -0700
                            Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 08:25 -0400
                              Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 19:41 -0400
                                Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 19:58 -0400
                                  Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 21:57 -0400
                                    Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 22:17 -0400
                                      Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 22:44 -0400
                                        Re: StringBuilder Difficulties Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 12:51 +1000
                                          Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 23:02 -0400
                                            Re: StringBuilder Difficulties John Doe <jdoe@usenetlove.invalid> - 2011-07-14 06:32 +0000
                                              Re: StringBuilder Difficulties supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-14 02:57 -0400
                                              Re: StringBuilder Difficulties Jane Doe <jdoe@love.in.d.jungle.invalid> - 2011-07-14 10:07 -0400
                                                Re: StringBuilder Difficulties thoolen <tholen01@gmail.com> - 2011-07-14 07:24 -0700
                  Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-04 07:58 -0700
                    Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 19:09 +0000
                      Re: StringBuilder Difficulties KitKat <kitkat_11697@gmail.example.com> - 2011-07-05 15:15 -0400
                        Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 20:03 +0000
                      Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-07-05 14:11 -0700
                        Re: StringBuilder Difficulties blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-06 16:55 +0000
        Re: StringBuilder Difficulties lewbloch <lewbloch@gmail.com> - 2011-07-03 00:08 -0700
          Re: StringBuilder Difficulties Robert Klemme <shortcutter@googlemail.com> - 2011-07-03 12:35 +0200
            Re: StringBuilder Difficulties lewbloch <lewbloch@gmail.com> - 2011-07-04 04:07 -0700
    Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-06-29 14:38 -0700
      Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-29 15:00 -0700
        Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-06-29 15:52 -0700
          Re: StringBuilder Difficulties Gene Wirchenko <genew@ocis.net> - 2011-06-29 18:58 -0700
            Re: StringBuilder Difficulties Patricia Shanahan <pats@acm.org> - 2011-06-29 19:26 -0700
            Re: StringBuilder Difficulties lewbloch <lewbloch@gmail.com> - 2011-07-03 00:11 -0700
    Re: StringBuilder Difficulties Roedy Green <see_website@mindprod.com.invalid> - 2011-06-29 18:32 -0700

Page 1 of 5  [1] 2 3 4 5  Next page →


#5757 — StringBuilder Difficulties

FromGene Wirchenko <genew@ocis.net>
Date2011-06-28 17:54 -0700
SubjectStringBuilder Difficulties
Message-ID<c4tk07dv1pq7u8k32qd6b7o1brc2rj8r30@4ax.com>
Dear Java'ers:

     I am working with StringBuilder now.  I grant that it is faster
in execution, but it is taking a bunch of my time to get it straight.
I decided to change my VRString class (call-by-value-result) to
VRStringB.  Complications ensued.

     The amount of ornamentation required in my code was nasty, so I
did some simplifying.

     How does one assign a String value to a StringBuilder variable?
For the class below (before I defined .Set()), I needed
          cParsedWord.Value.replace(
	   0,cParsedWord.Value.length(),cScan.substring(xStart,xEnd));
With .Set(), I just need
          cParsedWord.Value.Set(cScan.substring(xStart,xEnd));

     For value equality to a String value, one needs something like
          cParsedWord.Value.toString().equals("some value")
(because without the .toString(), the comparison will fail) whereas
with .equals() below, this will do it
          cParsedWord.equals("some value")

***** Start of Code *****
// VRStringB Class
// StringBuilder Value-Result Parameter Handling
// Last Modification: 2011-06-28

class VRStringB
   {
   StringBuilder Value;

   VRStringB()
      {
      this.Value=new StringBuilder("");
      }

   VRStringB
    (
    StringBuilder Init
    )
      {
      this.Value=Init;
      }

   boolean equals
    (
    String theString
    )
      {
      return this.Value.toString().equals(theString);
      }

   void Set
    (
    String theString
    )
      {
      this.Value.replace(0,this.Value.length(),theString);
      }
   }
***** End of Code *****

     Am I missing something about StringBuilder, or is it really this
difficult to play with?  It would make a lot more sense to me if
StringBuilder worked more like String does.

Sincerely,

Gene Wirchenko

[toc] | [next] | [standalone]


#5758

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-06-28 21:29 -0400
Message-ID<iudv69$mgc$1@dont-email.me>
In reply to#5757
On 6/28/2011 8:54 PM, Gene Wirchenko wrote:
> Dear Java'ers:
>
>       I am working with StringBuilder now.  I grant that it is faster
> in execution, but it is taking a bunch of my time to get it straight.
> I decided to change my VRString class (call-by-value-result) to
> VRStringB.  Complications ensued.
>
>       The amount of ornamentation required in my code was nasty, so I
> did some simplifying.
>
>       How does one assign a String value to a StringBuilder variable?

     One does not "assign" a reference of type T1 to a reference
of unrelated type T2.  One can, however, create a StringBuilder
whose initial content is the same as that of a given String:

	String str = ...; // non-null
	StringBuilder sbd = new StringBuilder(str);

These are "the same" in the sense that str.length() == sbc.length()
and str.charAt(k) == sbd.charAt(k) for all 0 <= k < str.length().
Also, str.equals(sbd.toString()) returns true.

> [...]
>       Am I missing something about StringBuilder, or is it really this
> difficult to play with?

     You've been advised to read some Java tutorials or textbooks,
and (it seems) have chosen not to follow that advice.  Under the
circumstances, then, I'd have to say StringBuilder is "really this
difficult to play with."

     Perhaps you're "too pressed for time" to learn Java before writing
it.  Okay, yeah, that's reality, shit happens.  But if so, you've been
"pressed for time" for some weeks now, and (I'll wager) have already
wasted more time chasing blind alleys than you would have spent learning
the rudiments of the language.  (A potential infinite regress looms.)

> It would make a lot more sense to me if
> StringBuilder worked more like String does.

     StringBuilder is only of interest because it is mutable, while
String is immutable.  From this fact flow many of the necessary
differences that give you so much trouble, but that others take in
stride.

     Summary: Fer Crissakes, Gene, read the damn' book!

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#5760

FromLew <noone@lewscanon.com>
Date2011-06-29 00:48 -0400
Message-ID<iuear4$g4r$1@news.albasani.net>
In reply to#5758
Eric Sosman wrote:
> Summary: Fer Crissakes, Gene, read the damn' book!

And don't go plonking everyone who gives you good advice, either, Gene.  Eric, 
like markspace before him, is giving you good advice.  Follow it instead of 
copping an attitude like you did before.

Straight, unvarnished, blunt truth can feel bad at first, but it helps you. 
It really does.

Also, refusal to learn harms you.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#5780

FromGene Wirchenko <genew@ocis.net>
Date2011-06-29 12:19 -0700
Message-ID<38um0755dut4ikf1347brih75nj26ahjrd@4ax.com>
In reply to#5760
On Wed, 29 Jun 2011 00:48:40 -0400, Lew <noone@lewscanon.com> wrote:

>Eric Sosman wrote:
>> Summary: Fer Crissakes, Gene, read the damn' book!
>
>And don't go plonking everyone who gives you good advice, either, Gene.  Eric, 

     I do not.  I plonked one person who called my sanity into
question.  As I like to say, disagreeing one thing, but being
disagreeable is quite another.  Snarking on sanity is the latter.

>like markspace before him, is giving you good advice.  Follow it instead of 
>copping an attitude like you did before.
>
>Straight, unvarnished, blunt truth can feel bad at first, but it helps you. 
>It really does.

     The attitude of some posters is that they are Keepers of the
Truth.  I suggest that there are different realities.  I have
programmed in quite a few programming languages.  I see no need to
jettison what I have learned, because some practice is different with
Java.  If it is better, I will consider using it.  If it does not meet
my needs, I see no need to use it regardless of what Java practice is.

>Also, refusal to learn harms you.

     I do not refuse to learn, but I know what I want to accomplish
with my program.  A number of the suggestions have been plain
irrelevant.  Some of them have been quite useful, but those subthreads
tend to die, because there is no need for further discussion.  Thus,
discussion tends to continue only on points of contention.  They are
not the only points.  There is more agreement than disagreement, but
you would not know that the way some posters keep coming at me.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5779

FromGene Wirchenko <genew@ocis.net>
Date2011-06-29 12:11 -0700
Message-ID<5otm07t5lrvp0me457o7f3s2lpe7uo5mk6@4ax.com>
In reply to#5758
On Tue, 28 Jun 2011 21:29:00 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote:

>On 6/28/2011 8:54 PM, Gene Wirchenko wrote:
>> Dear Java'ers:
>>
>>       I am working with StringBuilder now.  I grant that it is faster
>> in execution, but it is taking a bunch of my time to get it straight.
>> I decided to change my VRString class (call-by-value-result) to
>> VRStringB.  Complications ensued.
>>
>>       The amount of ornamentation required in my code was nasty, so I
>> did some simplifying.
>>
>>       How does one assign a String value to a StringBuilder variable?
                                      ^^^^^
>     One does not "assign" a reference of type T1 to a reference
                              ^^^^^^^^^
      I wrote "value".

>of unrelated type T2.  One can, however, create a StringBuilder
>whose initial content is the same as that of a given String:
>
>	String str = ...; // non-null
>	StringBuilder sbd = new StringBuilder(str);

     I have found that, but I was wondering about how to do it with
the same StringBuilder object.  I thought that part of the advantage
of using StringBuilder was that the amount of object creation got cut
down.

>These are "the same" in the sense that str.length() == sbc.length()
>and str.charAt(k) == sbd.charAt(k) for all 0 <= k < str.length().
>Also, str.equals(sbd.toString()) returns true.

     IOW, a String value assigned to a StringBuilder variable.

>> [...]
>>       Am I missing something about StringBuilder, or is it really this
>> difficult to play with?
>
>     You've been advised to read some Java tutorials or textbooks,
>and (it seems) have chosen not to follow that advice.  Under the
>circumstances, then, I'd have to say StringBuilder is "really this
>difficult to play with."

     Which I have.  I have been referring to the docs for
StringBuilder, but the docs are rather incomplete, and I have to
guess.  This takestime.

>     Perhaps you're "too pressed for time" to learn Java before writing
>it.  Okay, yeah, that's reality, shit happens.  But if so, you've been
>"pressed for time" for some weeks now, and (I'll wager) have already

     A few and part-time.

>wasted more time chasing blind alleys than you would have spent learning
>the rudiments of the language.  (A potential infinite regress looms.)

     I know the rudiments.  I am having trouble with the next level.

     I have been asking here to try to knock out some of those blind
alleys.  I can get something to work, but I would prefer to have
something work well.

>> It would make a lot more sense to me if
>> StringBuilder worked more like String does.
>
>     StringBuilder is only of interest because it is mutable, while
>String is immutable.  From this fact flow many of the necessary
>differences that give you so much trouble, but that others take in
>stride.

     Why is the syntax so different?  It does not need to be, but it
is.  In order to change from String to StringBuilder, I had to modify
a bunch of code apart from changing variable types.

>     Summary: Fer Crissakes, Gene, read the damn' book!

     I have been RTFM.  The docs often say what, but without an
example and usually not why.  I am paddling the best I can.  Please do
not cannonball next to me.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5792

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-06-29 22:06 -0400
Message-ID<iugloe$8jv$1@dont-email.me>
In reply to#5779
On 6/29/2011 3:11 PM, Gene Wirchenko wrote:
> On Tue, 28 Jun 2011 21:29:00 -0400, Eric Sosman
> <esosman@ieee-dot-org.invalid>  wrote:
>
>> On 6/28/2011 8:54 PM, Gene Wirchenko wrote:
>>> Dear Java'ers:
>>>
>>>        I am working with StringBuilder now.  I grant that it is faster
>>> in execution, but it is taking a bunch of my time to get it straight.
>>> I decided to change my VRString class (call-by-value-result) to
>>> VRStringB.  Complications ensued.
>>>
>>>        The amount of ornamentation required in my code was nasty, so I
>>> did some simplifying.
>>>
>>>        How does one assign a String value to a StringBuilder variable?
>                                        ^^^^^
>>      One does not "assign" a reference of type T1 to a reference
>                                ^^^^^^^^^
>        I wrote "value".

     You also wrote "assign."  The only values Java can "assign"
are primitives and references -- in particular, Java cannot "assign"
the sequence of characters that make up the content of a String or
a StringBuilder.

>> 	String str = ...; // non-null
>> 	StringBuilder sbd = new StringBuilder(str);
>
>       I have found that, but I was wondering about how to do it with
> the same StringBuilder object.  I thought that part of the advantage
> of using StringBuilder was that the amount of object creation got cut
> down.

     Not sure what the "it" you mention is.  The efficiency "advantage,"
to the extent that there is one, is illustrated by

	String result = "";
	for (String s : bigBunchOfStrings)
	    result += s;

vs.

	StringBuilder buff = new StringBuilder();
	for (String s : bigBunchOfStrings)
	    buff.append(s);
	String result = buff.toString();

>> These are "the same" in the sense that str.length() == sbc.length()
>> and str.charAt(k) == sbd.charAt(k) for all 0<= k<  str.length().
>> Also, str.equals(sbd.toString()) returns true.
>
>       IOW, a String value assigned to a StringBuilder variable.

     See above; this is not "assignment."

>>      You've been advised to read some Java tutorials or textbooks,
>> and (it seems) have chosen not to follow that advice.  Under the
>> circumstances, then, I'd have to say StringBuilder is "really this
>> difficult to play with."
>
>       Which I have.  I have been referring to the docs for
> StringBuilder, but the docs are rather incomplete, and I have to
> guess.  This takestime.

     Elsethread you mention that you've programmed in "quite a few
programming languages."  Did you study them as diligently as you're
studying Java, or are you like the Real Programmer who "can write
FORTRAN in any language?"

     Okay, if you've got a distaste for Java and are reluctant to
learn it, that's the way it goes.  I've resisted C++ for years and
years on equally flimsy grounds.  But if you're just trying to "get
by" and don't intend to learn, then at the very least stop whining!

>       I know the rudiments.  I am having trouble with the next level.

     IMHO you do not yet know the rudiments.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#5783

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-06-29 20:17 +0000
Message-ID<971fj1Fg1rU1@mid.individual.net>
In reply to#5757
In article <c4tk07dv1pq7u8k32qd6b7o1brc2rj8r30@4ax.com>,
Gene Wirchenko  <genew@ocis.net> wrote:
> Dear Java'ers:
> 
>      I am working with StringBuilder now.  I grant that it is faster
> in execution, but it is taking a bunch of my time to get it straight.
> I decided to change my VRString class (call-by-value-result) to
> VRStringB.  Complications ensued.
> 
>      The amount of ornamentation required in my code was nasty, so I
> did some simplifying.
> 
>      How does one assign a String value to a StringBuilder variable?
> For the class below (before I defined .Set()), I needed
>           cParsedWord.Value.replace(
> 	   0,cParsedWord.Value.length(),cScan.substring(xStart,xEnd));
> With .Set(), I just need
>           cParsedWord.Value.Set(cScan.substring(xStart,xEnd));
> 
>      For value equality to a String value, one needs something like
>           cParsedWord.Value.toString().equals("some value")
> (because without the .toString(), the comparison will fail) whereas
> with .equals() below, this will do it
>           cParsedWord.equals("some value")
> 
> ***** Start of Code *****
> // VRStringB Class
> // StringBuilder Value-Result Parameter Handling
> // Last Modification: 2011-06-28
> 
> class VRStringB
>    {
>    StringBuilder Value;
> 
>    VRStringB()
>       {
>       this.Value=new StringBuilder("");
>       }
> 
>    VRStringB
>     (
>     StringBuilder Init
>     )
>       {
>       this.Value=Init;
>       }
> 
>    boolean equals
>     (
>     String theString
>     )
>       {
>       return this.Value.toString().equals(theString);
>       }
> 
>    void Set
>     (
>     String theString
>     )
>       {
>       this.Value.replace(0,this.Value.length(),theString);
>       }
>    }
> ***** End of Code *****
> 
>      Am I missing something about StringBuilder, or is it really this
> difficult to play with?  It would make a lot more sense to me if
> StringBuilder worked more like String does.


Well ....

If all you need is something that's like a String but whose value
can change, it seems to me [*] that you might be better off just
writing a simple wrapper class for String -- I'm thinking a class
with one variable of type String, which could even be public if
you don't want to fool with writing getter/setter methods.

[*] The experts may disagree.  I'm a journey(wo)man at best
with Java.

Where StringBuilder is useful is in, well, building strings;
a typical use case is a situation in which you want to build
up a string piece by piece.  You *could* write something like

String a = "first";
a += " second";
a += " etc";

and my *guess* is that this is not horribly inefficient if the
number of concatenation operations is small.  (The conventional
wisdom, as I understand it, is that the Java runtime is pretty
good at managing short-lived objects, so creating new objects is
not invariably something to avoid, though as with anything else
one shouldn't get carried away, maybe.  Again the experts may
disagree.)

But if there are a lot of concatenation operations it's said to be
more efficient to use a StringBuilder, e.g.:

StringBuilder sb = new StringBuilder();
sb.append("first");
sb.append(" second");
sb.append(" etc");
String a = sb.toString();

The above is what I mostly use StringBuilder for; there are
undoubtedly other things one can do with it as well, some of
which may be useful to you (I haven't followed carefully all the
threads you've started).

(I'm not optimistic that this commentary will be helpful, or
even that it will be read [*], given that you didn't reply to
my posts in the threads about passing method names to methods,
but I guess I'll try again ....  <shrug> )

[*] That's not actually meant as snark; not long ago I changed
the e-mail address I use to post, to a GMail one, and I'm under
the impression that some Usenet participants routinely filter out
anything from a GMail address, so I worry just a bit ....

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

[toc] | [prev] | [next] | [standalone]


#5790

FromGene Wirchenko <genew@ocis.net>
Date2011-06-29 18:55 -0700
Message-ID<irln07dveti624e71v8viderf0hjtudue5@4ax.com>
In reply to#5783
On 29 Jun 2011 20:17:37 GMT, blmblm@myrealbox.com
<blmblm.myrealbox@gmail.com> wrote:

>In article <c4tk07dv1pq7u8k32qd6b7o1brc2rj8r30@4ax.com>,
>Gene Wirchenko  <genew@ocis.net> wrote:

[snip]

>>      Am I missing something about StringBuilder, or is it really this
>> difficult to play with?  It would make a lot more sense to me if
>> StringBuilder worked more like String does.

[snip]

>up a string piece by piece.  You *could* write something like
>
>String a = "first";
>a += " second";
>a += " etc";
>
>and my *guess* is that this is not horribly inefficient if the
>number of concatenation operations is small.  (The conventional

     IOW, who cares if it is only a bit of inefficiency?  Agreed.

>wisdom, as I understand it, is that the Java runtime is pretty
>good at managing short-lived objects, so creating new objects is
>not invariably something to avoid, though as with anything else
>one shouldn't get carried away, maybe.  Again the experts may
>disagree.)
>
>But if there are a lot of concatenation operations it's said to be
>more efficient to use a StringBuilder, e.g.:
>
>StringBuilder sb = new StringBuilder();
>sb.append("first");
>sb.append(" second");
>sb.append(" etc");
>String a = sb.toString();

     It is.  My test code appends one character at a time. Switching
from String to StringBuilder cut the execution time by about 40%.

>The above is what I mostly use StringBuilder for; there are
>undoubtedly other things one can do with it as well, some of
>which may be useful to you (I haven't followed carefully all the
>threads you've started).

     I have managed to get to the point where I have found out what
you have posted here, and I agree with it, too.

>(I'm not optimistic that this commentary will be helpful, or
>even that it will be read [*], given that you didn't reply to
>my posts in the threads about passing method names to methods,
>but I guess I'll try again ....  <shrug> )
>
>[*] That's not actually meant as snark; not long ago I changed
>the e-mail address I use to post, to a GMail one, and I'm under
>the impression that some Usenet participants routinely filter out
>anything from a GMail address, so I worry just a bit ....

     Not me.  I killfile only the deserving (meaning those undeserving
of my time).

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5795

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-06-30 20:30 +0000
Message-ID<9744m8FpnhU3@mid.individual.net>
In reply to#5790
In article <irln07dveti624e71v8viderf0hjtudue5@4ax.com>,
Gene Wirchenko  <genew@ocis.net> wrote:
> <blmblm.myrealbox@gmail.com> wrote:
> 
> >In article <c4tk07dv1pq7u8k32qd6b7o1brc2rj8r30@4ax.com>,
> >Gene Wirchenko  <genew@ocis.net> wrote:

[ snip ]

> >You *could* write something like
> >
> >String a = "first";
> >a += " second";
> >a += " etc";
> >
> >and my *guess* is that this is not horribly inefficient if the
> >number of concatenation operations is small.  (The conventional
> 
>      IOW, who cares if it is only a bit of inefficiency?  Agreed.
> 
> >wisdom, as I understand it, is that the Java runtime is pretty
> >good at managing short-lived objects, so creating new objects is
> >not invariably something to avoid, though as with anything else
> >one shouldn't get carried away, maybe.  Again the experts may
> >disagree.)
> >
> >But if there are a lot of concatenation operations it's said to be
> >more efficient to use a StringBuilder, e.g.:
> >
> >StringBuilder sb = new StringBuilder();
> >sb.append("first");
> >sb.append(" second");
> >sb.append(" etc");
> >String a = sb.toString();
> 
>      It is.  My test code appends one character at a time. Switching
> >from String to StringBuilder cut the execution time by about 40%.

So okay, you probably *do* want to use StringBuilder, and having
that confirmed by experiment is good.  

[ snip ]

> >(I'm not optimistic that this commentary will be helpful, or
> >even that it will be read [*], given that you didn't reply to
> >my posts in the threads about passing method names to methods,
> >but I guess I'll try again ....  <shrug> )
> >
> >[*] That's not actually meant as snark; not long ago I changed
> >the e-mail address I use to post, to a GMail one, and I'm under
> >the impression that some Usenet participants routinely filter out
> >anything from a GMail address, so I worry just a bit ....
> 
>      Not me.  I killfile only the deserving (meaning those undeserving
> of my time).

More useful information; thanks for the reply.

A general comment:  I'm inclined to agree with the people who are
saying that in general it seems like you're trying to write [name
of your favorite language] programs in Java, and in the long term
that seems less optimal than trying to grok the Java mindset.  
I think part of it may be struggling with the object-oriented
paradigm, but part of it may just be coming to terms with the fact
that Java is, as I think Patricia Shanahan said not long ago
(possibly in another thread), that Java is just plain verbose.

But I have some sympathy with the desire just to get something 
running:  I spent a number of hours a while back trying to teach
myself some Scheme and in the process trying make it conform to
my strongly-typed-languages-trained mindset, and I'd probably
have done better to get a good introductory book and try to grok
the no-types(?) mindset.  (Maybe I'll try again at some point.)

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

[toc] | [prev] | [next] | [standalone]


#5796

FromPatricia Shanahan <pats@acm.org>
Date2011-06-30 14:17 -0700
Message-ID<1v-dnd5CMOdnepHTnZ2dnUVZ_hmdnZ2d@earthlink.com>
In reply to#5795
On 6/30/2011 1:30 PM, blmblm@myrealbox.com wrote:
...
> But I have some sympathy with the desire just to get something
> running:  I spent a number of hours a while back trying to teach
> myself some Scheme and in the process trying make it conform to
> my strongly-typed-languages-trained mindset, and I'd probably
> have done better to get a good introductory book and try to grok
> the no-types(?) mindset.  (Maybe I'll try again at some point.)
>

I've tried several approaches to learning programming languages, and the
one that works best for me is to get an introductory book, and work
through it, reading each chapter and doing the exercises.

In working through the elementary material, I build the mindset,
terminology, and assumptions for the language I'm learning.

Patricia

[toc] | [prev] | [next] | [standalone]


#5806

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-06-30 21:36 -0400
Message-ID<iuj8bk$v5i$1@dont-email.me>
In reply to#5796
On 6/30/2011 5:17 PM, Patricia Shanahan wrote:
> On 6/30/2011 1:30 PM, blmblm@myrealbox.com wrote:
> ...
>> But I have some sympathy with the desire just to get something
>> running: I spent a number of hours a while back trying to teach
>> myself some Scheme and in the process trying make it conform to
>> my strongly-typed-languages-trained mindset, and I'd probably
>> have done better to get a good introductory book and try to grok
>> the no-types(?) mindset. (Maybe I'll try again at some point.)
>>
>
> I've tried several approaches to learning programming languages, and the
> one that works best for me is to get an introductory book, and work
> through it, reading each chapter and doing the exercises.

     To this I'd add (and perhaps this is reflective only of my
own modes of learning): Get hold of some samples of good code in
the language (or "believed to be good," since the learner is in
a poor position to judge), and read the code.  With the tutorials
and reference works at one's elbow, of course.  "Why didn't he need
to grab a lock here?"  "Oh, *that's* how you handle  file-not-found!"
And so on, and so on.

     I still recall learning SNOBOL years and years ago by studying
the SNOBOL source of the SNOBOL compiler while frantically flipping
pages in the SNOBOL book.  My grasp of the language SNOBOLed.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#5807

From"John B. Matthews" <nospam@nospam.invalid>
Date2011-07-01 01:41 -0400
Message-ID<nospam-5EA9EF.01415801072011@news.aioe.org>
In reply to#5806
In article <iuj8bk$v5i$1@dont-email.me>,
 Eric Sosman <esosman@ieee-dot-org.invalid> wrote:

>      I still recall learning SNOBOL years and years ago by studying
> the SNOBOL source of the SNOBOL compiler while frantically flipping
> pages in the SNOBOL book.  My grasp of the language SNOBOLed.

You might enjoy looking at the SPITBOL operations that are part of the 
GNAT Ada Library in the package, GNAT.Spitbol:

<http://gcc.gnu.org/onlinedocs/gnat_rm/The-GNAT-Library.html#The-GNAT-Library>

Much of the documentation is in the corresponding specification (.ads) 
files:

<http://gcc.gnu.org/viewcvs/trunk/gcc/ada/>

GNAT.Spitbol.Patterns is an example:

<http://gcc.gnu.org/viewcvs/trunk/gcc/ada/g-spipat.ads?revision=139296&view=markup>

The GPL version is available here:

<http://libre.adacore.com/libre/>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#5797

FromGene Wirchenko <genew@ocis.net>
Date2011-06-30 14:26 -0700
Message-ID<6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>
In reply to#5795
On 30 Jun 2011 20:30:00 GMT, blmblm@myrealbox.com
<blmblm.myrealbox@gmail.com> wrote:

[snip]

>A general comment:  I'm inclined to agree with the people who are
>saying that in general it seems like you're trying to write [name
>of your favorite language] programs in Java, and in the long term
>that seems less optimal than trying to grok the Java mindset.  

     My mindset is that I want to get my work done.  I do not care
about the Java mindset except as it helps me get my work done.

>I think part of it may be struggling with the object-oriented
>paradigm, but part of it may just be coming to terms with the fact

     No, I am experienced with OOP.

>that Java is, as I think Patricia Shanahan said not long ago
>(possibly in another thread), that Java is just plain verbose.

     Well, I posted about the verbosity earlier and got flak over it.

>But I have some sympathy with the desire just to get something 
>running:  I spent a number of hours a while back trying to teach

     And without having to buy into a language religion.

>myself some Scheme and in the process trying make it conform to
>my strongly-typed-languages-trained mindset, and I'd probably
>have done better to get a good introductory book and try to grok
>the no-types(?) mindset.  (Maybe I'll try again at some point.)

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5805

FromSteve Sobol <sjsobol@JustThe.net>
Date2011-06-30 17:33 -0700
Message-ID<MPG.2876b5c2caed60c79897ae@news.justthe.net>
In reply to#5797
In article <6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>, Gene Wirchenko 
says...

> >A general comment:  I'm inclined to agree with the people who are
> >saying that in general it seems like you're trying to write [name
> >of your favorite language] programs in Java, and in the long term
> >that seems less optimal than trying to grok the Java mindset.  
> 
>      My mindset is that I want to get my work done.  I do not care
> about the Java mindset except as it helps me get my work done.

Your choice, but unless *no one* is ever going to look at your code, I 
don't think yours is the right attitude to adopt.

I do try to follow the coding conventions of whichever language I happen 
to be using. Seems to me that that is a BCP...



-- 
Steve Sobol - Programming/WebDev/IT Support
sjsobol@JustThe.net

[toc] | [prev] | [next] | [standalone]


#5813

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-07-01 20:47 +0000
Message-ID<976q3jF3etU2@mid.individual.net>
In reply to#5797
In article <6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>,
Gene Wirchenko  <genew@ocis.net> wrote:
> On 30 Jun 2011 20:30:00 GMT, blmblm@myrealbox.com
> <blmblm.myrealbox@gmail.com> wrote:
> 
> [snip]
> 
> >A general comment:  I'm inclined to agree with the people who are
> >saying that in general it seems like you're trying to write [name
> >of your favorite language] programs in Java, and in the long term
> >that seems less optimal than trying to grok the Java mindset.  
> 
>      My mindset is that I want to get my work done.  I do not care
> about the Java mindset except as it helps me get my work done.

Yes, and if you were going to do a lot of programming in Java it
would seem to make sense to adapt to the local customs, so to speak.
Not to do so seems to me like fighting with your tools, which, well,
I do it too sometimes, but it does get in the way of getting stuff
done.

> >I think part of it may be struggling with the object-oriented
> >paradigm, but part of it may just be coming to terms with the fact
> 
>      No, I am experienced with OOP.

Huh.  Well, with all due respect ....

I'd have said otherwise given that all of the variables and methods
in your TimingTesting program (the version I tried revising) seem
to be static (except the local variables).  I'm also puzzled by why
that program duplicates so much code, when you could have factored
out the parts that are different using objects-as-code-wrappers.
But maybe the O-O languages you've used before don't make you do
that, and adapting to that particular Java idiom seemed not worth
the trouble.

> >that Java is, as I think Patricia Shanahan said not long ago
> >(possibly in another thread), that Java is just plain verbose.
> 
>      Well, I posted about the verbosity earlier and got flak over it.
> 
> >But I have some sympathy with the desire just to get something 
> >running:  I spent a number of hours a while back trying to teach
> 
>      And without having to buy into a language religion.

Hm.  I wouldn't say that adapting to local customs constitutes
buying into a language religion.  YMMV, I suppose.

> >myself some Scheme and in the process trying make it conform to
> >my strongly-typed-languages-trained mindset, and I'd probably
> >have done better to get a good introductory book and try to grok
> >the no-types(?) mindset.  (Maybe I'll try again at some point.)

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

[toc] | [prev] | [next] | [standalone]


#5815

FromGene Wirchenko <genew@ocis.net>
Date2011-07-01 17:29 -0700
Message-ID<e9ps07h56utkftkp8fcarm7uhkk5t999le@4ax.com>
In reply to#5813
On 1 Jul 2011 20:47:47 GMT, blmblm@myrealbox.com
<blmblm.myrealbox@gmail.com> wrote:

>In article <6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>,
>Gene Wirchenko  <genew@ocis.net> wrote:
>> On 30 Jun 2011 20:30:00 GMT, blmblm@myrealbox.com
>> <blmblm.myrealbox@gmail.com> wrote:
>> 
>> [snip]
>> 
>> >A general comment:  I'm inclined to agree with the people who are
>> >saying that in general it seems like you're trying to write [name
>> >of your favorite language] programs in Java, and in the long term
>> >that seems less optimal than trying to grok the Java mindset.  
>> 
>>      My mindset is that I want to get my work done.  I do not care
>> about the Java mindset except as it helps me get my work done.
>
>Yes, and if you were going to do a lot of programming in Java it
>would seem to make sense to adapt to the local customs, so to speak.
>Not to do so seems to me like fighting with your tools, which, well,
>I do it too sometimes, but it does get in the way of getting stuff
>done.

     My tools include manyyears of experience programming.  I do not
think that Java is such a precious snowflake -- the same is true of
any language -- that I should have to throw all that experience away
in order to use the language.

>> >I think part of it may be struggling with the object-oriented
>> >paradigm, but part of it may just be coming to terms with the fact
>> 
>>      No, I am experienced with OOP.
>
>Huh.  Well, with all due respect ....
>
>I'd have said otherwise given that all of the variables and methods
>in your TimingTesting program (the version I tried revising) seem
>to be static (except the local variables).  I'm also puzzled by why
>that program duplicates so much code, when you could have factored
>out the parts that are different using objects-as-code-wrappers.
>But maybe the O-O languages you've used before don't make you do
>that, and adapting to that particular Java idiom seemed not worth
>the trouble.

     Oh, I asked about that.  One apparently can not pass a function
pointer parameter as in C.  The ways that were posted involved lookup
every time AFIACS and I judged that it might swamp what I was
measuring (checking if a character were in a set).  So, to my chagrin,
I had to go with cut-and-paste.

>> >that Java is, as I think Patricia Shanahan said not long ago
>> >(possibly in another thread), that Java is just plain verbose.
>> 
>>      Well, I posted about the verbosity earlier and got flak over it.
>> 
>> >But I have some sympathy with the desire just to get something 
>> >running:  I spent a number of hours a while back trying to teach
>> 
>>      And without having to buy into a language religion.
>
>Hm.  I wouldn't say that adapting to local customs constitutes
>buying into a language religion.  YMMV, I suppose.

     Some of the posters have been quite vociferous about it.

>> >myself some Scheme and in the process trying make it conform to
>> >my strongly-typed-languages-trained mindset, and I'd probably
>> >have done better to get a good introductory book and try to grok
>> >the no-types(?) mindset.  (Maybe I'll try again at some point.)

     I am pretty much past the intro stage and into the pain stage
where there is not so much help.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5820

Fromrossum <rossum48@coldmail.com>
Date2011-07-02 11:36 +0100
Message-ID<s3tt07lbvuv5epqb2kp6uejvnmlrh9gj2n@4ax.com>
In reply to#5815
On Fri, 01 Jul 2011 17:29:15 -0700, Gene Wirchenko <genew@ocis.net>
wrote:

>One apparently can not pass a function
>pointer parameter as in C.
Just pass a Runnable, or a convenient equivalent.

Java is not C.

rossum

[toc] | [prev] | [next] | [standalone]


#5821

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-07-02 12:58 +0200
Message-ID<978bv1FnqaU1@mid.individual.net>
In reply to#5815
On 07/02/2011 02:29 AM, Gene Wirchenko wrote:
> On 1 Jul 2011 20:47:47 GMT, blmblm@myrealbox.com
> <blmblm.myrealbox@gmail.com>  wrote:
>
>> In article<6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>,
>> Gene Wirchenko<genew@ocis.net>  wrote:
>>> On 30 Jun 2011 20:30:00 GMT, blmblm@myrealbox.com
>>> <blmblm.myrealbox@gmail.com>  wrote:
>>>
>>> [snip]
>>>
>>>> A general comment:  I'm inclined to agree with the people who are
>>>> saying that in general it seems like you're trying to write [name
>>>> of your favorite language] programs in Java, and in the long term
>>>> that seems less optimal than trying to grok the Java mindset.
>>>
>>>       My mindset is that I want to get my work done.  I do not care
>>> about the Java mindset except as it helps me get my work done.
>>
>> Yes, and if you were going to do a lot of programming in Java it
>> would seem to make sense to adapt to the local customs, so to speak.
>> Not to do so seems to me like fighting with your tools, which, well,
>> I do it too sometimes, but it does get in the way of getting stuff
>> done.
>
>       My tools include manyyears of experience programming.  I do not
> think that Java is such a precious snowflake -- the same is true of
> any language -- that I should have to throw all that experience away
> in order to use the language.

As far as I can see nobody asked you to do that.  If adjusting to a new 
language's mindset requires you to throw away everything you've learned 
so far then you probably better stick with the previous experience and 
tools.  That will be much more efficient and beneficial.

If, on the other hand, you want to use a new language then you typically 
get best results (or results at all) if you adjust to the environment 
you find.  You may have noticed that your issues with StringBuilder seem 
to be quite unique - others posting here do not seem to have those 
issues.  In my experience this is usually an indication that I am doing 
something wrong or haven't properly understood the new environment yet.

>>>> I think part of it may be struggling with the object-oriented
>>>> paradigm, but part of it may just be coming to terms with the fact
>>>
>>>       No, I am experienced with OOP.
>>
>> Huh.  Well, with all due respect ....
>>
>> I'd have said otherwise given that all of the variables and methods
>> in your TimingTesting program (the version I tried revising) seem
>> to be static (except the local variables).  I'm also puzzled by why
>> that program duplicates so much code, when you could have factored
>> out the parts that are different using objects-as-code-wrappers.
>> But maybe the O-O languages you've used before don't make you do
>> that, and adapting to that particular Java idiom seemed not worth
>> the trouble.
>
>       Oh, I asked about that.  One apparently can not pass a function
> pointer parameter as in C.  The ways that were posted involved lookup
> every time AFIACS and I judged that it might swamp what I was
> measuring (checking if a character were in a set).  So, to my chagrin,
> I had to go with cut-and-paste.

The usual solution in Java is to factor out an API into an interface and 
have several implementations of that interface.  See Callable for 
example - this basically encapsulates a "function" with no arguments and 
a single return value:

http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Callable.html

In your TimingTesting program you could define a private interface like this

private interface Search {
   boolean search(char c);
}

Then you create inner classes

private final class SequentialSearch implements Search {
   @Override
   boolean search(char c) {
     for ( int i = 0; i < chars.length(); ++i ) {
       if (chars.charAt(i) == c) {
         return true;
       }
     }

     return false;
   }
}

public void parseSequentialSearch() {
   parse(new SequentialSearch());
}

private void parse(Search s) {
       int xScan=0;
       boolean fBuildingIdent=false;
       boolean fInIdentChars;
       String cIdent="";     // fussy init
       while (xScan<cParseString.length())
          {
          char CurrChar=cParseString.charAt(xScan);
          fInIdentChars=s.search(CurrChar);
...
}

etc.

This would be the _minimal_ refactoring to get what you want but you 
also need to switch from having all the state static in TimingTesting to 
instance.  Chances are that a more thorough refactoring yields a 
significantly better (in terms of OO and modularity) solution.

Btw, if you want to create a parser in Java then I recommend looking 
into ANTLR.  There is even a graphical UI (ANTLRWorks) which helps get 
results quickly and even has grammar debugging.  Cool stuff!

http://www.antlr.org/works/index.html

Cheers

	robert

[toc] | [prev] | [next] | [standalone]


#5849

FromGene Wirchenko <genew@ocis.net>
Date2011-07-04 07:52 -0700
Message-ID<gfk317di8imjcuvfgrn2mgtug1cne9m1m9@4ax.com>
In reply to#5821
On Sat, 02 Jul 2011 12:58:40 +0200, Robert Klemme
<shortcutter@googlemail.com> wrote:

>On 07/02/2011 02:29 AM, Gene Wirchenko wrote:

[snip]

>>       My tools include manyyears of experience programming.  I do not
>> think that Java is such a precious snowflake -- the same is true of
>> any language -- that I should have to throw all that experience away
>> in order to use the language.
>
>As far as I can see nobody asked you to do that.  If adjusting to a new 
>language's mindset requires you to throw away everything you've learned 
>so far then you probably better stick with the previous experience and 
>tools.  That will be much more efficient and beneficial.

     I do not name my variables the way some think I should.  I do not
use exceptions the way some others think I should.  And on and on.

     There have been some very good posts which I have appreciated.
There have been others which were nitpicky and antagonistic.

>If, on the other hand, you want to use a new language then you typically 
>get best results (or results at all) if you adjust to the environment 
>you find.  You may have noticed that your issues with StringBuilder seem 
>to be quite unique - others posting here do not seem to have those 
>issues.  In my experience this is usually an indication that I am doing 
>something wrong or haven't properly understood the new environment yet.

     Well, no, they are not.  I had a problem with StringBuilder
comparison with a string.  I STWed and found a discussion that was
originally posted here.  Roedy was involved in that discussion.

[snip]

>>       Oh, I asked about that.  One apparently can not pass a function
>> pointer parameter as in C.  The ways that were posted involved lookup
>> every time AFIACS and I judged that it might swamp what I was
>> measuring (checking if a character were in a set).  So, to my chagrin,
>> I had to go with cut-and-paste.
>
>The usual solution in Java is to factor out an API into an interface and 
>have several implementations of that interface.  See Callable for 
>example - this basically encapsulates a "function" with no arguments and 
>a single return value:

     It is horribly verbose.  Java: COBOL++?

[snip]

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5856

FromRobert Klemme <shortcutter@googlemail.com>
Date2011-07-04 21:45 +0200
Message-ID<97ejjfFrh1U1@mid.individual.net>
In reply to#5849
On 04.07.2011 16:52, Gene Wirchenko wrote:
> On Sat, 02 Jul 2011 12:58:40 +0200, Robert Klemme
> <shortcutter@googlemail.com>  wrote:
>
>> On 07/02/2011 02:29 AM, Gene Wirchenko wrote:

>>>        Oh, I asked about that.  One apparently can not pass a function
>>> pointer parameter as in C.  The ways that were posted involved lookup
>>> every time AFIACS and I judged that it might swamp what I was
>>> measuring (checking if a character were in a set).  So, to my chagrin,
>>> I had to go with cut-and-paste.
>>
>> The usual solution in Java is to factor out an API into an interface and
>> have several implementations of that interface.  See Callable for
>> example - this basically encapsulates a "function" with no arguments and
>> a single return value:
>
>       It is horribly verbose.  Java: COBOL++?

In part it's the price you pay for static typing (somewhere all those 
type names have to appear).  Tools are good enough these days to offload 
you from most of the hand typing via completion.  If you have not yet 
used a modern IDE yet you should really try Eclipse or NetBeans both of 
which are free of charge.

If you look for a language on the JVM with less overhead maybe Scala is 
for you.  Some people do find it too compact though.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web