OMG

Here you can discuss ReactOS related topics.

Moderator: Moderator Team

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto » Sat Feb 14, 2009 9:40 pm

I agree with Elledan, that there exist a sane subset of C++; nobody forces you to use ALL of innumerable features of the language.
Elledan wrote: […] and avoid OO.
No. Why should one avoid OO? :)

dark
Posts: 275
Joined: Wed Apr 06, 2005 9:40 pm

Re:

Post by dark » Sat Feb 14, 2009 10:03 pm

hto wrote:I agree with Elledan, that there exist a sane subset of C++; nobody forces you to use ALL of innumerable features of the language.
Elledan wrote: […] and avoid OO.
No. Why should one avoid OO? :)
I think the real problem this thread is getting to be about is people that out-right abuse the fact that c++ is a superset of c and start putting god awful c code in c++ programs while completely ignoring the whole object oriented thing.

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto » Sat Feb 14, 2009 11:25 pm

I think that the problem is not with ignoring object-oriented things. C++ has more features, so it requires more discipline.

Awful C++ code tends to be more awful, then awful C code. :)

Elledan
Posts: 363
Joined: Sat Jan 01, 2005 3:18 pm
Location: Netherlands
Contact:

Re: OMG

Post by Elledan » Sun Feb 15, 2009 3:19 pm

You could say that C++ gives you more rope to hang yourself with? ;)

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto » Sun Feb 15, 2009 5:07 pm

Different sort of rope.

GoBusto
Posts: 579
Joined: Fri Jan 25, 2008 11:13 am
Location: UK
Contact:

Re:

Post by GoBusto » Sun Feb 15, 2009 5:26 pm

hto wrote:Different sort of rope.
C:

Code: Select all

ROPE *r = NULL;

r = ropeCreate();

if( r )
{

  ropeHang( r, yourself );

  free( r );
  r = NULL;

}
C++:

Code: Select all

Rope *r = NULL;

r = new Rope();

if( r )
{

  r->hang( yourself );

  delete r;
  r = NULL;

}

dark
Posts: 275
Joined: Wed Apr 06, 2005 9:40 pm

Re: Re:

Post by dark » Sun Feb 15, 2009 7:08 pm

GoBusto wrote:
C:

Code: Select all

ROPE *r = NULL;

r = ropeCreate();

if( r )
{

  ropeHang( r, yourself );

  free( r );
  r = NULL;
C++:

Code: Select all

Rope *r = NULL;

r = new Rope();

if( r )
{

  r->hang( yourself );

  delete r;
  r = NULL;

}
Yeah, looks like you just tacked on object oriented stuff to your C code. Exactly as I was describing.
C++:

Code: Select all

rope rope_1;

rope_1.hang(yourself);

LRN
Posts: 140
Joined: Thu Oct 25, 2007 4:19 pm

Re: OMG

Post by LRN » Mon Feb 16, 2009 2:03 am

More like something like this:

Code: Select all

uses ropes, sound, nearbyheap, adjectives;

class MyRope: public RPBaseRope
{
  void Hang(RPObject &somethingToHang);
  void HangYourself()
  {
    Hang(dynamic_cast<RPObject>this);
  }
  
  RPstring mRopeLabel;

  MyRope();
  virtual ~MyRope()
  {
    sound::PlaySound(sound::OfCuttingRope);
  }

  template<T> void HangSomething(T)
  {
    Hang(dynamic_cast<RPObject>nearbyheap::PickRandomObjectOfTypeFromNearbyHeap(typeof<T>));
  }

}

MyRope::MyRope()
:mRopeLabel(ropes::DefaultRopeLabel)
:RPBaseRope(ropes::steel)
  {    
  }


MyObjectLibrary::MainLoopFunction(foo &bar)
{
  try
  {
    RPSuperSafeDynamicWeakPointerReference<MyRope> rope;
    rope->HangSomething(adjectives::Nasty);
  catch exception(&e):
    RPVirtualLog loginstance;
    loginstance->log(e);
  }
}
If you're not doing something like that, then you've got absolutely no reason to use C++. C would work just as good, maybe even better.

dark
Posts: 275
Joined: Wed Apr 06, 2005 9:40 pm

Re: OMG

Post by dark » Mon Feb 16, 2009 2:48 am

LRN wrote: If you're not doing something like that, then you've got absolutely no reason to use C++. C would work just as good, maybe even better.
What if I wanted to use wxWidgets for my GUI?

GoBusto
Posts: 579
Joined: Fri Jan 25, 2008 11:13 am
Location: UK
Contact:

Re: OMG

Post by GoBusto » Mon Feb 16, 2009 3:09 pm

dark wrote:
LRN wrote: If you're not doing something like that, then you've got absolutely no reason to use C++. C would work just as good, maybe even better.
What if I wanted to use wxWidgets for my GUI?
You need a GUI to hang yourself? Young people nowadays... back in MY day, we strung ourselves up using nothing but the DOS prompt.

LRN
Posts: 140
Joined: Thu Oct 25, 2007 4:19 pm

Re: OMG

Post by LRN » Mon Feb 16, 2009 10:22 pm

dark wrote:What if I wanted to use wxWidgets for my GUI?
Don't confuse the cause and the effect. wxWidgets isn't any better than other toolkits (i think it's actually worse, but that's just MHO). You're not using C++ because you want WX. Instead, you're using WX because you're using C++, and you're using C++ because you want to hang yourself violently and you need C++-only features for that. Although, it's not quite true. C++ fans could also use QT. Or GTKmm (GTK+ bindings for C++). Or anything else.
And again, while some may consider it a bad practice, you still can use C++ compiler to compile C code and use C++ libraries in C applications (more precisely - in C++ applications that are written without using C++-only constructs, in C-style).

encoded
Posts: 36
Joined: Mon Jun 11, 2007 9:39 am

Re: OMG

Post by encoded » Thu Feb 19, 2009 3:20 am

NT is very object oriented by design.

LRN
Posts: 140
Joined: Thu Oct 25, 2007 4:19 pm

Re: OMG

Post by LRN » Thu Feb 19, 2009 4:03 am

GTK+ is very object-oriented by design. But for some reason it is written in C, not C++.

GoBusto
Posts: 579
Joined: Fri Jan 25, 2008 11:13 am
Location: UK
Contact:

Re: OMG

Post by GoBusto » Thu Feb 19, 2009 2:40 pm

Aha, I know this one, I remember it back from my This-Is-How-You-Do-Hello-World-In-Java days at college: You don't need to use an Object Oriented language such as C++ or Java to use OO concepts - it merely makes things a bit more convenient.

For example, in my rope example above, the C version uses (inverted commas) Encapsulation (inverted commas), in that anyone using libHangYouself does not need to know about or access any data internal to a ROPE structure directly. Instead, they use functions in the same manner as methods would be used in a true OOP language.

Of course, the only thing stopping people from messing about with supposedly "private" members of the ROPE structure directly is getting them to promise not to do so...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests