import java.io.*;
public class Pair implements Serializable {
public Object o1;
public Object o2;
public Pair(Object o1, Object o2) {
this.o1=o1;
this.o2=o2;
}
}
Here http://btrgame.com/dev/srconline.jsp are full the package.
import java.io.*;
public class Pair implements Serializable {
public Object o1;
public Object o2;
public Pair(Object o1, Object o2) {
this.o1=o1;
this.o2=o2;
}
}
Here http://btrgame.com/dev/srconline.jsp are full the package.
Uh… can you be more descriptive with this?
I thought it was pretty self-explanatory, but then again, I also have several years of training doing this java stuff
Well if I read the source he has attached I can figure it out, but I don’t see how his example is too indicative of anything.
Are you disagree that Pair is short and usefull class? How your method returns x and y for example? In array of doubles with 2 elements? Or you will write special class? Point2D. Look there at m.util package. Most usefull things for common deeds are there.
Demonpants (and I) just think your example is not a good indication of the scope of your utilities. So a descriptive summary about what can be found in your utilities would have been more insightfull than this code snippet.
Yes, exactly. I would expect something more along the lines of:
“This is a package of code which includes drawing functions, physics utilities, and geometric calculations for use with games in Java applets.”
public static final void printStackTrace() {
try {
throw new RuntimeException(“StackTraceGetter”);
} catch(Exception e) {
e.printStackTrace();
}
}
another one bites the dust…
hahaha
and what about
public static int max(int[] arr) {
int max=0;
for (int i=1; i<arr.length; i++) {
if (arr[i] > arr[max]) {
max=i;
}
}
return max;
}
public int getAnswerToLife() {
return 42;
}
;D
public static int max(int[] arr) {
int max=0;
for (int i=1; i<arr.length; i++) {
if (arr[i] > arr[max]) {
max=i;
}
}
return max;
}
this is like indexOfMax(…), not max(…)
further, it doesn’t handle the cornercase where arr.length==0 properly: it should return -1
[quote]indexOfMax(…)
[/quote]
furthermore, it’s rather firstIndexOfMax(…
Thanks for sharing your code. =)
Your initial post seems to indicate you’re sharing some kind of library for doing trivial things with fewer lines of code, but when visiting the site, it appears to be the source code for your game, Battery.
While some of the code could possibly be useful, it’s not really suitable as a library. The naming is confusing, so there’s no way of telling what’s where, which means it’s probably faster to write your own indexOfMax loop than to look through your code to see if you’ve written something like that already.
Many of the functions are totally pointless, sometimes entire classes are, and what’s even worse, sometimes they’re both pointless and WRONG.
For example:
public static final double angle(double x, double y) {
return Math.atan2(x, y);
}
That would be fine, except it’s easier to type Math.atan2(x, y) than m.util.U77.angle(x, y), and the fact that Math.atan2 takes y, x, not x, y.
Now, if you use angle() like atan() and pass y, x, you get the right results, but the code seems to indicate you should pass x first.
The code is ok, if a bit rough, and it’s interesting to see what solutions you’ve used in your game, but a good library of easy to use functions, it is not.
Markus, mathematicans could disagree with me but for me angle starts from zero on clocks and grows as hours or minutes…
with angle() method i get exactly what i want. tell me please more wrong methods and classes.
Actually, I can’t find anything else that’s outright wrong, so I apologize for implying there are more errors. Sorry.
About atan2: If it works for your project, then it’s great. I myself also use Math.atan2(x, y) in my projects, but I also always get sin and cos mixed up.
I just meant for a library, it’s probably a good idea to pay very close attention to the standards. =)
Some minor feedback:
You should move all packages from m.* to com.btrgame.. It’s not insanely important, but if several people make libraries in the m. package, things will get confusing, that’s why there’s a package name standard.
Catching compile time errors and throwing runtime errors instead is… well… Some people think it’s valid style, but I strongly disagree. It’s much better than empty catch blocks, though.
What’s worse, often you catch Exception and just return false or null… that will lead to bugs as it forces the people who use your code to do manual error checking, or just get silent failures. Failures should be LOUD.
m.util.File77.copy(String, String) is very, very slow as it reads and writes a single byte at a time.
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead= 0;
while ((bytesRead=in.read(buffer))!=-1)
out.write(buffer, 0, bytesRead);
m.util.File77.delete(String) is dangerous as all hell.
m.util.U77.repeat(String, int) is very slow. “res += s” is the same as “StringBuffer tmp = new StringBuffer(res); tmp.append(s); res = tmp.toString();”
This probably will never matter in your game, but if someone writes something that relies on it, I’m sure they’d appreciate it if it was faster:
StringBuffer res=new StringBuffer();
for (int i=0; i<count; i++) res.append(s);
return res.toString();
Thanks, Markus.
Have you got my mail?
Yes, I did. Unfortunately, I can’t seem to send any emails any more, so I can’t reply.
I don’t have enough free time to join a project right now, what little time I’ve got, I spend on my own silly projects and on gaming (gta4 and tf2, baby!)
Tf2==Turtles Fighter 2? <- i love this unhealthy smile
Team Fortress 2 i imagine