Basically, trying to define a set of types to replace the standard int, char, float, etc... to make C++ more like Ruby. This is what I have so far... not sure what to name a namespace other than perhaps POOP (Pure Object Oriented Programming... obviously very unprofessional), so I haven't tossed them in a namespace yet.
Anyways, any suggestions on what else I might need to add, or how to implement things like Ruby's arrays (can store any number of any types of objects, and are safe from memory leaks)... obviously void pointers aren't exactly an option.
Interesting fact: It takes less characters to type out class and public than it does to type out struct and private. Thus, as long as I am using at least one private or protected member, I am better off writing something as a class, so I can shorten the number of characters I have to type writing it up. Otherwise, for an all public data type, struct will be more appropriate.
Tried doing template specialization for the p_char_obj to make it just a p_obj_type, didn't work out too well. But I guess I like the idea of a char more like an Ada Character than just an 8 bit number
you should probably create a base class object for all of your objects, and support virtual methods for things like tostring, equality and the like. That way, everything is an object (literally, heheh).
class Object {
public:
virtual std::string to_s() {
std::ostringstream out;
out << "Object:" << (void*)this;
return out.str();
}
C++ is meant to work however you want to make it work. That's the entire idea behind making it multiparadigm. Anyways, found a way that sort of works.... should probably use virtuals for a few things though, like >>17 suggested.
>>19
Trying to do prototype OO (likely the alternative >>14 has in mind) in C++ is not going to work out. C++ isn't a dynamic language and you would have to subvert the object system almost entirely to make it work. It would be a lot like doing OO in C.
I'm not doing prototype OO though. I'm wrapping all the basic data types in classes and giving them an ass load of methods to make them the C++ equivalent of Ruby Fixnum objects (or, alternatively, do to int, float and char what std::string did to char*). The only thing I can't do is shit like 5.to_s() or Fixnum.each { block_of_code }, because that's beyond the power of C++. Although I wish I could make an equivalent of the proc class, and have it store some function pointer (or anonymous function ala C++11), let it be aware of it's own arity, and have some call (bleh, ...) method.
Yeah, there would be limits to what you could type like "hello".print(); But you could still do String("hello").upperCase().concat(" faggot").concat(" how are you doing today?").print();
Name:
Anonymous2011-12-26 18:33
>>22 I'm not doing prototype OO though. [...] The only thing I can't do
The only thing you can't do is what everyone does with Ruby: treat it like a proto-OO system.
Since Ruby is a dynamic language it isn't hard to support monkey patching classes (at the cost of performance.) This is how eg. rails works. You can't provide an object system in C++ that comes anywhere near approximating the way people use Ruby, where every framework piles its crap into the base classes. It's why Ruby is so slow (look at benchmarks that don't use rails vs. ones that do.)
Why don't you just stop using C++? There are a lot of other languages out there that have different type/object systems. In fact in some languages what you're trying to do is considered quite acceptable instead of downright terrible.
I'm not talking about how everyone uses Ruby, I'm talking about how Ruby was built. With the philosophy that everything is an object and should be able to be manipulated as such. Also, given that this is not for any web development, why are we bringing up Rails? Rails is not Ruby, it's just a framework people tend to use with Ruby
>>26
I brought up rails because it's the most common Ruby framework. More Ruby code is written with it than without, or was the last time I checked. You don't need to target the web just to use a framework.
Anyway you seem bent on fagging up whatever your working with so you might as well stick with C++. When you finally make integers, floats and pointers into objects you'll be somewhere between the speed of rails and plain Ruby.