Archived

This topic is now archived and is closed to further replies.

MSW

Is there something wrong with me?

Recommended Posts

MSW    151
I''ve been programing for the better part of the last 20 some years...everything from COBOL, FORTRAN, Pascal, Basic, C, even some x86 assembler...I''ve made tons of 2D graphical applications...from sprite/tile editors, to side scrolling style games...I''ve even started a software rendered 3D version of the original NES Legend of Zelda several years ago in DOS (I stopped because I kept hitting the 640k memory limit, and wanted to keep from useing a memory manager as part of the challange)...I''ve written file format converters and loaders to Duke 3D ''cell-shadeing" rendering engines...I''m no programming god (not by a LONG shot)...but I''ve "been around the block" If you know what I meen. But for the life of me, I can''t get a handle on this Object Oriented stuff...It seems so abstract, that I can hardly make any sense of it...and those rare times that I do, it just seems rather silly (for example in the beginners form there is a post titled "general OO question" about units in a RTS game...I can think of tons of different ways to do that without useing OO ) I''m not trying to start a flame war or anything...I''m just wondering if I''m ''wired'' wrong...or if there are others like me who just don''t understand OO?

Share this post


Link to post
Share on other sites
civguy    308
You''d probably understand OO easily if you gave it a good try sometime . With a help of a good book preferably. A few years ago it sounded a little too abstract to me too so it took me a while until I even wanted to learn it.. At first I learned OO simply as "classes are structs that have functions which operate on it''s data". Hehe. Well, that''s what it really is on the least abstract level. But then I gradually learned about data hiding, inheritance and polymorphism, and it started making sense more and more. You''re not supposed to just jump into OO. You start with basics, make a few programs with ''simple'' OO, and move on to ''harder'' stuff when you can handle the basics.

Share this post


Link to post
Share on other sites
petewood    819
no, there's nothing wrong with you.

i used to imagine there was a big secret, that i just didn't 'get it' because there was something wrong with me.

it is quite likely that ways you have already programmed exhibit different aspects of object oriented design. object oriented programming makes use of the language specific features to implement object oriented design.

if you have an api in c then that is an abstraction. you can change the implementation behind the api and people using it will be none the wiser (espscially if you don't increase the version number (c: )

oop and ood encourage you to be aware of these abstractions and understand how to better use them in a complex system.

making use of oop language features also makes it possible to represent data with a consistent interface attached to it. this makes it possible to enforce correct manipulation of a unit of data. this has always been possible with c as well through an api and data handles. c++ (or java or ruby) just keeps it all in one place for you. the data cannot be manipulated any other way (if that's what you want) this is all known as encapsulation.

using inheritance means you can extend your datatypes without having to reinvent the wheel everytime, without having to recode the api to manipulate the new data type.

you can also manipulate all your new, extended data types in a consistent way. so if you have a FileIO class or a derived CompressedFileIO class or a DebugLoggedFileIO class then they'll all behave in a consistent way and you can swap them seamlessly.

these are just the main points really. but, hopefully, you can see that it's really to do with consistent interfaces to data.

there are many issues to do with design and understanding the interdependance of the interfaces. one book, which is the classic standard book that everyone should read, is 'design patterns' by gamma et al. it is very abstract and took me a long long time (a couple of years) before i really started to value it.

i've just started learning ruby which is an object oriented language. there is a complete book on this website. if you set up your web browser to download for offline browsing it's quite a good read.

peace

[edited by - petewood on October 21, 2002 4:54:46 AM]

Share this post


Link to post
Share on other sites
Advanced Bug    122
quote:
Original post by MSW

I''m not trying to start a flame war or anything...I''m just wondering if I''m ''wired'' wrong...or if there are others like me who just don''t understand OO?





I''m in a similar situation. I learned C++ (and all that OOP stuff) few years ago. But since every time I used OOP it end up with a huge mess, I switched back to procedural programming.

I think there are two major problems with OOP:

1. If you follow all OOP design guidelines (public accessor functions for all private fields, catching and re-throwing exceptions in each class, writing a wrapper for everything) you get a code that is about 10 times the size of equivalent procedural code.

2. Effective use of polymorphism is not possible in language that doesn''t use garbage collection because it leads to very complex memory management issues.

In the newest languages like Java and C# some of those problems are solved, but I''m sure it will be a long time until OOP will be really usable.

Share this post


Link to post
Share on other sites
Darrell L    122
I, like you, have been around the block more times than I care to think. And I also had problems when I started my first OO app. Looking at that code today still makes me wince.

Several apps/years later it occured to me that maybe my perspective was wrong. I was so function-centric with the other paradigms (ughh, sorry).

To me, OO has become more about the data and the functions used to manipulate that data, than about the functions themselves. I used to sit down and design a set of functions for say, a tile-based game. You got your blitting and your animating and your moving and your collision detection and your yada-yada-yada. Now I look at it as: a tile, a level, a gameboard, a sprite, a player, etc., and then look at what functions are necessary to support those pieces of data. In Information Engineering theory they call this parallel decomposition.

Don''t get me wrong, I still have that lowest level of abstraction which I consider to be akin to my old functional-based approach, e.g., a bitmap or window class. But now I have many layers of abstraction from which to choose from to begin the design, instead of just the one low level one I used to have.

It''s worth the effort to gain an understanding if you want to expand your code reuse. Try something simple, like maybe a game of Solitaire, and see where it takes you when looking at the data structures first.

Share this post


Link to post
Share on other sites
Arild Fines    968
quote:
Original post by Advanced Bug
1. If you follow all OOP design guidelines (public accessor functions for all private fields,


There is no such guideline. Most of the private fields should not be visible to the outside at all. The fewer accessors you have, the more OO it is.
quote:

catching and re-throwing exceptions in each class,


Huh?
quote:

writing a wrapper for everything)


Huh?
quote:

you get a code that is about 10 times the size of equivalent procedural code.


Hogswash!




The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. - Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)

Share this post


Link to post
Share on other sites
Beer Hunter    712
quote:
Original post by Advanced Bug
2. Effective use of polymorphism is not possible in language that doesn''t use garbage collection because it leads to very complex memory management issues.
std::auto_ptr, boost::shared_ptr, ...

Share this post


Link to post
Share on other sites
Arild Fines    968
For the OP - try reading this Design Patterns - Elements of Reusable Object-Oriented Software[1]. It was the book that made me ''get'' OO.

[1]http://www.amazon.com/exec/obidos/tg/detail/-/0201633612/qid=1035192823/sr=8-2/ref=sr_8_2/002-4934260-3764802?v=glance&n=507846



Faith.n. Belief without evidence in what is told by one who speaks without knowledge, of things without parallel.Ambrose Bierce

Share this post


Link to post
Share on other sites
Advanced Bug    122
I just love OOP. It allows you to write soooooo compact programs . For example:



  
class Rectangle
{
public:
Rectangle(int x, int y, int width, int height)
: _x(x), _y(y), _width(width), _height(height)
{}
Rectangle(const Rectangle &other)
: _x(other._x), _y(other._y), _width(other._width), _height(other._height)
{}
const Rectangle &operator= (const Rectangle &other)
{
_x = other._x;
_y = other._y;
_width = other._width;
_height = other._height;
return *this;
}
void SetX(int x)
{
_x = x;
}
int GetX()
{
return _x;
}
void SetY(int y)
{
_y = y;
}
int GetY()
{
return _y;
}
void SetWidth(int width)
{
_width = width;
}
int GetWidth()
{
return _width;
}
void SetHeight(int height)
{
_height = height;
}
int GetHeight()
{
return _height;
}
private:
int _x;
int _y;
int _width;
int _height;
};



Cool, isn''t it. 50+ lines of code for such simple thing.

Share this post


Link to post
Share on other sites
MadKeithV    992
quote:
Original post by Advanced Bug
I just love OOP. It allows you to write soooooo compact programs . For example:
(code snipped)
Cool, isn''t it. 50+ lines of code for such simple thing.




Get/Set pairs on all your private data?

*stifled laughing*


Share this post


Link to post
Share on other sites
CaptainJester    523
MSW: Don''t worry about it. OOP can be confusing at first. Especially if you come from a procedural background. Just keep at it and it will come to you. For those things that don''t make sense, you can try to get by without a complete understanding of them and come back to them later when you have learned more concepts, then they may make more sense.


quote:
Original post by Advanced Bug
I just love OOP. It allows you to write soooooo compact programs . For example:

Cool, isn''t it. 50+ lines of code for such simple thing.

If that is all you think OOP is, then your as clueless as SabreMan says you are.

quote:
Original post by Advanced Bug
catching and re-throwing exceptions in each class


Since when is this part of OOP? It may be included in some langauages, but is not part of the definition of OOP.

quote:
Original post by Advanced Bug
Effective use of polymorphism is not possible in language that doesn''t use garbage collection because it leads to very complex memory management issues.


Rectangle *myRect=new Rectangle(0,0,10,20);
myRect->draw();
delete myRect;

Oh my god that was confusing. Ever hear of constructors/destructors? Properly built, OOP makes memory management easier than ever.

Maybe you should learn the concepts before you start bashing them.



Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
SabreMan    504
quote:
Original post by Advanced Bug
Rectangle, which coordinates you cannot read/set?

Bogus hypothetical example removed from real-world scenario?

Share this post


Link to post
Share on other sites
Alpha_ProgDes    6921
MSW.
i myself am having a hard time with the OO paradigm.
C++ does make it easy, at least to set up a simple object.
For me, some of the syntax is confusing and can be a hassle.
But of course, I'm starting out so that's to be expected.
As you can see from this attempt, I am having a hard time with it. Thankfully that's just a preliminary version but nonetheless I gonna keep at it until I get it right (or as close to it as possible).

So ask Fruny, Dr.Pizza, Sabreman or even Petewood (my new friend ) for a suggestion on what book to go through.

But i do know one thing, OOP is not the end all to programming

[edited by - Alpha_ProgDes on October 21, 2002 8:10:47 AM]

Share this post


Link to post
Share on other sites
petewood    819
class SomeoneElsesRectangle {
public:
SomeoneElsesRectangle(Point topRight, Point bottomLeft);
Point GetTopRight();
Point GetBottomLeft();
}

class MoreAppropriateRectangle {
SomeoneElsesRectangle rect_; // private representation
public:
Length GetWidth();
Length GetHeight();
Point GetAnchor();
}


i won't bother with the implementation but even with this very simple, not-really-what-oop-is-all-about example, you can see the usefulness of encapsulation

hi alpha! yes everyone, we're friends now (c:

[edited by - petewood on October 21, 2002 8:19:54 AM]

Share this post


Link to post
Share on other sites
Advanced Bug    122
quote:
Original post by petewood
class SomeoneElsesRectangle {
public:
SomeoneElsesRectangle(Point topRight, Point bottomLeft);
Point GetTopRight();
Point GetBottomLeft();
}




No this design is absolutely wrong!!! This way you cannot subclass the Point class, and then subclass the Rectangle class to return subclassed Point class. Here is better design:

  
class Point
{
public:
Point(int x, int y) {}
virtual void Draw();
};


class SubclassedPoint : public Point
{
public:
SubclassedPoint(int x, int y)
: Point(x, y)
{}
void Draw(); // Override the Draw() method

};


class Rectangle {
public:
Rectangle(Point topRight, Point bottomLeft);
virtual std::auto_ptr<Point> GetTopRight();
private:
Point _topRight;
Point _bottomLeft;
};


class SubclassedRectangle : public Rectangle
{
public:
SubclassedRectangle(Point topRight, Point bottomLeft)
: Rectangle(topRight, bottomLeft)
{}
std::auto_ptr<Point> GetTopRight()
{
// Don''t try to understand what is going on in this line

// How copy constructors are called, and in what order?

return new SubclassedPoint(*GetTopRight());
}
};

SubclassedRectangle rect(Point(0, 0), Point(10, 10));
rect.GetTopRight()->Draw();



I''m making progress - instead of 50 lines of code for a simple rectangle, now I can write 50 lines of absolutely unreadable code.

BTW, why doesn''t it compile?

Share this post


Link to post
Share on other sites
CPeX    122
http://www.drcaffeine.com/

its a realy good book to get the concepts.

The only problem is that it is written for people who haven''t programmed before. do it procede slowly

Share this post


Link to post
Share on other sites
Advanced Bug    122
quote:
Original post by SabreMan
Original post by Advanced Bug
BTW, why doesn't it compile?
Because you don't have a clue what you are doing.


No way! I'm trying to return auto_ptr constructed from pointer which is a result of calling operator new which calls copy constructor of class SubclassedPoint passing as parameter a pointer returned from overloaded * operator of another auto_ptr obtained by calling overriden virtual function, where the second auto_ptr in constructed from pointer obtained by call to new operator which calls copy contructor of class point specifing a _topRight field as an argument.

Yeah, if all OOP could be so simple

[edited by - Advanced Bug on October 21, 2002 9:17:24 AM]

Share this post


Link to post
Share on other sites
Advanced Bug    122
BTW,
here
is an example, how using OOP methods can increase code size 4 times. (see chapter 3. DETAILS SHOULD DEPEND UPON ABSTRACTIONS. ABSTRACTIONS SHOULD NOT DEPEND UPON DETAILS. (PRINCIPLE OF DEPENDENCY INVERSION). The original procedural code example is 16 line of code, the OOP code - 60.

Share this post


Link to post
Share on other sites