PDA

View Full Version : kernel info


inkedmn
09-22-2002, 10:15 PM
hacked this badboy out a couple nights ago.

it works, but i'd still like to know if it looks okay to everyone...


import java.net.*;
import java.io.*;

public class GetKernel {
public static void main(String[] args) {
String server = "kernel.org";
Socket sock;
BufferedReader in;
char[] stuff = new char[710];
try {
sock = new Socket(server, 79);
sock.getOutputStream().write('\n');
in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
in.read(stuff, 0, 710);
sock.close();
System.out.println(stuff);
} catch (IOException e) {
System.out.println(e);
System.exit(1); }
}
}

Strike
09-23-2002, 01:17 PM
Just out of curiosity, why the hardcoded 710? What significance is that number?

inkedmn
09-23-2002, 02:09 PM
that's the number of bytes that are sent from kernel.org.

bwkaz
09-23-2002, 02:24 PM
Always? What happens when 2.10.10 gets released? Wouldn't that require an extra byte over and above the 710 limit?

Or what happens if they start reporting another patch set, like the -dj patchset which just came up not all that long ago?

inkedmn
09-23-2002, 02:34 PM
then i'll make it 711... :rolleyes:

kmj
09-23-2002, 03:39 PM
inkedmn: his point is that you should make it a const variable, and use that variable. That way, when you need to change it, you only change it in one spot. Using integer literals throughout your code is considered bad style especially when the same value is used more than once.

inkedmn
09-23-2002, 03:41 PM
i didn't get that from his post at all, but thanks for the input

kmj
09-23-2002, 04:48 PM
oh, well, anyway, DO THAT!!!! :)

or don't. Here it doesn't matter, but if you did it like this in a real project, it'd get quite messy and unmaintainable.

inkedmn
09-23-2002, 05:01 PM
i understand that, but being a java n00b, i'm comfortable with making n00b mistakes :)

thanks again for the input :)

Strike
09-23-2002, 06:48 PM
That's not really a Java newbie mistake as much as a general programming newbie mistake. Hardcoded numbers in code are almost never good (with a few exceptions, like starting at 0 while iterating through loops and such). Symbolic constants are always much easier to read, and since they are defined once and used many times, they are much easier to change as well.

inkedmn
09-23-2002, 07:15 PM
i see your point...