C++ is an Object Oriented Language?

What does “Object Oriented” mean?

Can Perl or PHP be considered “object oriented”? Sometimes? When? How?

What is the alternative to object oriented? What does that mean?

Further, what is .NET useful for? If, hypothetically, I wanted to create a simple server/client program for my LAN (mostly win98 and XP), would C# and/or .NET make it easier somehow? Does this rule out all Linux? It sounds like TCP/IP is somehow intergrated? Would there not be networking (and GUI) libraries written and available in C to compensate?
[venturing off into IMHO]
I’ve scoured the forums and have read all the threads I can find and am more confused than ever regarding which language to choose (to learn). I was dead set on C++, and it’s still the front runner, but I would like some advice, please.

I’ve programmed extensively in Applesoft BASIC on my Apple //e (heh), and more recently Perl and PHP for pretty intensive (to me anyway, meaning several thousand lines, mySQL backend) web/database applications. I’ve taken C source code for linux, made small changes, and recompiled.

I want to be able to build a windows hello world program in minutes, using freely available libraries - complete with <file - exit>, <minimize> etc,… I want to easily communicate with other computers on my LAN via name. I want to leverage existing libraries and routines people already wrote to automate this shit.

But, then, I also want to (for example) write a quick linux program to monitor the serial port and listen for telnet-like instructions on port 12121.

Is there any language/toolkit which will satisfy these desires? If I get Borland C++ Builder, will the knowledge gained be sufficent to write simple programs which could be compiled with gcc?

Cost of the dev kit is not too much an issue as I am not directly responsible and in the end it’s a writeoff…

Graphics are not really an issue, and I’d like to steer away from java mainly because of the download. I hated downloading a 60k app then discovering I need to install 8MB JRE 1.4, that’s worse than having to go find the VB dlls. Then the apps didn’t “look right” in windows, and tended to be slow IME. Same for .NET - a 30MB download IIRC.

I apologize in advance, this post got away from me a little…

I won’t tackle everything, but…

It referes to the organization structure of the program.

An object has data, sometimes called properties and methods (i.e. functions). In true OO programming you can only access data via these methods. In other words, the data inside the object is only visible to the methods that belong to that object.

For instance:


class rectangle
{
       private:
              int width;
              int height;
              int area;
       public:
              int GetWidth();
              int GetHeight();
              int CalcArea(){return width * height;};
              void SetWidth(int w){width = w;};
              void SetHeight(int h){height= h;};
              void rectangle(){width = 0; height=0;};
              void rectangle(int w,int h){width = w;height = h;};
              void ~rectangle();
}

Once you have defined your class, you can instanciate objects:
rectangle MyRect;

If you want to read or change the data inside your object, you have to do so via the functions listed in the “public” part of the class. (This is using C++ syntax.)

OO also makes use of polymorphism, that is to say that more than two methods can have the same name, but come with different arguments. In the example above, there are two constructors (the method that gets called when you create an object). You can then create a rectangle like I did above, in which case the dimensions default to 0x0, or you can provide values, in which case the second method is called.

Another very important aspect of OO programming is inheritance. If I write:


class cube::rectangle
{
          blah,blah,blah;
}

This means that “cube” is inherited from “rectangle”. In practical terms this means that cube, by default, contains all the properties and method that rectangle has. I can, however, overide these by defining methods that have the same name and arguments in cube.

Inheritance is extremely useful if you work on large, or very large projects.

C++ isn’t really a “pure” OO language, it’s really just C to which keywords were added to make working in an OO framework easier. Languages like Smalltalk, on the other hand, are entirely object-oriented. I work on a project that is written entirely in C and that is nevertheless, for the most part, object oriented.

This is a question that’s hard to answer factually, because there is wide disagreement about what “Object Oriented” means–even among professionals and academics. IMO, what pretty much everyone agrees on is that an Object Oriented language must have user-definable types that can be aranged in some kind of hierarchy and some kind of dynamic dispatch.

“Heirarchical user-defined types” means that the developer can create new datatypes that aren’t included in the base language. For example, if someone was writing a graphics program, they might make a “point” type that has an “x coordinate” component and a “y coordinate” component. Hierarchical means that the same developer can then make a new “colored point” datatype that includes all the properties of a point, plus “red”, “blue” and “green” coordinates. “colored point” would then be a “subtype” of “point.”

“Dynamic dispatch” means that you can write routines that behave differently at run-time depending on the type of their arguments. For example, you might write one “draw” routines for a “point” that puts a white pixel on the screen at the given coordinates, and you might write another “draw” routine for a “colored point” that puts an apropriately colored pixel on the screen at the given coordinates. The routine would have the same name and arguments in each case, but the precise behaviour would depend on the type of the argument that was passed at run-time.

C++ meets both of the above requirements, although you have to explicitly request that a routine be dynamically dispatched at runtime (you must declare a method of a class to be “virtual” to get this behaviour).

Then it gets hairy, because there are some people (myself included) who say that there are other important properties that an object-oriented language must have, such as a single type heirarchy: Every data type in the language is the subtype of some other datatype, except for one “parent of everything” type. By this standard, even Java fails, because it’s “int,” “float,” etc. datatypes aren’t subtypes of Object. Some languages that meet all the above standards would be ANSI Common Lisp and Smalltalk.

As another example, some people consider “opaqueness” an important feature: you can only access the components of an object (e.g., the “x” and “y” coordinates of a point) through explictly defined methods. I myself think this is irrelevant–many would disagree.

As for language advice, you’ve given an enormous range of requirements. I’m gonna let my own preferences ooze forth and recommend Xanalys’s Lispworks ANSI Common Lisp compiler/environment. You’ll be able to write programs that do both GUI stuff and network stuff that will be code-compatible across both Windows and Linux, i.e., your code will compile to native code making calls to the native GUI on Windows and it will compile to native code making calls to Motif on Linux. You can get the personal edition for both platforms from www.lispworks.org . Bear in mind that language choice is largely a matter of personal preference.

I don’t have anything about OOP be to add, but I couldn’t help but notice this.

I’ll chip in to fill a couple of gaps in the above. More recent versions of Perl have object oriented features (the “bless” keyword, etc), meaning Perl can be used for OOP, although the features were bolted on to the pre-existing language and aren’t terribly elegant. I certainly wouldn’t recommend Perl if you want to learn about OOP.

The traditional opposite to object-oriented programming is procedural programming: languages such as Pascal, C, and COBOL fall into this category. In such languages, programs are structured based around procedures (aka subroutines or functions) which operate on data. (There are also languages called functional languages, such as Haskell, ML, CaML, Scheme, which don’t distinguish functions from data, but that’s a slightly different issue, and I only mention it so you don’t confuse them with procedural languages.)

If you’re looking for OO languages, Python is also worth considering: it’s elegant, comparatively simple, and free.

What you describe above is usually called “overloading.” “Polymorphism” is determining which method to call at runtime based on the type of the arguments to a method (or, in C++, the type of the instance whose method is invoked). Methods are never polymorphic in C++ unless they are declared virtual. Constructors are never polymorphic in C++.

Overloading is (in C++) resolved at compile time.

And, just as a pre-emptive strike against some ignorance I’ve seen time and again: There’s no such thing as C/C++. There are two languages, C and C++, and the similarities between them belie some pretty fundamental differences in philosophy and design.

For example, C++ is no longer C with Classes: The subset of C++ that was once C is no longer ANSI/ISO Standard C, but a modified variant designed to accept Standard C++'s OO structures. Standard C programs are no longer guaranteed to compile the same way on a Standard C++ compiler.

There. I feel better, and I’ll be able to point to my post when someone displays ignorance in this area.

(BTW, There is a language that could accurately be described as C with OO features added on: Objective-C. Used in the Mac world now, and the NeXT world historically, it is an OO language that truly supports Standard C as a subset.)

