Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Passing a Method Name to a Method

Reply
Thread Tools

Passing a Method Name to a Method

 
 
Arved Sandstrom
Guest
Posts: n/a
 
      06-23-2011
On 11-06-23 01:33 PM, Joshua Cranmer wrote:
> On 6/23/2011 9:23 AM, Arved Sandstrom wrote:
>> Setting things up the "OO way" in this situation, while aesthetically
>> appealing, also means that you've made a deliberate design decision to
>> allow for more straightforward swapping of parse logic.

>
> Given that most of the parsers I deal with are lengthy recursive-descent
> parsers, I assumed that there would have been a distinct parser object
> that handled the lexing and parsing itself and furthermore that two
> parsers would want to be in two separate classes. Also, since the
> question was asked with the purpose of timing, I presumed that it was
> fairly large and complicated parsers that were being tested for the
> purpose of determining the more efficient one. As a logical consequence
> of these assumptions, I would have assumed that the natural way to
> implement this code is as objects, hence my surprise to not find it
> implemented in such a manner.
>
> Of course, all of this relies on my assumptions being correct.
>

In this particular situation, even if the code is throwaway testing
stuff, implementing it your way is either the best decision or a good
decision. After all, it's not exactly a complicated OO problem.

My point was simply that if this *is* back-of-the-envelope test code,
that using interfaces etc is not necessary. It's not inadvisable - it's
just not _needed_.

Don't mind me - the last few years I've been questioning dogma. All of
it.

AHS
 
Reply With Quote
 
 
 
 
Nebulous
Guest
Posts: n/a
 
      06-23-2011
On Jun 23, 1:43*pm, "Fuschia, President-Elect of the Bright Purplish-
Green Council" <(E-Mail Removed)> wrote:
> On 23/06/2011 12:07 PM, Gene Wirchenko wrote:
>
> > * * * What is the difference between the two newsgroups other than that
> > c.l.j.help seems fairly moribund?

>
> This group's not much less moribund.
>
> It almost makes you wish for the good old days when there were thousands
> of posts a month here and [suspected implied insult deleted]


No. None of the nasty things that you have said or implied about me
are at all true.

 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-23-2011
On Wed, 22 Jun 2011 16:00:46 -0400, "Fuschia, President-Elect of the
Bright Purplish-Green Council" <(E-Mail Removed)> wrote:

>On 22/06/2011 3:46 PM, Gene Wirchenko wrote:
>> Dear Jav'ers:
>>
>> Maybe I will find this after searching more, but so far, no good.
>>
>> I want to pass a parameter of a method name to another method.
>>
>> N.B.: I do not want to pass the method name as a string. I want
>> to pass it as a pointer / reference / whatever term is used for this
>> in Java.

>
>Unfortunately, you can't do this easily or efficiently (you'd need to
>use the Reflection API's Method objects) in Java; what you really want
>is a functional language like Clojure or Scala.
>
>If you really must use Java, define an interface that ThisWay and
>ThatWay can be instances of and which specify a parse method, and pass
>an instance to the parser class's method. (The so-called "strategy
>pattern".)


The reason why I want to do this is to check speed of
implementations in Java. Obviously, I have to use Java to test Java
impementations.

I am writing a preprocessor and need to implement a simple
parser. It has to recognise identifiers. The characters allowed for
identifiers vary from language to language. I have the character set
configurable.

The question is which is the best way to implement the function
that returns whether an input character is in the set of identifier
characters. There are three ways that I want to test:
Stuff them in a String and access sequentially.
Stuff them in a String and access with a binary search.
Stuff them in a Treeset.
The outer parser code will be the same. The only difference will be
which character-checking method will be called.

I suppose I am going to end up doing cut-and-paste to make my
test program.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-23-2011
On Wed, 22 Jun 2011 22:30:42 -0400, Joshua Cranmer
<(E-Mail Removed)> wrote:

[snip]

>> static returntype ThisWay(formal parms)
>> {...}
>>
>> static returntype ThatWay(formal parms)
>> {...}

>
>Why are you having static methods (on the same class, I presume) for two
>different ways of parsing instead of using separate parser classes?


I am not writing different parsers. I am writing different
methods for handling a small (but frequently called) part of the
parsing. I wish to test how fast each of these methods are.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-23-2011
Gene Wirchenko <(E-Mail Removed)> writes:
> The question is which is the best way to implement the function
>that returns whether an input character is in the set of identifier
>characters. There are three ways that I want to test:
> Stuff them in a String and access sequentially.
> Stuff them in a String and access with a binary search.
> Stuff them in a Treeset.


This would all only be needed, when it had to change at run time,
which is not the case here. So one uses source code, for example:

public static boolean isIdentifierCharacter( final int codePoint )
{ return codePoint >= 'a' && codePoint <= 'z'; }

. When the set of possible characters is small (ASCII), one can
use an array:

return isIdentifier[ codePoint ];

. For Unicode, one might use character properties, for example:

return java.lang.Character.isAlphabetic( codePoint );

 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-23-2011
On 23 Jun 2011 22:10:14 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram)
wrote:

>Gene Wirchenko <(E-Mail Removed)> writes:
>> The question is which is the best way to implement the function
>>that returns whether an input character is in the set of identifier
>>characters. There are three ways that I want to test:
>> Stuff them in a String and access sequentially.
>> Stuff them in a String and access with a binary search.
>> Stuff them in a Treeset.

>
> This would all only be needed, when it had to change at run time,
> which is not the case here. So one uses source code, for example:


Bad assumption. It is the case for what I am doing.

[snip]

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-23-2011
On Thu, 23 Jun 2011 09:06:08 -0300, Arved Sandstrom
<(E-Mail Removed)> wrote:

[snip]

>At this stage of the game, considering the original problem statement, I
>haven't seen any compelling arguments for not doing
>
>for (i=1; i<=nRepetitions; i++)
> ParseThisWay(args);
>
>and
>
>for (i=1; i<=nRepetitions; i++)
> ParseThatWay(args);
>
>(Note the editing from the original.) I mean, there's a strong
>distinction between testing different methods of parsing (which the OP
>mentioned he was doing) and coding your application to permit selection
>of arbitrary parsing method.
>
>We may be thinking at cross-purposes here. It could be that Gene,
>incidental to the problem of testing parsing techniques, might really
>just be curious as to whether it's possible to do something like he
>asked about, i.e. function pointer-looking things. Practically everyone


Yes.

>else seems to have posited a Parsing U"ber-Problem which demands an
>interface/pattern-based adaptive dynamic solution for production use,
>and for my part I'm suggesting that if the actual issue is simply
>adhoc/experimentally testing a couple of different chunks of code why
>not just hardcode a couple of different methods (the engineering Good
>Enough approach).


Quite so. I am lazy. If I can do something reasonably well and
simply, so much the better. I do not get stupid about it though which
is why I wanted to benchmark. That led tomy question.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      06-24-2011
On 6/23/2011 1:53 PM, Arved Sandstrom wrote:
> Don't mind me - the last few years I've been questioning dogma. All of
> it.


For what it's worth, I've spent the past few weeks starting to get
really tricky with python. I think I hit the apex when I realized I was
wanting a macro system in python, only shortly after writing functions
that returned functions. I think "good OO design" got thrown out the
window a while ago, although working in the same space as a bunch of
programming language interns is certainly going to mutate your sense of
good language design dogma.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Fuschia, President-Elect of the Bright Purplish-Green Council
Guest
Posts: n/a
 
      06-24-2011
On 23/06/2011 10:15 PM, Joshua Cranmer wrote:
> On 6/23/2011 1:53 PM, Arved Sandstrom wrote:
>> Don't mind me - the last few years I've been questioning dogma. All of
>> it.

>
> For what it's worth, I've spent the past few weeks starting to get
> really tricky with python. I think I hit the apex when I realized I was
> wanting a macro system in python, only shortly after writing functions
> that returned functions. I think "good OO design" got thrown out the
> window a while ago, although working in the same space as a bunch of
> programming language interns is certainly going to mutate your sense of
> good language design dogma.


Sounds like what you really want is a Lisp. Might I suggest Clojure?

 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      06-24-2011
On 06/24/2011 01:48 AM, Fuschia, President-Elect of the Bright
Purplish-Green Council wrote:
> On 23/06/2011 10:15 PM, Joshua Cranmer wrote:
>> On 6/23/2011 1:53 PM, Arved Sandstrom wrote:
>>> Don't mind me - the last few years I've been questioning dogma. All of
>>> it.

>>
>> For what it's worth, I've spent the past few weeks starting to get
>> really tricky with python. I think I hit the apex when I realized I was
>> wanting a macro system in python, only shortly after writing functions
>> that returned functions. I think "good OO design" got thrown out the
>> window a while ago, although working in the same space as a bunch of
>> programming language interns is certainly going to mutate your sense of
>> good language design dogma.

>
> Sounds like what you really want is a Lisp. Might I suggest Clojure?


Since it's not Java related, I don't want to dwell on it, but this
project has constraints which prohibit most languages. Python is pretty
much the only tenable language (legacy code being in python makes a big
difference, too ).

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a Method Name to a Method, Redux Gene Wirchenko Java 51 07-24-2011 10:02 AM
Passing method name to method? Arfon Smith Ruby 3 09-28-2007 03:38 PM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments