Thread: Programming!
View Single Post
  #102    
Old March 21st, 2013 (12:03 PM).
Archenoth's Avatar
Archenoth
The arch foe
 
Join Date: Jan 2012
Gender: Male
Nature: Lonely
Quote originally posted by Serene Grace:
On the flip side, a procedural based language that doesn't give you the options to have any object oriented methods (which I believe C and Javascript are) are straightforward in the sense that they're for mocking up quick pieces of code (in my opinion, anyway) and anything more will confuse (or at least make it harder to make significant changes quickly) the programmer, even with good comments, six months or so down the line when they come to change the code.
Well, JavaScript is actually multi-paradigm in the same way as PHP is. Except it uses "prototype-based" object orientation, which is a bit weird for some people. It has many advantages over class-based, but it is less flexible when it comes to inheritance. (Though can serve the same purpose) If you are curious, here is what prototype-based object oriented JavaScript commonly looks like...

This code can be invoked like you would expect a class can be:

Code:
var rest = new REST("table");
Also, unrelated to the above code but, in JavaScript, you can also create objects in a functional and anonymous way (Which is all kinds of useful):

Code:
var someObj = {
  number: 5,

  printNumber: function(){
    alert(this.number);
  }
};

someObj.printNumber(); // alert(5);
Quote originally posted by Serene Grace:
It's funny, before studying it, I always thought object oriented paradigm was so confusing and now I don't program in anything but that style. Still, I would love to learn a fully procedural language such as C but it all seems so... messy to me.

While I do know PHP, I always use it in an object oriented fashion, therefore I still technically don't know a procedural language! XD
That's because procedural is messier. It's easy to handle for small projects, but working with larger programs becomes a real exercise in code management. It really demonstrates the requirement for coding conventions well I think.

Procedural is a direct predecessor of object-oriented. You start out with code, and to modularize and organize it, you split it up into functions, this is the procedural style... And from there you split those functions up into related groups, Objects, or in Java's case, Classes. This is the object-oriented style.

Without object orientation, you have to do the association and management of functions on your own. So you start naming functions with more descriptive names depending on what you want them to do AND what you want them to interact with.

Languages like Java also don't use functions, but rather methods. The difference here is that a function is executable code, whereas a method is actually an object passing the class that it was instantiated from a "message" to run some given code it has within it. Every object created from a class will all have methods that reference the exact same code, and the only thing unique to each object is actually the variables, or state within it. Just like how it works in Procedural. The only difference is that everything is managed for you and you are restricted to the code that you designated was "right" for a given amount of information.
Reply With Quote