Jump to content

Recommended Posts

Hello,

 

I'm a self-directed programmer (haven't studied informatics or something simular) which, i guess, has some benefits, but also some disadvantages.

 

let's say that i can look at programming with an open mind.

 

And bad side, i'd sometimes feel disoriented and the way that i would tacle a coding problem seems not to match the "general mainstream way of doing coding".

 

In a attempt to code more at a 'scientifically / educational' level, i delved myself into OO-programming and frameworks.

 

I was wondering if: ,


- is it better to code OO?
- are frameworks usefull? necessary?

- all big applications, should they be OO?

 

- what's the speed at what you guys are learning? I'm reading about PHP for 1 year now, a good time to start OO?

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/
Share on other sites

1) is it better to code OO?

2) are frameworks usefull? necessary?

3) all big applications, should they be OO?

4) what's the speed at what you guys are learning? I'm reading about PHP for 1 year now, a good time to start OO?

 

1) Not always.  It is what I personally prefer, though.

2) They are usually useful, but more so depends on which one you choose for your project, and if it suites your project well.  They are not necessary, but can speed up development time and give your project a solid foundation to work on.

3) Not always.  It is what i personally prefer, though.

4) Yes.  But, I would recommend learn OO with a tighter language, first.  Like Java.  Learn the concepts there, then come back to PHP.  You can make a mess real quick learning OO with PHP because of how loose everything is.  This is my humble opinion, though.

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417262
Share on other sites

I can tell you from my experience as a non-officially-educated programmer as well that coding in OO is better than ordinary procedural coding even if you're coding all by yourself. Yes, It may take longer time to code but in future the code will be clearly readable and changes will be significantly easier than they would with all the code mashed up together. This of course is my point of view, people are welcome to disagree.

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417268
Share on other sites

- is it better to code OO?

"Better" is subjective. Does the code look better? Yes. Is it suitable for highly-constrained environments, like those of low CPU or low memory or high performance? Generally not.

- are frameworks usefull? necessary?

Definitely useful: it's a bunch of functionality all in one place. It's often "necessary" in that 99% of the time you'll end up writing some set of common functions or classes and presto! you have a framework.

- all big applications, should they be OO?

To some degree. OOP greatly helps with coding and maintenance but at an expense. It also depends on the language: OOP in PHP will slow down the script and increase memory usage, while in C it's often done with macros and thus not very different from procedural code.

- what's the speed at what you guys are learning? I'm reading about PHP for 1 year now, a good time to start OO?

It's always a good time to learn OOP.
Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417299
Share on other sites

- is it better to code OO?

Yes, OOP is the standards for good programming practices, it is a step necessary for amateur programmers to improve into professionals. If you are doing programming for a living, chances are you wont find a job unless you are comfortable about OOP. OOP offers many things other paradigms either cannot or can only mimic poorly, good examples are Polymorphism, Encapsulation, Modularization/Reusability, Better Maintenance and Easier teamwork. In a perfect script everything is an object, you cant be perfect, but you can approach it as much as possible.

 

- are frameworks usefull? necessary?

They definitely are, but whether its necessary or not to use Frameworks will depend on your project. Sometimes Id say go for it, sometimes you can survive as well without them.

 

- all big applications, should they be OO?

Yes, successful big applications all use OO, theres a reason for that. Large projects typically rely considerably on teamwork, which is difficult if your application uses procedural style. The benefits of OOP  I mentioned earlier also are much more evident in larger projects than smaller ones. You can build a fansite with Procedural programming just fine, but for a professional website it wont work.

 

- what's the speed at what you guys are learning? I'm reading about PHP for 1 year now, a good time to start OO?

Id say its a good time to consider OOP, but only after you are comfortable with the basics of PHP. 1 year is not a short learning time, I'd assume you are already quite good at procedural PHP so its about time to improve yourself further. Remember, you cant be an advanced or professional programmer until you can code in OOP.

Edited by Hall of Famer
Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417313
Share on other sites

Everything comes down to experience. 

 

In the real world when you got such a close deadline you will see alot of programmers going the traditional procedural coding with PHP. PHP OOP is not always the best solution for every task, you won't be using OOP for job out there you get hired for because sometimes its just a waste of time. 

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417323
Share on other sites

Object Oriented Programming (OOP) definitely has its place. Even if you're not going to use it in your projects, learning how to think OOP will improve your code and coding style. Guaranteed.

That said, as (almost) everyone above have said: Both OOP and procedural code has its place, and knowing when to use what is the real trick. Try to force something that should be procedural into being OO, and you've just added a whole lot of unnecessary complexity for no gain at all. Vice versa, and you've got a (too) inflexible solution which puts severe limits on future expansion.

 

Both procedural and OOP can easily be utilized to create an unholy mess, avoiding that is entirely up to the programmer. Generally speaking though, the more complex the system the easier it is to create said unholy mess.

 

