Follow us on Twitter!
The measure of a mans life is not how well he dies, but how well he lives.
Friday, April 25, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 17
Guests Online: 15
Members Online: 2

Registered Members: 82909
Newest Member: awais
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

OOP Advice

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Apprentice
Posted on 30-07-10 00:57
Hi guys,
I've wanted to take OOP on for a while now, but I just can't get my head around it. Procedural programming (for me) is a lot easier to understand, so I'd appreciate it if I could get some help/advice from someone more experienced Pfft

I've started my first PHP OOP project, which is a chart drawing script. I haven't completed the project, yet still I'd like to get some feedback before I continue.

The Scripts is supposed to do the following:

take in:
- chart name
- chart resolution
- X axis name
- Y axis name
- X and Y coordinates for 3 bars. (bar name and color will be added later)

display:
- chart logo, axis names and axis points
- 3 bars on top of the charts

Now I haven't started working on the bars yet, but I've managed to create a chart where the X and Y axis are drawn with 0 as starting point, and up to any user specific number on both X and Y axis.

a link to my project can be found here: http://www.demons. . ./index.php

OOP source can be found here:http://www.demons. . .iz/oop.rar

Procedural source: http://www.demons. . .edural.rar

both sources do almost the same thing, yet still the OOP was a bit longer (consisting of 2 files so far) and was a bit more confusing to write...

To get a proper charts drawn, you need to fill in at least X and Y coordinates for 1 bar so that the maximum axis length can be set.

The problem is that procedural programming is a bit forward, you program whatever you see come next. But the OOP mindset confuses me a little bit. I seem to use classes as containers for functions, which seems like a waste since I can get the same job done in less code when using non-OOP.

How do I reach the OOP full potential? Is there a certain way to think before constructing a program?

Thanks in advance?
base_dropper@hotmail.com www.demonshalo.com
Author

RE: OOP Advice

spyware
Member



Posts: 4192
Location:
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 30-07-10 01:19
Demons Halo wrote:
How do I reach the OOP full potential?


Shiiiiiiit.