Aye, got my jargon crossed. The clarification is welcome, I assumed polymrphism referred to both.

One of the best ways to understand what an OO language is is to examine why Visual Basic isn’t one. On the surface, it looks like one–you have modules, which look a lot like classes, and you can create instances of a module. But VB doesn’t provide any kind of inheritance mechanism, and that precludes polymorphic variables, which most people will agree are the real defining feature of OOP.

Wow, thank you all very much. There is a lot of info here, and I’m still struggling with some of the concepts.

This sounds more like what I’m familiar with.

Can anybody extoll the relative merits/virtues of object oriented programming versus procedural programming?

Is C “lower level” than C++? (Am I correct in my understanding that assembly and machine code are the lowest?)

Does there exist a C devkit and/or libraries that simplify developing with the win32 API - for example GUI and dynamic link libraries?

Also can somebody please touch on my .NET question? What’s it useful for? Does C# preclude any linux programming?

Thanks again, this is helping me tremendously.

Well, IANA professional programmer(yet), but from what I’ve heard, .NET is the latest in a long line of languages that Microsoft has created to replace Java(the others being J++ and C#). So far, they haven’t had any success.

C and C++ are seperate languages, as Derleth said. C++ is essentially the C language with some minor syntax changes(biggest I can think of is new instead of malloc), and C++ is object oriented whereas C is a procedural language.

What is .NET?

The best comparison to .NET is Java. .NET doesn’t tie you to a single language, but .NET runtimes aren’t yet available for as many systems as Java.

The .NET languages are Visual Basic, C#, Managed C++ (C++ with a lot of new keywords), and JScript. You can write different modules in different languages, then use them all in the same application, as long as you stick to a common subset of types and features that all the languages support. The compilers for these languages produce .NET bytecode (Intermediate Language or IL), which is then translated by the runtime environment.

The .NET runtime environment (Common Language Runtime or CLR) is a just-in-time (JIT) compiler, similar to a Java environment, which translates IL to instructions for your CPU. The IL contains a lot of information about your original source code, which can make the JIT compiler’s job easier. Microsoft has CLRs for Windows and Pocket PC, and Ximian has one for Linux called Mono. Just like in Java, the CLR automatically deletes objects when you’re done using them.

A big part of .NET is the framework. Just like Java’s library, the .NET framework contains a ton of useful classes like lists, hash tables, sockets, and so on. One part of the framework, Windows Forms, lets you easily make GUI applications just like you’re using Visual Basic - and you can use Windows Forms from any .NET language.

In .NET, all data types are eventually derived from System.Object. Even primitive types like int (a.k.a System.Int32) and string (System.String) are based on System.Object, which makes it easy to make a list that can contain any type.

If I wanted to create a simple server/client program for my LAN, would .NET make it easier somehow?

I believe so. The .NET framework includes support for “remoting” - invoking methods over a network. I’m not sure what you need to do to set it up, though.

Would that rule out Linux?

No. Mono isn’t entirely finished yet, but it works and they’ve implemented a large part of the .NET framework, so if you write your app with that in mind, you should be able to run it on both Windows and Linux. I think they also have working C# and VB compilers.

You can just tell this thread has maybe 5 more posts in it before it heads off to GD (or the Pit :slight_smile: )

My two cents: OO is a way of thinking, not a way of programming. It is sets forth a way of decomposing the problem domain (what you are trying to program). The key is that with procedural programming you are telling the computer what to do with a set of basically sequential steps. For instance:

Connect(12121)
if ConnectionIsOpen
While 1=0
if datastream <> “”
parseStream(datastream)
end
loop
end
Release(12121)
In the OO world you describe the thing in the domain. These things are called objects and they have properties and methods. Properties decribe the object (think adjective), while methods represent what an object can do (verbs). Once you describe he object though you must then set the object in motion. The code above might therefore tranform into

Connection.port = 12121
Connection.Open
If Connection.isOpen
Connection.parseStream
end
Connection.Release

The code changes are subtle, but the PERSPECTIVE is dramatically different. And that’s the key. OO Analysis (studying the problem), OO Design (planning the solution), and OO Programming (creating the solution) are techniques and ways of thinking that are more natural for us as humans because its how we view the world. IMHO there no such thing as an OO Programming language. There are instead a multitude of languages that offer varying degrees of support and ease for me to express my thoughts in code. SQL? Bad. Visual Basic? Better. Java? mmm, I like Java. C++ ? Darn tootin’. PERL or PHP? Not bad, and getting better because they are adding things to the language that make it easier for me to express myself; the language is starting to think more like me, rather then the other way around.

And that’s the key.

To quote Bjarne Stroustrup (the creator of C++)

If you don’t come to grips with the PHILOSOPHY of Object Orientation you will never really understand why you are writing what you are and you’ll be another “The three pillars of OO are encapsulation, inheritance, and polymorphism” parrot who says silly things like

The ‘Implements’ keyword (which has been a part of VB for IIRC about 7 years) allows a VB class to inherit any number of interfaces and CAN be used to acheive polymorphism. Just like Java. What VB does lack is implementation inheritance, though it can be acheived using aggregation. VB is a good OO language because I CAN create classes (and objects based on them) with proerties and methods that represent things in my problem domain. Java is a better OO language only because it makes it easier to do so.

Visual Basic .NET has implementation inheritance.

Huh. I stopped following VB after 6.0 because it wasn’t useful to me.

Anyway, the point is that most people would consider some form of polymorphic variable a necessary characteristic for a language to be object-oriented.

My take on this topic is that objects are great for developing libraries and toolkits and procedural programming is great for implementing your application’s functionality.

For example, if I’m writing a networking (sockets) library I would implement the functionality using classes. I would do this to encapsulate the required data, protect it from illegal modifications, and relieve my users from needless complexity.

On the other hand, when I’m writing an application using a networking library, I’ll write it in a procedural way. My application requirements dictate that I perform actions A, B, C, D, and E. Some actions may be repeated and some may be optional. This type of code lends itsself well to procedural programming (IMHO) and poorly to OO design (there is no need to implement my actions (and their optional repitition or elision as classes, if they benefit from a class implementation I’ll use that, but I’d never design an app that way).

OO design also shows benefits when you’re looking at application architecture (from a very high level), but the actual implementation and design may be OO, procedural, data flow, or data-transformation based.

This depends on how you define “low level”

Definition 1: A lower level language lets me use features not accessable in a higher-level language.
Using this definition, C is not lower-level than C++.

Definition 2: A lower level language is easier to translate into Assembly or machine code.
Using this definition, C is lower-level than C++ (C compilers are much simpler than C++ compilers)

Definition 3: A lower level language lacks features present in a higher level language.
Using this definition, C is lower-level than C++.

I don’t know of any, and there’s little reason for anyone to create such a thing now (since C++ compilers are readily available and widely accepted on the Win32 platform, there would be little benefit to developing such a toolkit for C instead of C++).

Warning, the following is pure opinion:
.NET is useful for very small projects (proofs of concept) and large business applications. It provides a large platform library and easy integration with http servers for developing web-based business applications. .NET is also likely to be very useful for interfacing with .NET applications.

.NET is unlikely to be useful for scientific applications. .NET is unlikely to be used for game engines.

There exists a project called mono which provides a C# compiler usable on Linux and some frameworks, however the set symmetric difference between the feature sets of mono and the Microsoft implementation will be nonempty for the forseeable future (mono and the Microsoft implementation provide different feature sets, you should not assume that a specific piece of functionality is supported by both or that it is supported in a code-compatible way).

Sigh. I knew this would coax this kind of nonsense out of the woodwork. For the record, this is incorrect.

.NET is a Web Services framework, based partially on the SOAP standard (of which Microsoft is a contributing member). J++ is actually a licensed Java development tool (albeit one that Sun sued MS over because of the “extensions” to the Java standard that it included); I have managed projects that used J++ to develop applications that ran fine on non-Microsoft Java VMs. There can be little doubt, though, that C# is an attempt to de-throne Java, as evidenced by MS having it adopted as ISO and ECMA standards (recalling Sun’s notorious flirts with both organizations over standardizing Java). Can you provide details of other languages in the “long line” of MS’s attempts to undermine Java?

C++ was based on a pre-ANSI dialect of C (K&R is probably the closest thing to a “standard” that existed before ANSI). There are more than “some minor syntax” changes, although the one you cite is wrong; the library function malloc still exists in C++ (C does not contain an allocation keyword such as C++'s new). You’re right that C++ was designed to be object oriented (as others have observed here, its success in this regard is definitely a matter more suited to GD than GQ).

.NET is a lot more than just web services. If you write a simple C# app with Windows Forms that doesn’t use the network at all, it’s still quite accurate to say you’re using .NET.

Alright, in the interest of full disclosure, let me quote what Microsoft has to say:

[quote]
Microsoft .NET is software that connects information, people, systems, and devices. It spans clients, servers, and developer tools, and consists of:
[ul][li]The .NET Framework 1.1, used for building and running all kinds of software, including Web-based applications, smart client applications, and XML Web services—components that facilitate integration by sharing data and functionality over a network through standard, platform-independent protocols such as XML (Extensible Markup Language), SOAP, and HTTP.[]Developer tools, such as Microsoft Visual Studio® .NET 2003 which provides an integrated development environment (IDE) for maximizing developer productivity with the .NET Framework.[]A set of servers, including Microsoft Windows® Server 2003, Microsoft SQL Server™, and Microsoft BizTalk® Server, that integrates, runs, operates, and manages Web services and Web-based applications.Client software, such as Windows XP, Windows CE, and Microsoft Office XP, that helps developers deliver a deep and compelling user experience across a family of devices and existing products.[/ul][/li][/quote]
Suffice to say that my original point that .NET was not a programming language designed to take on Java remains valid.

.Net is a marketing term (probably developed by the same idiot that thought ‘ActiveX’ was good name") that encompasses ALOT of stuff. Note to any MS employees: please find this person and thrash them.

Basically its a furthur evolution of how we develop applications for the Windows platform. There are two diametrically opposed considerations:[ul]
[li]The platform (Windows) is constantly adding new features and getting bigger and more complex.[/li][li]Developers need easier ways to use those features.[/li][/ul]
You can see this evolution in the “bibles” of Windows development (which I always refer to by the author; “Hey! Who stole my Procise?”:[ul]
[li] Petzold: Raw Win32 in C; 250 pages before you have a “Hello World” message box; Ouch![/li][li]Procise: GUI in C++ using the “easier” MFC classes.[/li][li]Richter: Internals that mattered. WOW!!![/li][li]Box: COM. The art and science of getting code written in different languages to talk to one another. No easy trick.[/li][li]Appleman: VB made GUI’s so easy that folks literally lost their minds. Appleman reminded VB’ers of they beast the hoped to harness.[/li][/ul]
Then you throw folks like Booch, Rumbaugh, Coad/Yourden, and Martin in the mix… AIIEEEYYEEE!!!

Bottomline: .Net is any language (VB, C++, C#, Fortran, COBOL, etc) , any place (local, network, CGI, Web Service), one platform (Windows; I’m withholding judgement on Mono) .

Java on the other hand is one language (Java), most any place, one platform (Java).

To the OP: If you wanna learn what OO is all about, but want to actually see code (I get the sense that you’re the impatient type) please read
Thinking in Java . You can download it for free, but I’d be willing to be that once you’ve read it for free you’ll buy the book because Bruce deserves the money.

I know I did.[list=a]
[/list=a]