13 Jun, 2007, Ugha wrote in the 1st comment:
Votes: 0
I've been running my own mud for around nine years now, during those nine years I was the exclusive coder.

It's ROM based, so of course I was coding in C. I felt no need during this time to learn C++.

Now I've found myself forced to learn C++ due to the lack of information/libraries/code examples out there in
normal C. I hate this.

Of course, this casts C++ in a negative light in my eyes. I dislike the concepts of the language (although a
few of the non-object based ones are very interesting, such as overloading) and I'm having a hard time
figuring out WHY some things are the way they are.

So… I came up with a good idea I think. I'm a mud coder… and as a mud coder, I have one hell of an ego.

I have yet to meet a single coder who doesn't have an ego big enough to have its own area code, so let's
do what all people with giant egos like to do… debate.

I want to get a debate started about which is better and why C++ has made some of the changes it has.

The structure is simple… I'll post a "feature" of C++ that I disagree with (or perhaps don't fully understand)
and you can post a reply with your thoughts on the "feature"… either agree or disagree. Whatever you'd like.

So lets get this started.

If OOP is supposed to make everything more centralized to a single object, why on earth do 99% of all objects
have their functions defined OUTSIDE of the object? Doesn't that defy the very point of OOP?
13 Jun, 2007, Davion wrote in the 2nd comment:
Votes: 0
Ugha said:
If OOP is supposed to make everything more centralized to a single object, why on earth do 99% of all objects
have their functions defined OUTSIDE of the object? Doesn't that defy the very point of OOP?


By object, do you mean 'class'? And if so, methods can and are defined within the class definition itself, so I'm not sure what it's doing outside. eg.
class Bird
{ public:
void sing() { cout << "Cherp. Cherp." << endl; }
};

sing() is a method, and in this style I believe it's called inline method.
The actual code for the method can be stored else where in a .cpp file. eg.
Bird.h
class Bird
{ public:
void sing();
};

Bird.cpp
#include <iostream>
#include "Bird.h"
using namespace std;
void Bird::sing()
{ std::cout << "Cherp. Cherp." << endl;
}


Btw, from the sounds of it, I think your big beef with C++ isn't C++ itself, but OOP. OOP is not C++. It's a way of thinking and a style of programming, you, in no way shape or form absolutely have to use OOP methods in your code. C++ just facilitates this style moreso than C.
13 Jun, 2007, KaVir wrote in the 3rd comment:
Votes: 0
Except for a few specific cases, C++ is effectively a superset of C. If you decide to use C++, nobody's going to come around to your house and break your kneecaps just because you're not using OOP. You could even stick to writing perfectly valid C code, and just use the C++ compiler for the improved type checking.

If you're using C++, and there's a feature of C++ you don't like, don't use it.

If you're using C, and there's a feature of C++ you need, you'll have to find a workaround.
13 Jun, 2007, Justice wrote in the 4th comment:
Votes: 0
As Kavir said, C++ is a superset of C. This means that with some exceptions, your C code should be able to compile under C++. (Those exceptions generally include the use of reserved keywords like "class")

In addition to the basic C constructs, C++ allows the use of operator overloading, function overloading, templates, and classes.

The use of a function instead of members does not break OOP, there are many reasons why you would want to do this. For example, you might want to use a class to handle a specific task, while a function implements the greater system. This allows you to easily expand the code in 2 ways. You can implement the class to handle new tasks, or you can write functions to handle the task slightly differently.

I use this approach often with searches. For example, in my ranged search snippet, the search_callback class defines how a single room is handled. It defines a single method that returns "true" to say "stop searching, we've found it", and "false" to say… "This is not the room we're looking for." I define 3 search functions to handle the actual algorithm being used. The BFS algorithm uses a "breadth first search", similar to how "track" is implemented on most DIKU muds. The DIR/LOS searches use an algorithm similar to how "scan" commands are generally used.

By separating the code that gathers rooms from the code that uses it allows you to reuse the search algorithm for many tasks. Many muds want a "mini-map" code, using this approach, I'm able to generate detailed (and accurate) maps with about 100 lines of code.

I'm currently working to make a snippet of my other search code. What this code does is define a "filter" which works similarly to search_callback. That is, a function loops through and calls the filter for each item in the list. If the filter returns "false" it skips the item, if it returns "true" it does what it needs to. I've defined several functions which handle similar tasks. These come in 2 basic forms, one returns the first acceptable value it finds. The other adds each value to a supplied list and returns a count of how many were added. Functions are used for this because I need to be able to search at multiple scopes. For objects, I've defined search functions for the global list, areas, rooms, character, and containers.

Anyway, there are alot of reasons to do things in a variety of ways, and there's much discussion about techniques like composition vs inheritance, single inheritance vs multiple inheritance. When is it good to use operator overloading, when should you overload methods/functions. When to include features as part of an interface or make them separate tools. In general I view C++ as a better language than C.
13 Jun, 2007, Dorian wrote in the 5th comment:
Votes: 0
KaVir said:
Except for a few specific cases, C++ is effectively a superset of C. If you decide to use C++, nobody's going to come around to your house and break your kneecaps just because you're not using OOP. You could even stick to writing perfectly valid C code, and just use the C++ compiler for the improved type checking.

If you're using C++, and there's a feature of C++ you don't like, don't use it.

If you're using C, and there's a feature of C++ you need, you'll have to find a workaround.


While this works, I would just like to issue a strong word of caution when trying to use C++ as a "better C". There are subtle but significant differences in and outside of the language which can lead to a lot of confusion. Moreover, the new standard coming out later this decade may severely break paths with C. While, of course, longtime features will likely work the same, features from C99 may not work or work differently. Also, new concepts/caveats may be introduced that would never happen in C. If you are going to use C++ as C, be very, very careful!
14 Jun, 2007, Tyche wrote in the 6th comment:
Votes: 0
Ugha said:
Now I've found myself forced to learn C++ due to the lack of information/libraries/code examples out there in
normal C. I hate this.

Of course, this casts C++ in a negative light in my eyes.


If you can't find the examples you are looking for in C, wouldn't that instead cast C in a negative light.
I really don't think you've looked hard enough or have looked in the right places perhaps.

Ugha said:
If OOP is supposed to make everything more centralized to a single object, why on earth do 99% of all objects
have their functions defined OUTSIDE of the object? Doesn't that defy the very point of OOP?


The OO model is based on the concepts of encapsulation, inheritance and polymorphism. That would mean that 99% of functions would be defined as class member functions. But just a wild guess, I suspect you are talking about the physical location of code, and why C++ programmers would write:

// object.h
class Object {
foo();
bar();
};

// object.cpp
Object::foo() {do stuff}
Object::bar() {do stuff}


instead of …
// object.h
class Object {
foo() {dostuff}
bar() {dostuff}
};


The reason is because C++ is based on C and C is a single pass compiler. Declarations and definitions are often separated in both C and C++ to avoid problems with redefinition and ordering of inclusion problems. C++ sucks in this regard because C sucks. ;-P
Other OOP languages (like Java) have multi-pass compilers, or (like Ruby) allow dynamic redefinition of classes and member functions.
14 Jun, 2007, Ugha wrote in the 7th comment:
Votes: 0
I'm very pleased with the amount of response this thread has generated… although it seems I'm the only person against OOP here ;)

In response: Davion, your correct, I apologize for using the wrong terminology. I did mean class, not object.

I'll attempt to restate my original question with the correct terms below.

And my major beef with C++ is indeed the OOP aspect. The main problem I have, is I learn by example… I want to find information on
how to do a simple windows application (a simple non-console telnet client) and EVERYTHING I've managed to locate uses OOP to
do everything. Being old fashioned, this makes it very hard for me to understand the code and "get" why things are done the way
they are.

But that's kind of off topic.

Restating my original debate topic:
Why on earth does C++ and OOP in general allow/encourage outlining member functions when the entire concept of OOP is to keep
everything self-contained within the object?
14 Jun, 2007, Ugha wrote in the 8th comment:
Votes: 0
Tyche, I was writing my reply when you posted yours, sorry for asking something you just explained :)

Can you go into a bit more detail about what you mean by single and multi-pass compilers?
14 Jun, 2007, Tyche wrote in the 9th comment:
Votes: 0
Ugha said:
Tyche, I was writing my reply when you posted yours, sorry for asking something you just explained :)

Can you go into a bit more detail about what you mean by single and multi-pass compilers?


http://en.wikipedia.org/wiki/Multi-pass_...
http://en.wikipedia.org/wiki/One-pass_co...

Ignore the parts about optimization, although they seem to dwell on it. The key point is that the C language is designed to parse a module once, which is why declarations must be seen before they are referenced. Thus declarations and definitions are separated when they need to be used across modules in C, otherwise you end up defining a function or variable twice and the compiler has doesn't have anyway of knowing which is the correct one. C++ inherits this compiler design primarily to be backwardly compatible with C. This has nothing at all to do with OOP, just the C++ language.

OO design and programming is simply a methodology (or way of thinking about and solving problems) that builds on structured procedural programming. And OOP is has been extended with Generic Programming and Aspect Oriented Programming (AOP). There's also Functional Programming. C++ also supports Generic Programming.

But first things first. Diku/Merc/ROM aren't even examples of good Structured programming in C. The methodologies of Structured and OO programming are really language independent. Understanding OO design will in fact make you a better programmer even in C.
14 Jun, 2007, Scandum wrote in the 10th comment:
Votes: 0
Ugha said:
If OOP is supposed to make everything more centralized to a single object, why on earth do 99% of all objects
have their functions defined OUTSIDE of the object? Doesn't that defy the very point of OOP?


The general idea of OO was that OO code would be re-used.

In practice this never happens, kind of like how communism only works well in theory. So OO enforced languages exist because some geniuses decided OO is good for you.

Ugha said:
Why on earth does C++ and OOP in general allow/encourage outlining member functions when the entire concept of OOP is to keep everything self-contained within the object?


Probably because it doesn't compile/work properly if they do. OO programming happens to be pointless and counter productive 50% of the time. It's like trying to tap dance on skates. Fortunately devotion to non rational habits and believes has been hardwired in the human psyche for some reason, so you'll find as many people favoring OO as you'll find people favoring the bible above the church of the sub genius.
14 Jun, 2007, Davion wrote in the 11th comment:
Votes: 0
Quote
And my major beef with C++ is indeed the OOP aspect. The main problem I have, is I learn by example… I want to find information on
how to do a simple windows application (a simple non-console telnet client) and EVERYTHING I've managed to locate uses OOP to
do everything. Being old fashioned, this makes it very hard for me to understand the code and "get" why things are done the way
they are.


I'm not to big on writting GUI's, but I've played around with QT and wxWidget's a bit. These libs tend to rely highly on inheritance to customize your widgets. The style in which the libs are ment to be used conform to OO design, because, as time goes on, it is becoming (has become) the standard metheology when programming. I actually don't know of any pure-c GUI libs, so if any of you guys know of one do tell. If you're being tossed into the world of C++, I say, if you don't have the money for a book from amazon, check out a torrent site, I know they're loaded with ebooks. I always recommend people read Stroustrup's C++ 3rd Edition.
14 Jun, 2007, Justice wrote in the 12th comment:
Votes: 0
Ugha said:
Restating my original debate topic:
Why on earth does C++ and OOP in general allow/encourage outlining member functions when the entire concept of OOP is to keep
everything self-contained within the object?


The concept of OOP is not to keep everything self-contained within an object. That method often leads to poor design due to bloat. Because OOP is such a complex idea, it's often difficult to explain how it works, but as Tyche said core concepts include encapsulation and polymorphism. Inheritance is simply an expression of polymorphism.

