[ajug-members] convert program
Wilson, Jeff
jw9615 at att.com
Mon Sep 22 09:34:32 EDT 2008
As a generalization, I think the difference between most programs that
can benefit from an OO approach versus those that don't, is state. If
you have to manage more than trivial state in your app, OO may help it.
If you're just doing algorithms, OO won't help.
+jeff (MJW)
---
"Love is a snowmobile racing across the tundra and then suddenly it
flips over, pinning you underneath. At night, the ice weasels come."
-- M. Groening
---------------------------------------------
M. Jeff Wilson, Lead Member Technical Staff
AT&T Services, Inc.
Operations & Service Dev
jw9615 at att.com
+1 404.499.7235
-----Original Message-----
From: Chris Fowler [mailto:cfowler at outpostsentinel.com]
Sent: Friday, September 19, 2008 7:41 PM
To: ajug-members at ajug.org
Subject: Re: [ajug-members] convert program
Wilson, Jeff wrote:
>
> If you're just doing algorithmic work, you may not need OOP. I took a
> look at the tow pond code you sent me last week, and there's really no
> reason to have an object at all for that. But that's not really Java.
> To get any advantages of an OO language, you're problem space needs to
> be a little more complex than that.
>
Correct, the problem does not lend itself to OOP.
I had a problem today that would fit well. I am looking for a Linux
programmer with network programming experience.
I got a resume and decided that to really know how much UNIX and network
programming this person could do, I would device a short test.
The test I created was to write a network server that users could telnet
to and chat. Program could be written in 30 minutes or less in Perl or C
only.
to prove it could be done, I started and completed in about 20 minutes
with interruptions from AIM, email and desk phone. It worked but with 10
minutes more one could add logging and IP address header to all messages
so we know who is talking.
I asked one of my engineers to telnet to my desktop to test it and he
commented that he would like to see a nick instead of an address. I
stated that I simply used getpeername() on the socket to get the address
and all I stored was an array of sockets. To really do something like
that I would need to store more information about the client.
So this is where OOP would work. I need to create an object for each
client that includes the socket, mode, and possibly even a chat room
name. As I'm processing messages from clients I can then use that
information to route messages correctly.
Here is some pseudo/java code :)
public class client {
private Socket _sock = null;
private int mode = 0;
public client(Socket sock)
this._sock = sock;
mode = 1; // Not in room yet
}
public string get_Address() {
return peername;
}
public void write(String txt) throws Exception {
write socket;
}
....
}
Anyway. In my test, to get it done fast, I programmed in Perl. Perl
supports OOP so I can easily create objects just for the clients.
An array of file descriptors was perfect until I decided the program
needed
to be extended. For the 30 minute test, objects and complexity like this
would
take too long.
> +jeff (MJW)
>
> ---
>
> "Without question, the greatest invention in the history of mankind is
> beer. The wheel does not go nearly as well with pizza."
>
> -- Dave Barry
>
> ---------------------------------------------
>
> M. Jeff Wilson, Lead Member Technical Staff
>
> AT&T Services, Inc.
>
> Operations & Service Dev
>
> jw9615 at att.com
>
> +1 404.499.7235
>
> *From:* 521 [mailto:521 at ofig.org]
> *Sent:* Friday, September 19, 2008 3:52 PM
> *To:* ajug-members at ajug.org
> *Subject:* [ajug-members] convert program
>
> i want to use oop correctly...
>
> i want to take input as a csv of doubles named heights,
> 1.3,3.4,7.6,8.2,5.3,3.2,0.32
>
> then take another csv of doubles named distances,
> 0.0,25.2,50.1,75.3,100.1,125.5,150.3
>
> do some math (get some areas/volumes/etc);
>
> then give back an area/volume/etc
>
> in order for me to not just use static-methods from various classes;
> how can i program this using oop; a user here last week or so told me
> that Java is not made this way; and i understand why he said that...
> (here is the php version i made years ago: *http://tinyurl.com/4bnt4a*
>
> barclay
>
>
------------------------------------------------------------------------
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>
--
Chris Fowler
OutPost Sentinel, LLC
Support @ SIP/support at pbx.opsdc.com
or 678-804-8193
Email Support @ support at outpostsentinel.com
_______________________________________________
ajug-members mailing list
ajug-members at ajug.org
http://www.ajug.org/mailman/listinfo/ajug-members
More information about the ajug-members
mailing list