Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: Ryan Marcus on September 22, 2005, 09:33:59 pm

Title: Code/Interface Seperation
Post by: Ryan Marcus on September 22, 2005, 09:33:59 pm
Alright, I have a question for all you people who know what your doing...

... Do you believe in separating your code from your interface?

By this I mean a series of classes that make functions more and more specific.. As in a PacketSocket class to a RawData socket, to a bnetsocket, or a ShellSocket to a ShellFunctionClass. (When I say class, I mean a class. Not a fake VB module.) I do because I like reusing code, and I quickly make a change at the base of similar classes without changing each one...

Others argue that coding "right in the UI" is easier, faster, and better because you can customize your code... I would rather have a "Whisper" event then have to parse the packet right there in the UI..


Thoughts? Comments? Ideas? Questions? Sandwiches?
Title: Re: Code/Interface Seperation
Post by: Sidoh on September 22, 2005, 09:36:28 pm
Alright, I have a question for all you people who know what your doing...

... Do you believe in separating your code from your interface?

By this I mean a series of classes that make functions more and more specific.. As in a PacketSocket class to a RawData socket, to a bnetsocket, or a ShellSocket to a ShellFunctionClass. (When I say class, I mean a class. Not a fake VB module.) I do because I like reusing code, and I quickly make a change at the base of similar classes without changing each one...

Others argue that coding "right in the UI" is easier, faster, and better because you can customize your code... I would rather have a "Whisper" event then have to parse the packet right there in the UI..

Organization is Godly.



Sandwiches?
Great idea!  I'll be back in a few minutes.
Title: Re: Code/Interface Seperation
Post by: rabbit on September 22, 2005, 09:42:31 pm
VB has classes.  Don't assume things.
Title: Re: Code/Interface Seperation
Post by: Ryan Marcus on September 22, 2005, 09:45:28 pm
I knew that... I met that using modules did not count as separation.
Title: Re: Code/Interface Seperation
Post by: MyndFyre on September 22, 2005, 11:23:12 pm
VB has classes.  Don't assume things.

VB has classes, but not class, and is not object-oriented.
Title: Re: Code/Interface Seperation
Post by: Warrior on September 24, 2005, 10:57:06 am
Alright, I have a question for all you people who know what your doing...

... Do you believe in separating your code from your interface?

By this I mean a series of classes that make functions more and more specific.. As in a PacketSocket class to a RawData socket, to a bnetsocket, or a ShellSocket to a ShellFunctionClass. (When I say class, I mean a class. Not a fake VB module.) I do because I like reusing code, and I quickly make a change at the base of similar classes without changing each one...

Others argue that coding "right in the UI" is easier, faster, and better because you can customize your code... I would rather have a "Whisper" event then have to parse the packet right there in the UI..


Thoughts? Comments? Ideas? Questions? Sandwiches?

Well coding (in VB) I seperate all code which is reuseable into a class module and static code as in code that does things that need no abstraction (like conversions, and other simple things) go in regular modules.

Now in PHP I make all of my bulk functions in a single file or if I'm programming OOP I make them a bunch of classes which extend the core. To display the UI it would pass through the template handler then the feed from each page which would then write to the page itself.

Title: Re: Code/Interface Seperation
Post by: Sidoh on September 24, 2005, 01:22:59 pm
Now in PHP I make all of my bulk functions in a single file or if I'm programming OOP I make them a bunch of classes which extend the core. To display the UI it would pass through the template handler then the feed from each page which would then write to the page itself.
That's a rather common technique.
Title: Re: Code/Interface Seperation
Post by: iago on September 24, 2005, 05:22:57 pm
Separating interface and processing is one of the basic things you learn that you have to do if you want to program anything that's a reasonable size.  Visual Basic is very hard to do that in, it greatly encourages mixing up interface/processing. 

When you program a project, think about this: if you wanted to change it to a console interface, or remote interface, or a different graphical interface, how much code would you be replacing? If you would have to replace code that has nothing to do with the interface, then you have a problem. 
Title: Re: Code/Interface Seperation
Post by: Ryan Marcus on September 24, 2005, 05:34:06 pm
Separating interface and processing is one of the basic things you learn that you have to do if you want to program anything that's a reasonable size.  Visual Basic is very hard to do that in, it greatly encourages mixing up interface/processing. 

