[java] The best way to call methods

Started by
14 comments, last by moregames 23 years, 5 months ago
No, as stated in the first reply I made:

For single keystroke commands:
Use the Command interface with execute().

For multistroke commands (Ie. like the console in quake):
Use Tries (or Patricia trees?) finite state machines or even build a real parser. Tries are best for simple commands with no parameters.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Advertisement
Sorry for being such a newbie... what is Tries? Treemaps? I can''t seem to find Tries in any of my java books. And Patricia Trees as well where can I read about those.
What about baseing a consone on python or other scripting languages that compile nativly to java as well as having the ability to evaluate new code on the fly. Seems like a good compromise to me.

import org.python.util.PythonInterpreter;
import org.python.core.*;

public class SimpleEmbedded {
public static void main(String []args)
throws PyException
{
PythonInterpreter interp =
new PythonInterpreter();

System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");

interp.set("a", new PyInteger(42));
interp.exec("print a");
interp.exec("x = 2+2");
PyObject x = interp.get("x");

System.out.println("x: "+x);
System.out.println("Goodbye, cruel world");
}
}

moregames, ignore that Python posting. That is not what you need.

Tries is an abstract datastructure. It is not specific to any specific programming language, but is a structure like lists and maps. List and maps happens already to be implemented in the Java standard library for your convienience but a lot of other structures also exist. One of the goals of programming is to find the structure that best solves the question at hand.

If you want a good introduction to various data structures and algorithms the feature book on the gamedev.net main page at the moment:

Cormen, Leiserson & Rivest: Introduction To Algorithms

is serious and very recommendable. (I just looked Trie up in it, and it don''t seem to be listed, though)

On the net you can find a description of tries at
http://www.links.nectec.or.th/~thep/datrie/datrie.html
(for C, but you should be able to understand it)

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
quote:
If that was the case then the use of a hash map is not ideal. The use of a Trie is much better and more efficient.


I''m sure it would, but bugger me if I''m going to define one in the reply to a board

quote:Original post by felonius
And besides using Java reflection is really slow and should be avoided at all costs, besides it is generally bad style if not aboslutely essential for the purpose. The use of interfaces and virtual methods should be preferred any day.



Arse! Its worse to hard code commands to methods.
quote:Original post by bobbin
Arse! Its worse to hard code commands to methods.


Hmm, you do have a point, bobbin. Point taken.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games

This topic is closed to new replies.

Advertisement