Consider affects on a typical SMAUG. The current system uses a value on the struct to determine what each affect does. Functions interpret this to figure out how to apply and remove these affects. At a basic level, these 2 abilities encapsulate what an affect does. Simply knowing how to apply and remove an affect however, doesn't get the job done. Typically affects are used by things like spells and equipment. Spells generally have a timer, which causes them to wear off after a period, while equipment relies an wearing or removing the equipment to apply their effects. Don't forget that SMAUG removes all affects from equipment when a pfile is saved to prevent data corruption if the objects are modified online.

It would be poor OOP design to include the spell/equipment part into what is considered an "affect" because they represent different systems. In this case, your spells and equipment may be classes themselves and can define appropriate functions to apply/remove their affects. In some cases, you may not have a handy class to write utility functions for, in this case it's often preferred to use a function.

Now, you have several types of affects that can be applied, each works differently. Some modify numeric values, while others work on bitvectors. In this case, you can write classes that extend your affect class. By doing this, they inherit the ability to apply and remove affects. At this point, polymorphism comes into play. The implementation of each affect type is now self-contained and polymorphic. That is it can be treated as an "affect" or as itself. As you extend more classes, the more types this class can behave like.

Anyway, this is a simplistic example, and there are several things to work out, but it should give an example of how OOP can be used to solve a problem. The idea is that a class encapsulates an idea. How that class is used is NOT part of the problem, and often is better handled outside of the class. Depending on the circumstances, this may be used in a variety of ways, including functions.
14 Jun, 2007, Tyche wrote in the 13th comment:
Votes: 0
Ugha said:
I want to find information on
how to do a simple windows application (a simple non-console telnet client) and EVERYTHING I've managed to locate uses OOP to
do everything.


PuTTY is a Windows GUI Telnet application written in C. There are thousands of simple C examples using the Windows GUI API. You'll have to poke around in old repositories. Microsoft Systems Journal articles and source archives are a good source. And of course there are dozens of Mud/Telnet clients written in C.
14 Jun, 2007, Justice wrote in the 14th comment:
Votes: 0
Scandum said:
Ugha said:
If OOP is supposed to make everything more centralized to a single object, why on earth do 99% of all objects
have their functions defined OUTSIDE of the object? Doesn't that defy the very point of OOP?


The general idea of OO was that OO code would be re-used.

In practice this never happens, kind of like how communism only works well in theory. So OO enforced languages exist because some geniuses decided OO is good for you.


I disagree that it never happens in practice. As a professional programmer, I use OOP every day. With object oriented code, I often double or triple my productivity and get even larger gains in maintenance.

Scandum said:
Ugha said:
Why on earth does C++ and OOP in general allow/encourage outlining member functions when the entire concept of OOP is to keep everything self-contained within the object?


Probably because it doesn't compile/work properly if they do. OO programming happens to be pointless and counter productive 50% of the time. It's like trying to tap dance on skates. Fortunately devotion to non rational habits and believes has been hardwired in the human psyche for some reason, so you'll find as many people favoring OO as you'll find people favoring the bible above the church of the sub genius.


There is a very good reason why C++ allows using functions… it's called backward compatibility with C. As for the rest, obviously OOP can be used poorly. Perhaps you simply lack understanding… sort of like driving a screw with a hammer. It'll work but you're wasting your time, learn how to use a screwdriver and you get better results. The trick with OOP is simple, people tend to think about how things are different, the concept of OOP is recognising how things are fundamentally similar and using those similarities to simplify and reuse code.
14 Jun, 2007, mann_jess wrote in the 15th comment:
Votes: 0
Quote
I disagree that it never happens in practice. As a professional programmer, I use OOP every day. With object oriented code, I often double or triple my productivity and get even larger gains in maintenance.

Likewise. I feel bad for you if you don't get any use out of OO. I use it all the time, given that I program in Java, and without it I wouldn't be anywhere *near* where I am today. It's just a tool like any other.