When you program a project, think about this: if you wanted to change it to a console interface, or remote interface, or a different graphical interface, how much code would you be replacing? If you would have to replace code that has nothing to do with the interface, then you have a problem. 

Amen.
Title: Re: Code/Interface Seperation
Post by: Warrior on September 26, 2005, 03:21:29 pm
Exactly, having all of the essential code wrapped around other functions which the UI can call fourth would make switching whatever UI you use a snap. :)
Title: Re: Code/Interface Seperation
Post by: Tuberload on September 26, 2005, 03:30:50 pm
And Object Oriented Programming was born.
Title: Re: Code/Interface Seperation
Post by: Warrior on September 26, 2005, 03:34:13 pm
Hello world.
Title: Re: Code/Interface Seperation
Post by: Ryan Marcus on September 27, 2005, 07:16:46 pm

Neither my tech teacher or I think that putting code into a module counts as UI separation.

It really ticks me off when I look at converted VB source code and they have all of there controls (PushButtons, Sockets, etc.) "forward" to a module, and then that module calls that socket DIRECTLY.

I was talking to the guy that wrote MikeBot, first complaining that there where swear words in his comments, and we started discussing programming. His idea of UI and code separation was to have modules do all the "processing".

NO NO NO NO!

Correct me if I am wrong, but to correct way to do things involves a class hierarchy. For example, you would have a class called PacketSocket, which would use other classes such as PacketBuilder and PacketBuffer to pass a packet in an event. Then, you could create 2 sub-classes, rawbnetsocket, and rawbnlssocket. There, you handle all the connection information. For example, in the BNLS socket, you would have a method called "SendCDKey" which would trigger an event that included (or just returned) the hashed CDKey. Then you could sub-class rawbnetsocket to have methods such as Whisper, SayText, etc.

So many people use the module method, I figure there has got to be a reason, but I just can't find one!
Title: Re: Code/Interface Seperation
Post by: Warrior on September 28, 2005, 03:55:52 pm
Exactly. Have a core bot class which then invokes independant socket classes and stuff.
Title: Re: Code/Interface Seperation
Post by: rabbit on September 29, 2005, 06:59:46 pm
In my most recent bot (not released or even working quite yet), I've gone through painful lengths to class just about everything.  I even control the form from a main class.  I've broken it down a lot farther than I ever have, but I doubt I will even finish this thing.
Title: Re: Code/Interface Seperation
Post by: Tuberload on October 01, 2005, 01:03:40 pm
If you are truely interested in seperating your core system code from the interface code then why not move AWAY from VB and start using a language that actualy encourages the seperation in the first place?
Title: Re: Code/Interface Seperation
Post by: Warrior on October 01, 2005, 01:06:51 pm
I doub't he's willing to switch from a language he's written almost a complete bot in, just looking for programming tips to code better through the seperation of code an interface which through a lot of work can be acomplished in VB and most likely RB as well.
Title: Re: Code/Interface Seperation
Post by: Ryan Marcus on October 01, 2005, 06:48:17 pm
I am not using VB.. Die first.

I am using REALbasic, which does encourage code/interface separation.
Title: Re: Code/Interface Seperation
Post by: Tuberload on October 02, 2005, 02:59:32 pm
Easy kids, easy. I am just curious to know why you aren't trying to learn a language that is actually worthwhile. I don't need your reasoning for why you persist to limit yourselves.

Oh, and the excuse "because I programmed a whole bot in it" is a bad one... I have programmed complete bots in multiple languages, and finally settled for a language I like. Broaden your horizons a bit.
Title: Re: Code/Interface Seperation
Post by: Ryan Marcus on October 02, 2005, 03:04:57 pm
I'm learning Java.

REALbasic is not at all limited.
Title: Re: Code/Interface Seperation
Post by: Tuberload on October 02, 2005, 03:35:14 pm
I'm learning Java.

REALbasic is not at all limited.

I hope your learning experience is a good one.