Also, one thing that most people struggle to understand, is that using classes and objects is not equatable to OOP. You can use objects in strictly procedural code, like in this example. As you can write object-oriented code without using objects (albeit, that tends to be more difficult).

It is all about how you structure your code, how it's abstracted out.

 

PS: I wouldn't put too much stock in how Hall Of Famer extols OOP, stating that it is the end-all and perfect solution. He's a "bit" too biased, for some reason.

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417469
Share on other sites

You can use objects in strictly procedural code, like in this example.

 

umm whats your point? That one was just an example from a typical PHP site, I have my own database, query object, domain model and mapper classes to handle OO script and I dont feel it necessary to post it here as it will require too many lines of code and files. Id personally never use that style for an OOP application lol.

Edited by Hall of Famer
Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417520
Share on other sites

Hello,

 

I'm a self-directed programmer (haven't studied informatics or something simular) which, i guess, has some benefits, but also some disadvantages.

 

let's say that i can look at programming with an open mind.

 

And bad side, i'd sometimes feel disoriented and the way that i would tacle a coding problem seems not to match the "general mainstream way of doing coding".

 

In a attempt to code more at a 'scientifically / educational' level, i delved myself into OO-programming and frameworks.

 

I was wondering if: ,

 

- is it better to code OO?

- are frameworks usefull? necessary?

- all big applications, should they be OO?

 

- what's the speed at what you guys are learning? I'm reading about PHP for 1 year now, a good time to start OO?

 

 

Like others have said, 'better' is a loaded term.  Better for whom, and in what context?  OO, when done right, enforces encapsulation and modularity, which leads to reuse.  These are Good Things.  Those things, however, come at a cost.  It generally takes a fair amount of bootstrap code to do anything useful when going pure OO, and (less relevant in the vast majority of cases) objects aren't as memory friendly as other primitive data types. 

 

Put another way, there's an equilibrium point where the up front costs of using OO will be exceeded by the cost of not using OO.  It's up to you to determine that point and what projects fall on either side of it.

 

Regarding frameworks: they're very usefull and all-but-necessary.  That said, you should learn the fundamentals of OO first before using one.  Big apps do and should use a framework.

 

Regarding learning time: there's no definitive answer.  OO is notoriously hard to grasp at first, and everyone learns at a different rate anyway, so don't treat it as a contest where you think you failed because you didn't learn it in X amount of time.  Further, programming is a skill.  There's no real endpoint for gaining skill.  Even the greatest minds in our industry continue to learn.

 

What resources are you going to use to learn OO?

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417545
Share on other sites

My point was, as I wrote, to show that one can use objects in a purely procedural code. That was simply the first and best example I had available.

 

Alright then, guess I should apologize for posting a bad example of non-OO PDO usage. I pretty much copied it from PHP.net since I realized my actual database class and domain model objects will be too long for a newbie to read. The reference is here:

http://www.php.net/manual/en/pdo.prepare.php

 

But yeah, you are right these are bad examples with poor OOP practices. I will edit out my post so as not to confuse newbies with amateurish procedural coding, thanks for pointing it out.

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417588
Share on other sites

class world {
    private $text;
    
    public function __construct($t=null)
    {
        if ($t)
            $this->text = $t;
        else
            $this->text = 'Hello World';
    }
    
    public function output()
    {
        return $this->text;
    }
}

$obj = new world();

echo $obj->output();

 

There must be an easier way

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1417592
Share on other sites

Thanks all for the replies!
 

 

What resources are you going to use to learn OO?

 


KevinM1, this is a very interesting question!

Actually, i have a sort of "framework" which i doubt, anyone is going to know. It's called NORMALISED SYSTEM FRAMEWORK.

 

Why do i say sort of framework: because actually it prescribes how applications should be build and encapsulated in higher level modular constructs, the so-called 'elements')

 

The elements are:
- action elements (performing tasks),

- data elements (for going to the database),

- user-connector element (uses MVC architecture and provides CRUD functionality)

- workflow elements (defining flow of actions on data-elements)

- trigger element (defines triggers for starting the workflow)

 

The elements all contain classes. Example: an action element contains an Agent, an InterfaceClass, Argument, Parameter and 1 or more implementation classes containing the actual implementation of a task (say calculating VAT). All other classes must be added to provide stability/ modularity/ no ripple effects. 

 

Now this framework is mainly writtin with one purpose: avoid combinatorial effects (= avoid change to the application growing along with the size of the system), i.e. achieve stability.

 

I have a simple application writtin with the "laws" of NORMALISED SYSTEMS, i went through it in 7 days. As far as i can see it, the promise of stability seems to hold.

 

 

Anybody heard of the framework by accident ?

Link to comment
https://forums.phpfreaks.com/topic/275375-oo/#findComment-1418844
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.