Best of Luck,
-Jess
14 Jun, 2007, Scandum wrote in the 16th comment:
Votes: 0
Justice said:
I disagree that it never happens in practice. As a professional programmer, I use OOP every day. With object oriented code, I often double or triple my productivity and get even larger gains in maintenance.

So you double/triple your productivity re-using OOP code written by others? Copyright issues aside that's wonderful.

Justice said:
There is a very good reason why C++ allows using functions… it's called backward compatibility with C. As for the rest, obviously OOP can be used poorly. Perhaps you simply lack understanding… sort of like driving a screw with a hammer.

I think it's more likely that you lack proper understanding of this complex subject. A statistical study in 2006 showed that working too much with C++ causes brain rot… sort of like brushing your teeth with Mr Muscle.
14 Jun, 2007, Justice wrote in the 17th comment:
Votes: 0
Scandum said:
So you double/triple your productivity re-using OOP code written by others? Copyright issues aside that's wonderful.


From this statement, it's obvious that you don't work as a programmer. When a client pays for you to work on their proprietary software there aren't copyright issues for that work. There are many open source libraries available, don't forget the standard libraries. On occassion it's necessary to purchase a software license to work on things.

Scandum said:
I think it's more likely that you lack proper understanding of this complex subject. A statistical study in 2006 showed that working too much with C++ causes brain rot… sort of like brushing your teeth with Mr Muscle.


From this statement, I take it you have first hand experience and the prosthetic brain is overheating.
15 Jun, 2007, mann_jess wrote in the 18th comment:
Votes: 0
Quote
So you double/triple your productivity re-using OOP code written by others? Copyright issues aside that's wonderful.

Simply using a program could violate copyright. You don't assume that someone has violated a copyright when they mention using a program, do you? Why are you so insistent on reinventing the wheel, when unnecessary?

Quote
I think it's more likely that you lack proper understanding of this complex subject.

Would you say the same thing about a carpenter that used a nail gun? OO is a tool. Using any tool does not innately entail being an idiot. I could easily say the exact same thing about any other programming practice, including one that you use.

Best of Luck,
-Jess
15 Jun, 2007, Tyche wrote in the 19th comment:
Votes: 0
Scandum said:
Fortunately devotion to non rational habits and believes has been hardwired in the human psyche for some reason…


Psychological Criticism of the Prototype...
An Ontological Critique of Object Orient...
Classes vs. Prototypes: Some Philosophic...
Class-is-Type is Inadequate for Object R...
15 Jun, 2007, Scandum wrote in the 20th comment:
Votes: 0
Justice said:
From this statement, it's obvious that you don't work as a programmer.

Nope, I'm into direct marketing, and somewhat of an expert when it comes to bypassing spam filters.

Justice said:
Scandum said:
I think it's more likely that you lack proper understanding of this complex subject. A statistical study in 2006 showed that working too much with C++ causes brain rot… sort of like brushing your teeth with Mr Muscle.

From this statement, I take it you have first hand experience and the prosthetic brain is overheating.

When diagnosed with an incurable form of brain cancer
the woman asked, "can't I get a donor brain?"
That's where Bill came into play
having lost his balls in a bicycle accident.
As Donnie Darko said: life without a dick is meaningless
and the same goes for a life without balls.
So Bill awoke with breasts and a clitoris
which technically is a miniature penis.
Life made sense again but not much else did
till he met a man on wtf.com.
This man named Jane had the brain of a woman
and still peed while sitting down.
Their marriage was a compromise
and they raised their children
who were surprisingly bright
as their own.

Tyche said:
Scandum said:
Fortunately devotion to non rational habits and believes has been hardwired in the human psyche for some reason…


Psychological Criticism of the Prototype...
An Ontological Critique of Object Orient...
Classes vs. Prototypes: Some Philosophic...
Class-is-Type is Inadequate for Object R...

I'd much rather have you insult my intelligence than having me spend half an hour reading your links. It's an interesting way however to support my statements and avoid getting drooled over at the same time.
0.0/41