No one knows.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
[center]�Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?� - Ebert[/ce
Author

RE: OOP Advice

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Apprentice
Posted on 30-07-10 01:25
spyware wrote:
Demons Halo wrote:
How do I reach the OOP full potential?


Shiiiiiiit.

No one knows.


I guess if you don't then it's true, no one knows :/
base_dropper@hotmail.com www.demonshalo.com
Author

RE: OOP Advice

spyware
Member



Posts: 4192
Location:
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 30-07-10 01:36
Demons Halo wrote:
I guess if you don't then it's true, no one knows :/


Wat.

No, look. OOP probably has it's uses in large-scale projects with many repetitive tasks. I just don't like it.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
[center]�Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?� - Ebert[/ce
Author

RE: OOP Advice

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Apprentice
Posted on 30-07-10 01:44
spyware wrote:
Demons Halo wrote:
I guess if you don't then it's true, no one knows :/


Wat.

No, look. OOP probably has it's uses in large-scale projects with many repetitive tasks. I just don't like it.


The problem is that everybody use it now a days. so if you dont understand it, it's freaking hard to follow up and understand the structure of the programs written by others!
base_dropper@hotmail.com www.demonshalo.com
Author

RE: OOP Advice

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 30-07-10 01:57
Object oriented programming makes much more sense in some situations compared to others. I wouldn't consider myself anywhere near "good" at understanding and using OOP, but I've met quite a few situations where it can be very useful. I've never looked at utilizing it in PHP, as I've always focused a bit more on python for OOP related stuff, but when you refer to a class just being a container for some functions, it can be a lot more than that. The class instances can also hold variables, which is what makes OOP very useful in that context.

A great example is, say you're building a network scanner.
The user wants to scan 192.168.0/24. Doesn't seem too hard, but say, we want to scan *every* port, and we want to keep information on each host. Examples of that information would be what it's DNS resolves to, the whois report, etc. As you can see, it would become a little difficult to manage all of that. With OOP it's as simple as creating a class that has the attributes (variables) ip, dns, whois, etc. Then you can make methods of that class that do things related to the class, such as LookupWhois, and Scan, rather than having it as a outside function. You then create 256 instances of that class, and boom, the scanner code got a lot simpler. This is also far more elegant and easy to understand, at least in my opinion.

Another great feature of it is inheritance. This makes working with libraries and large amounts of code amazingly easy. Each class you create can "subclass" another class. By doing that, all the methods and information are also pulled into your class, and then you just "overwrite" what you feel like.
For instance, in python, making a threaded application is as easy as:

Code
import threading
class mythread(threading.Thread):
        def run(self):
              while 1:
                    print "Hi"
instance = mythread()
instance.start()




We never created a start() method, but we call it, and we can because that was inherited by the threading.Thead class. That way, the programmer doesn't have to worry about any threading code or anything, because he basically just steals most of it and writes over the part he wants to do his way. That's much easier than the non-OOP way, imo.

The problem with all of OOP is it's really fucking complicated compared to non-OOP until you manage to wrap your head around it, but when you do it looks far simpler and way more elegant. So, I'll basically just sum up and tell you what I tell everyone else: If you *really* want a good understanding of OOP, go get a book, and spend lots of time thinking about where it would be really useful, and implement those ideas.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com
Author

RE: OOP Advice


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-07-10 02:32

The problem is that procedural programming is a bit forward, you program whatever you see come next. But the OOP mindset confuses me a little bit. I seem to use classes as containers for functions, which seems like a waste since I can get the same job done in less code when using non-OOP.

How do I reach the OOP full potential? Is there a certain way to think before constructing a program?


are we talking here about OOP or brain surgery

what is there to be confused about ?

you group some functions and structure/variables togethet and give that grupe a name and you have yourself a class, or im a living in a delusion ???
Author

RE: OOP Advice

Demons Halo
Member



Posts: 261
Location: Sweden
Joined: 26.03.09
Rank:
Apprentice
Posted on 30-07-10 13:50
stealth- wrote:
Object oriented programming makes much more sense in some situations compared to others. I wouldn't consider myself anywhere near "good" at understanding and using OOP, but I've met quite a few situations where it can be very useful. I've never looked at utilizing it in PHP, as I've always focused a bit more on python for OOP related stuff, but when you refer to a class just being a container for some functions, it can be a lot more than that. The class instances can also hold variables, which is what makes OOP very useful in that context.

A great example is, say you're building a network scanner.
The user wants to scan 192.168.0/24. Doesn't seem too hard, but say, we want to scan *every* port, and we want to keep information on each host. Examples of that information would be what it's DNS resolves to, the whois report, etc. As you can see, it would become a little difficult to manage all of that. With OOP it's as simple as creating a class that has the attributes (variables) ip, dns, whois, etc. Then you can make methods of that class that do things related to the class, such as LookupWhois, and Scan, rather than having it as a outside function. You then create 256 instances of that class, and boom, the scanner code got a lot simpler. This is also far more elegant and easy to understand, at least in my opinion.

Another great feature of it is inheritance. This makes working with libraries and large amounts of code amazingly easy. Each class you create can "subclass" another class. By doing that, all the methods and information are also pulled into your class, and then you just "overwrite" what you feel like.
For instance, in python, making a threaded application is as easy as:

Code
import threading
class mythread(threading.Thread):
        def run(self):
              while 1:
                    print "Hi"
instance = mythread()
instance.start()




We never created a start() method, but we call it, and we can because that was inherited by the threading.Thead class. That way, the programmer doesn't have to worry about any threading code or anything, because he basically just steals most of it and writes over the part he wants to do his way. That's much easier than the non-OOP way, imo.

The problem with all of OOP is it's really fucking complicated compared to non-OOP until you manage to wrap your head around it, but when you do it looks far simpler and way more elegant. So, I'll basically just sum up and tell you what I tell everyone else: If you *really* want a good understanding of OOP, go get a book, and spend lots of time thinking about where it would be really useful, and implement those ideas.


Thanks for the explanation =)
The scanner was indeed a good example of an oop project.
Now that I think about it, OOP will help me out when I'm about to create multiple bars for the charts. So I can create an instance for every bar and have its' info stored inside =D That way I can ignore using for loops!

I'll try it out. Thanks for the help =)
base_dropper@hotmail.com www.demonshalo.com
Author

RE: OOP Advice

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 30-07-10 20:53
Demons Halo wrote:
Thanks for the explanation =)
The scanner was indeed a good example of an oop project.
Now that I think about it, OOP will help me out when I'm about to create multiple bars for the charts. So I can create an instance for every bar and have its' info stored inside =D That way I can ignore using for loops!

I'll try it out. Thanks for the help =)


No problem, good luck with your project Smile

@mestar

It's kinda like database designing. It doesn't seem that complicated, but when you get into keys and weaving different tables and databases together, stuff gets a lot more advanced. Then people start writing books on the theory, how to best utilize it, the most elegant designs, etc. and all of the sudden database designing isn't so straightforward. At least that's how I look at it.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com