Date: Thu, 13 Nov 2003 05:21:40 +0100 From: Erik Trulsson <ertr1013@student.uu.se> To: Lucas Holt <luke@foolishgames.com> Cc: freebsd-questions@freebsd.org Subject: Re: Newbie: The C / C++ Issue Message-ID: <20031113042139.GA10707@falcon.midgard.homeip.net> In-Reply-To: <2721593A-1582-11D8-BB00-0030656DD690@foolishgames.com> References: <200311130137.hAD1bUg02673@gateway.home> <2721593A-1582-11D8-BB00-0030656DD690@foolishgames.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Nov 12, 2003 at 09:36:15PM -0500, Lucas Holt wrote: > > On Nov 12, 2003, at 8:37 PM, Marty Leisner wrote: > > > > > > >BTW -- I've been doing "object oriented" stuff in C for years -- > >its harder, but its doable. You have a much simpler language > >to deal with. > > > >First learn how to write good programs in C. > >Then see if C++ buys you anything extra. > >If it doesn't, you don't need C++. > >But I've seen far too much C++ that's just obscure C. > > > >Just my experience and opinion. > > > >marty > > Am I missing something here? When does C have OO capability? Structs > don't count. What about inheritance and polymorphism? You can write object oriented code in almost any language. This does not mean that those languages have features that are intended to facilitate writing object oriented code. C does not directly support inheritance or polymorphism, but it is quite easy to "fake" it by hand. A bit more work than if you had done it in C++, but quite doable. > > To me a struct is like a VCR with no record button. You can view the > content, but you can't manipulate it with the struct. If i want to do > something to destroy the tape, I must apply a magnet from an outside > source (much like a plain old function). And classes provide security, > much like the tab on the front of the tape. The data is private if the > tab is puched out. (ok thats a bad analogy) > > If C had OO features, then why do we have C++ and Objective C? Because C does not really have any OO features. You can write OO code in C, but it is easier to do it in C++ or Objective C, or some other OO langauge like Smalltalk. > > I would agree that you can write programs that do the same thing in all > three languages above, but I don't think that OO is a waste of time. > OO promotes code reuse. That is the whole point. > > Using C++ implies a state of mind. You can write code like in C, but > it defeats the purpose of using an OO language. C++ is not really an OO langauge. It is a language with features that support writing OO programs, but it also has features that help writing programs in other styles. That is actually my main complaint against C++. It has so many features, and so many special cases that it is almost impossible to actually understand the whole language. This means that you either have to restrict yourself to a small subset of the language (in which case you probably better off using some other language) or run into surprises when things don't work as you would expect. IMO, C++ is almost never the best language for any particular task (but on the other hand it is almost never the worst language either.) -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031113042139.GA10707>