Archived

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

null_pointer

Technical side of C++ OOP

Recommended Posts

(This is a touchy topic, so I want to make my purpose clear first -- I apologize if this sounds rude, but I don't want people ruining the topic) First off, I want to ask the forum moderator to PLEASE delete any replies or parts of replies that put forth opinions obviously meant as flame-bait. I want a purely technical, mature discussion on this topic. Please, if you don't know enough to answer my questions here, just come back to it tomorrow and someone will have posted an answer. (Whew! what you gotta do to keep posts on topic...) There are a couple of questions I am going to list, and I'd like to know whether it is actually faster for both development AND run-time (and, of course, possible ) to do some things in OOP or not. Basically, I'm trying to do something along the concept of plugins for C++. Question 1 - Dynamically linking classes in DLLs Here's what I do: create an abstract class in a static DLL, then take the generated .lib and .h files and include them in the dynamic DLLs. In the dynamic DLLs, I derive my own classes from the abstract class, and build them. In the dynamic DLLs, I create a standard function using C linkage that returns a pointer to the abstract base class. Then, from the static DLL, I can enumerate the dynamic DLLs and chose one at run-time. Will whis work? People complain about virtual functions, but in this instance, isn't getting the dynamic address of a lot of functions (the typical method) exactly what using the abstract base class does? Also, does nearly every platform have a "DLL" type code module, and do they allow me to get the address of a "C" function from that module at run-time? Question 2 - Possibility of cross-platform development Basically, I started building a simple API for games, but decided that as I added more and more it was becoming a full-blown VM. I have written a lot of interfaces describing how things work (like, a ton), and I have what I think to be the best system of classes out there. It derives all of its platform specific code through several dynamically-linked "DLL" type files called drivers, while keeping the ANSI C++ stuff in the main, static DLL that programmers will use. I (obviously) don't know enough to code 100% perfect code for everything game-related on every platform, but I know enough about how games work to code quite a bit of the standard. How flexible should I be with the first "wave" of driver-developers for my VM (see below)? Should I allow them to change anything? I realize the abundance of opinions on OOP design, but I want to know if my standard is logical...I guess I can't expect an answer to that if I can't post my source, huh? Well, maybe later. How much do you think I should build before finding people to start on the drivers? Is this technically feasible? If so, can you give me an objective answer as to whether or not I would find people willing to develop drivers for each platform? The idea is that the end programmer's source is exactly the same on different platforms. If all these things are true, it may well be the biggest game API out there. Question 3 - Coding standards This one may seem subjective, but I only want to know 3 things: whether many workplaces typically use Hungarian Notation, whether there are other standards (for prefixes), and exactly how well-liked the Hungarian Notation system (and any other standards) is/are. Question 4 - Sites about OOP theory and design Can you recommend any sites that talk about theory and basic principles (preferrably in C++)? I need to draft a standard of principles governing the building of the drivers -- what I will allow and what I don't allow from developers. If you read this far, thanks I've had this idea ever since I started programming and I'm slightly paranoid about someone stealing it.
- null_pointer Sabre Multimedia Edited by - null_pointer on 4/9/00 7:45:04 AM

Share this post


Link to post
Share on other sites
1. Should work. Give it a try. As for overhead, it''s no more overhead than you''d get from doing the equivalent construct in C (i.e. seeing if your structure overloaded a particular function and calling the function).

2. Don''t re-invent the wheel. There are bags of cross-platform frameworks out there, and a lot of ''em work better than the one you''re wanting to write. Start here.

3. [dons flameproof suit] I''ve never seen a non-trivial project implement hungarian notation completely and successfully. They inevitably end up watering the notation down to a dozen common one or two-letter prefixes. IMHO, the scope-resolution and type-overloading of C++ should have killed off Hungarian ten years ago. Furthermore, C++ muddles Hungarian horribly --since much of C++ involves creating new data types on top of the dozen or so intrinsic types built into C, you either have to follow the standard and create new Hungarian prefixes for each class or you have to depart from the standard and do something like making "c" the prefix for all classes you create --which basically renders it useless.

IMHO, Hungarian was a clever way for programmers to be able to work around the weak C type-checking. C++ has much much stronger type checking, and being able to scan your code for types that don''t jive isn''t much necessary when the compiler''s already doing it for you.

4. Buy Object Oriented Analysis and Design by Grady Booch.

As for stealing your idea, I must''ve missed it. What was your idea?

Share this post


Link to post
Share on other sites
johnhattan: For number 2, I tried that website but didn''t see anything for games -- those were for business apps and GUIs. I still think that what I have is good enough, if only to learn quite a bit about how games work apart from Windows or any other platform. For number 3, I don''t use all of Hungarian either but I''m defining my own subset for the project. Just simple prefixes...

As for the idea, I was trying to be somewhat vague so that not too many people would understand. I guess I was a little to vague.

I''m going to keep working on it though

I guess that''s all the questions that I had.




- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
I''ve written a 2D OOP game architecture that sounds similiar to what you''re talking about (except mine is a static lib because I wasn''t sure if all platforms supported dynamic linking, but I believe at this point they all do). And I''m sure there are many others as well. The game code is 99% platform independant, and the ''driver'' is pretty easy to port to different OS''s (input/video/sound/timer/error reporting). I''m not saying that yours won''t be great, but under no circumstance will it be the only one.

Its a pretty basic idea, but to be honest, most developers don''t really care that much about cross-platform development. It seems like that''s starting to change, but by far most are still Win only. And if you aren''t planning to work on the drivers, then I''m not sure people will do that for you. You need to really establish the API before that happens.

As far as hungarian goes, I personally hate it. The only real reason I see is for member variables, since those aren''t always a page-up key away. Functions SHOULD be written small enough so that local vars are never more than 2 keystrokes away. And if you change the var from short to long, you need to change to var name and everywhere its referenced. Boooooooooooo!

Rock

Share this post


Link to post
Share on other sites
Null.

As for the GUI toolkits, what exactly are you needing to do that one or more of those kits won''t handle?

You say that they are mostly for "business apps and GUIs". I must ask you, what''s the difference? Many of them have good bitmap support, and at least two of them (wxWindows and QT) support OpenGL. You''ve thrown out a hand-waving dismissal of the entire set without even giving ''em a close look or specifying what you need that they don''t provide.

Share this post


Link to post
Share on other sites


Answer #1

If I understand correctly, your having a single "common" dll that describes the interface your supporting dlls will implement should work fine.

We currently do something similar..e.g. we have a dll that exports an abstract class that is implemented by other dlls.

One of the whole underpinnings of COM is that every interface is derived from IUnknown which is an abstract interface you must implement (ATL and MFC will add this support automagically)


Answer #2

You should provide the dll that exports the interface they are to support, beyond that, they should feel free to do whatever they want.

I think once you have your abstract interface, and maybe a sample dll implementation, you should then start getting feed back on how other people will try to use it (if you can get it). Try to let your audience help you decide what direction to take your product, and what functionality you should provide, where they can take over, etc..

Answer #3

Half the people on our team use Hungarian (our MFC diehard fans) and the other half do not. We do not enforce a particular coding style.

I don't know if there are other "standards" out there.

People usually either love hungarian notation, or they hate it....I have an extreme dislike for it.


[deleted diatribe of how I think the use of Hungarian notation became so widespread]


I believe in the holy grail of Consistency. If you are consistent in whatever form you chose to code, most people should not have a problem deciphering it.


Answer #4

I am not sure what you mean by "what I will allow and what I don't allow from developers"?

I think the biggest feature you can probably include would be to allow developers to extend or build upon whatever it is you have already built. However, I might not understand the scope of what your trying to do.

I don't know of any good sites about OOA&D but there are some good books out there .


..ahh...time for another cup o'coffee...



Good luck!




Edited by - mordell on 4/10/00 8:31:43 AM

Share this post


Link to post
Share on other sites
johnhattan: I''ll send you an email explaining the project and I have a few questions to ask about GameDev hosting. (didn''t mean to sound rude in the previous reply )

mordell: Thanks, that''s kind of what I''m looking for. (It''s got all the "extension" you could ever want... ).



- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
If you''re concerned about portability, you''ll want to make sure you use ANSI C++, and avoid any of the propriety Windows stuff. Find an API that supports the platforms you want to develop for. GTK and OpenGL are found for both Windows and Linux, and there are others to choose from. I''m not sure whether .dll''s are portable, they might be an windows-only thing. I haven''t seen any for other operating systems. And working with different versions of .dll files is one of the major causes of Windows crashes.

About Hungarian Notion? I think it makes the code cryptic for those who don''t know it. It did for me when I first saw it. There''s no substitute for well-commented code.

I''m just learning OOP this year, and I think the overhead may be worth the flexibility, unless the majority of your audience are still using 286''s and 386''s. I think it gives you so much more flexibility, and the ANSI standard means a much smaller worry about the differences between compilers. C++ is my personal favorite language.

Share this post


Link to post
Share on other sites
It''s a fallacy that code generated by C++ is significantly slower than that by C.

If the C++ is written well enough, and the compiler is capable, there is almost no difference in performance.

Of course, when you start piling things like MFC on top of the language, performance drops right off the sharp end.

TheTwistedOne
http://www.angrycake.com

Share this post


Link to post
Share on other sites
Okay, thanks everyone!

Yes, it will be ANSI C++ and it will be multi-platform. According to my friend Plutt who is doing the research on DLLs, every platform has their "version" of a dynamic code library, so it will work fine. The DLLs will be different on every platform anyway, so it doesn't matter too much about compatibility. Also, the main code may be stored in a static lib instead of a DLL that is statically linked.

Does anyone know how to put the leave the code in the DLL while still statically linking, without also bloating the source of the game? Is it simply by creating a DLL project and then using __declspec(dllexport) and __declspec(dllimport)? Or do I have to do something special to get the code to remain in the DLL?




- null_pointer
Sabre Multimedia


Edited by - null_pointer on 4/15/00 5:00:41 PM

Share this post


Link to post
Share on other sites