I'm still not in the habit of creating functions or classes in whatever I write. Really I am just asking for some advice about how often I should be writing functions. I don't fully understand OOP yet so we'll leave this out.
Do you create a function at every change possible or do you tend to use them as soon as you see yourself writing the same bit of code twice?
Do you see it worth the hassle of having to work out a function that can handle 2 types of situation but run similar code or do you find it best to whack an if statement around 2 similar pieces of code?
At what point should you change your script to a function
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
As you begin to develop more applications you start to realize that some code will be used more than once. Time for a function. As those functions begin to appear in more and more code but in different context's it might be time for a class.
For testing code, I will almost throw down some procedural stuff. But that is quite literally to test PHP functions. Once I use them, they will almost always go into a function/method.
For testing code, I will almost throw down some procedural stuff. But that is quite literally to test PHP functions. Once I use them, they will almost always go into a function/method.
- The Phoenix
- Forum Contributor
- Posts: 294
- Joined: Fri Oct 06, 2006 8:12 pm