quote: Original post by msn12b
You''re designing the data model incorrectly; while in real life you need to know pretty much everything about a certain weapon before using it, but in a game, using an objectified approach, you can use abstractions to correctly model the solution. These abstractions don''t need to model real life at all. (Since we''re dealing w/ the C++ Standard here, take a look at how streams and iterators were adapted to coexist with each other.)
Weapons, in general, have several traits: they can be equipped, they deal damage, they have accuracy modifiers, and they alter the current appearance and reaction of the equipping character. All these traits can be expressed in a base class, with the derived classes providing specific functionality.
Wow! That''s a lot different than what I did! What I did was to put several traits (data members) in a base class (weapon), with the derived classes (gun, sword) providing specific functionality (pull_trigger, manage_ammo, swing, etc.). I''m glad you told me how to do it correctly! LOL
quote: Original post by msn12b
This is blatantly incorrect. Object oriented programming is not designed to model real life; it is a paradigm that treats the problem domain as a set of objects that interact with each other, where an object is a collection of data that can respond to messages. While objects tend to coincide with how people generally view the world, they do not have to model the real world AT ALL.
null, while your philosophical approach to software engineering is admirable, you have to realize that, in the end, it is engineering, not philosophy, and as such needs to be more strongly grounded in reality. Waxing philosophical is nice, but you have been missing out on the basic tenets of programming in general. Real life and software life are two completely different realms.
Um, yeah, get back to the real world and stop acting like software is meant to model the real world!
1) Software exists in real life, it exists to interact with other parts of real life, it is created by people in real life, and it has a real purpose. To work 100% correctly with every other part of real life, software needs to model real life. Saying we should model imaginary objects using improper abstraction (like your gun example) to make programs that simulate reality (and all games do this to a certain extent) will only create trouble down the road. It''s not open to expansion by any means other than breaking the class, which is not modular, and destroys encapsulation.
2) Stop and think about your gun model. You are moving things that should be in the character class (used with all weapons, like evade percent, armor value, etc.) to the weapon class. Try to write a character class and a weapon class to work together, to do the entire attack, and it either won''t work or you''ll have to use public data members (or simulate them with writing accessors). I''m sick of seeing classes that have so many pitfalls that they won''t work. Why don''t people just use what is there (reality), and then make classes from that? It''s stupid to adjust reality to your thinking. I''m sorry, but I haven''t found a place where modeling classes according to the real life objects they are expected (by the user of the class) to model has not turned out better.
Elighten me, O Great One! Grant unto me the divine creative power of irreality! The unbelievable organizational freedom of Chaos!! LOL
(Perhaps I misunderstood, no?)
quote: Original post by chippydip
I should have been clearer. I was thinking more along the lines of a painting, piece of music, or other art form. These all exist in some physical form, yet the evaluation of thier beauty it completely subjective. The same is true of computer code. It exists in a physical form, yet its interpretation as "readable" is purely subjective. The biggest difference between these two examples is that programmer''s views of readability are generally much closer than artists'' or musicians'' views of how aesthetic their respective arts are. Despite this pseudo-standard view of readability, there is still no definite, external, standard so readability still remains subjective.
No, it''s still a bad analogy. You just can''t be clear with over-simplified examples.
1) Art may exist in a physical form, but beauty does not. The only link between the physical form and the beauty is people. Beauty wouldn''t exist without people. (As pertains to my idea I don''t care how many people have to read it or what they think; I''m concerned what the compiler sees! How many times do I have to say this?
2) Code, unlike art, is not created to be viewed by other people. It is there to be interpreted by computers. It uses the English language as a mere convenience -- the standard was already implemented when coding languages came on the scene, so it was used. No matter what you say, subjective viewpoints have no effect on the compiler''s interpretation of the code.
quote: Original post by chippydip
Like I said, however, once you have this function, the probability that two "best" solutions exist is really a subjective evaluation. I think that it is quite possible and you think that its nearly impossible.
Why? I thought we were supposed to quantify them objectively?
quote: Original post by chippydip
Sort of. If everyone had a different idea of what made readable code then the idea would be truly useless. Programmers in general tend to have similar (but not identical) views of what makes readable code. This makes it useful to aspire to generally readable code, but there is no exterior standard which can be used to say that one coding style is more readable than another. The final judgement is subjective.
bzzt! Check out your reasoning here...rationalisms...rationalisms...rationalisms...
Reconcile the second sentence in that paragraph with the last sentence in that paragraph, and I may concede.
quote: Original post by Kylotan
You are using my labels to enforce definition again Just because you use a language construct only as it exactly matches the name, doesn''t mean I will, -especially- not when using English
...
If you expect me to be able to converse with you in an intelligent way, you -must- use the English standard. The efficiency of our communication is directly proportional to your compliance with the English standard.
If you expect me to be able to converse with you in an intelligent way, you -must- use the English standard. The efficiency of our communication is directly proportional to your compliance with the English standard.
quote: Original post by Kylotan
The alternative model, a single Exception class with a string parameter, was something I proposed for argument''s sake. You could give it 2 parameters, 1 for the function-name that threw the exception, and 1 for the error message. RTTI could give you the error message, given explicit and long-winded enough typenames, but it won''t give you the function in which it was thrown. So you need 1 parameter anyway, may as well have 2. If, in your design you never need to execute conditional code based on the nature of exceptions you catch, a hierarchy is overkill.
1) The function from which it was thrown? Function exception specifications.
2) I only said that my model was better than trying to do type-checking another way. I never said you couldn''t add data members.
quote: Original post by Kylotan
Although, is there anything to stop the use of a switch to call virtual functions (which may have to be overriden by further switches in user code)? Ugly.
How is that different from allocators?
quote: Original post by Kylotan
On that note, C++ lacks local functions. This could perhaps be considered a deficiency in the language. You can simulate them with private members, but then any other member could call that function when it makes no sense to do so. You could also simulate them with objects having an overloaded operator(), but that doesn''t seem right either.
Local classes.
quote: Original post by Kylotan
Interesting viewpoint... you say to use typechecking, which allows the compiler to do checks for us, rather than needing to use switch statements or string comparisons... and I agree. But garbage collection is built on a similar premise... tell the system when you need memory, and let it worry about checking whether it is still needed or not. The same goes for auto_ptr as mentioned in the other thread. It''s about standardising (your favourite process ) the access to a certain system, process or routine and minimising the interface to reduce the chance of programmer error. Having to remember an explicit ''delete'' to match each ''new'' is a source of many bugs and memory leaks. I would agree that if a C++ programmer moved to a garbage-collected language, then yes, they would introduce hidden bugs, but only because they don''t really appreciate how the allocation model works. Once you have it mastered in your head, it is cleaner. (Quicker/more efficient? That''s another story. Choose the right tool for the job. )
1) Actually, new()-ing and delete()-ing are easy operations. Add one in the constructor, the other in the destructor, and you''re set. You can also define the copy constructor and operator=() if you wish, or just make them private.
2) Your analogy is bad. Type-checking is a language feature. Garbage-collection is re-writing the new and delete operators. If the purpose or re-writing is not to provide an add-on (perhaps fail-safe wrappers when exceptions occur?) to the language, then it is stupid to use it. If garbage collection does nothing but increase the code size over corresponding new and delete operators, then it is truly useless.
quote: Original post by Kylotan
quote:
--------------------------------------------------------------------------------
This "design by contract" thing seems to be a concept that has been used by programmers for ages: responsibility. You can enforce it with exceptions, and type-checking, scope resolution, etc. There are so many tools in C++.
--------------------------------------------------------------------------------
*gasp* You''re not suggesting that a single feature can be implemented in numerous different ways, are you?
No, in this case the problem is very complex and requires several language features, each doing their particular task, and working together to accomplish one big task. I still don''t understand what advantage exceptions have over assertions, from the viewpoint that assertions are unusable across software layers.
- null_pointer
Sabre Multimedia