SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member bit101010's Avatar
    Join Date
    Jan 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Better PHP Development

    I've been studying and using PHP for a while now and believe I have a pretty good grasp on the language. My problem is maintaining a good programming structure, in particular MVC. I have difficulty trying to prevent myself repeating code and I constantly worry that I might be doing something wrong. It is after reading the source code of frameworks such as CakePHP and Codeignitor I see the marvelous work the developers have done and wonder if I will ever be able to code to such a high standard. I realize they have thousands of hours of programming under their belt, but I still doubt myself.

    My main issues are:
    Maintaining a proper error checking and logging system,
    Code repetition / Abstraction - Particularly database related functions (eg using PDO I still have to use over ten lines to execute and check the result of a query, there must be a simpler more abstract way),
    My rapid introduction to the Web development environment - I live in a rural area and as such many businesses don't have websites. I have 3 clients lined up in addition to the one I currently have. A lot of potential for money there, but it worries me that I have not had a huge amount of time to develop my programming skills. On the other hand I know taking on the clients will help with this, but I can't afford to get it wrong.

    What do I do? Do you have any suggestions for improving my programming ability? I will be starting a Computer Science / Mathematics degree this year also which I expect will improve my skills in this area. I've also considered learning CakePHP, because I believe this will help with my understanding of structure as well as speed up development.

    Also, I tend to do a Design/Develop combo whereas generally there would (I think) be two people, one who is fluent with the design side and one with development. I can manage the mockup HTML, CSS just fine, but sometimes people request flashy Javascript features that I simply can not offer them. What do I do in that situation? I've just been ensuring that they understand what my skills are and what I can offer them.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bit101010 View Post
    I've been studying and using PHP for a while now and believe I have a pretty good grasp on the language. My problem is maintaining a good programming structure, in particular MVC. I have difficulty trying to prevent myself repeating code and I constantly worry that I might be doing something wrong. It is after reading the source code of frameworks such as CakePHP and Codeignitor I see the marvelous work the developers have done and wonder if I will ever be able to code to such a high standard. I realize they have thousands of hours of programming under their belt, but I still doubt myself.
    If you're looking for learning material, I recommend From Flat PHP to Symfony2, Create Your Framework book, and PHP Objects, Patterns and Practice. Beyond that, continue to look at the code from the best and popular frameworks, such as Symfony, Zend, Cake, and CI.

    Quote Originally Posted by bit101010 View Post
    My main issues are:
    Maintaining a proper error checking and logging system,
    Code repetition / Abstraction - Particularly database related functions (eg using PDO I still have to use over ten lines to execute and check the result of a query, there must be a simpler more abstract way),
    Many of the modern frameworks use database abstraction layers and object relational mappers. Although these tools may be more than you need right now. Perhaps we could help you tighten up your PDO code.

    Quote Originally Posted by bit101010 View Post
    My rapid introduction to the Web development environment - I live in a rural area and as such many businesses don't have websites. I have 3 clients lined up in addition to the one I currently have. A lot of potential for money there, but it worries me that I have not had a huge amount of time to develop my programming skills. On the other hand I know taking on the clients will help with this, but I can't afford to get it wrong.
    It may be worthwhile to be in contact with a few other more experienced people who you can call on if you get stuck. Try to do the jobs yourself, but have a safety net ready if you can't.

    Quote Originally Posted by bit101010 View Post
    What do I do? Do you have any suggestions for improving my programming ability? I will be starting a Computer Science / Mathematics degree this year also which I expect will improve my skills in this area. I've also considered learning CakePHP, because I believe this will help with my understanding of structure as well as speed up development.
    If your goal is to get into web development, then speaking as someone who went through four years of college, I don't think the degree is worth it. You'll be dropping about $40K. Half of that will be spent on general education courses that are largely a repeat of high school. Half of your computer courses will be in theoretical fields that you won't use in your day-to-day work. And the other half of computer courses that are actually relevant will teach only the basics.

    A lot of employers in this field, especially development agencies, place little weight on education. They care only about your knowledge and skill, regardless of how you acquired that skill. When I was last hired to an agency-style job, I didn't even bother to mention my degree. If you want to be good in this field, then it will require a lot of self-learning.

    The good news is that, thanks to the wonders of the Internet, you can learn from the very best in the field. They blog, speak, tweet, and an assorted collection of other high quality resources. And of course there's always the manuals and specifications.

    But to be safe, before you consider taking my advice, I also suggest that you scope out the kinds of places where you'd like to work, and get in touch. Ask the employers directly what kind of background they look for, what kind of skills they look for, and get their advice on how best to learn those skills.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member bit101010's Avatar
    Join Date
    Jan 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you're looking for learning material, I recommend From Flat PHP to Symfony2, Create Your Framework book, and PHP Objects, Patterns and Practice. Beyond that, continue to look at the code from the best and popular frameworks, such as Symfony, Zend, Cake, and CI.
    Thanks! I'll check it out.

    Perhaps we could help you tighten up your PDO code.
    I'll see if I can get some example code and post it later on.

    but have a safety net ready if you can't.
    Excellent, thankyou.

    If your goal is to get into web development, then speaking as someone who went through four years of college, I don't think the degree is worth it.
    Thanks, but I will be doing the degree regardless. I have a genuine interest in the computer science field and would like to know and understand more about the technical stuff behind it. I've been using computers everyday since the age of 4 so if this isn't the course for me I don't know what is. Regardless of whether it will aid in furthering my career I would like to at least do the course for my own personal interest.

  4. #4
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    It's a long process that only comes with practice. Once you move beyond asking "How can I solve this?" to "How should I solve this?".

    In general, I'd say applying a couple of principles to your code will demonstrate to you how to code is better. It's not immediately obvious what advantages they give until you've used them in real projects. The benefits come to you when you try to use your code and realise how flexible and easy to maintain it is.

    1) Favour composition over inheritance. I actually removed 99% of "Extends" keywords from my codebase and it became a hundred times better. It wasn't until I did it that I realised quite how much I was coding to work around inheritance and using it where I really shouldn't be.

    2) Make all class variables private and avoid getters/setters unless they are absolutely needed. This goes hand in hand with 1) but it will help you achieve better encapsulation, which is a fundamental principle in OOP.

    3) Dependency inejection. Once I started using a dependency injection container, I realised that most of the code I had was messy. Creating objects arbitrarily is messy! Try IoC (inversion of control) and you'll quickly see the benefits.

    4) Law of demeter: http://en.wikipedia.org/wiki/Law_of_Demeter Apply this and your code will become better. It's not immediately obvious if you don't understand it, but it forces you to think about the dependencies your classes have.

    5) Unit testing. Once you start writing code that's easy to test, you have code that's easy to isolate and therefore, reuse.

    That's my top 5 tips for going from "advanced" to "pro".

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bit101010 View Post
    Thanks, but I will be doing the degree regardless. I have a genuine interest in the computer science field and would like to know and understand more about the technical stuff behind it. I've been using computers everyday since the age of 4 so if this isn't the course for me I don't know what is. Regardless of whether it will aid in furthering my career I would like to at least do the course for my own personal interest.
    Sounds like me when I started. My only point is that, for example, $200 for Knuth will teach you tremendously more than will $2K for a course on Algorithms and Data Structures.
    "First make it work. Then make it better."

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    If your goal is to get into web development, then speaking as someone who went through four years of college, I don't think the degree is worth it. You'll be dropping about $40K. Half of that will be spent on general education courses that are largely a repeat of high school. Half of your computer courses will be in theoretical fields that you won't use in your day-to-day work. And the other half of computer courses that are actually relevant will teach only the basics.

    A lot of employers in this field, especially development agencies, place little weight on education. They care only about your knowledge and skill, regardless of how you acquired that skill. When I was last hired to an agency-style job, I didn't even bother to mention my degree. If you want to be good in this field, then it will require a lot of self-learning.
    Interesting, I actually had the opposite experience (from a job placement standpoint). I whole-heartily agree that the college degree isn't worth the paper it's printed on (by the time I entered college, I could pass every course I had to take by just taking the final exam -- if they would have let me; I ended up skipping class and just showing up when assignments were due or tests were being given).

    However, I found that every job I've interviewed for, continuously looked for that piece of paper showing an applicable degree. Maybe it is geographical and the part I live in puts more focus on it than other locations, maybe it is the industry I was focused on getting into, who knows. But I will say this.

    Research it in your area and in the places you think you may want to work in the future. If your location doesn't care if you have a degree or are willing to over-look it based on your experience and knowledge in the field through self-study, by all means, save your money and skip it. In fact, land the job, and hope they have a tuition reimbursement benefit that you can utilize. You can then get them to pay the tuition and you will still get the degree you desire so much.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Research it in your area and in the places you think you may want to work in the future. If your location doesn't care if you have a degree or are willing to over-look it based on your experience and knowledge in the field through self-study, by all means, save your money and skip it. In fact, land the job, and hope they have a tuition reimbursement benefit that you can utilize. You can then get them to pay the tuition and you will still get the degree you desire so much.
    Absolutely agree.
    "First make it work. Then make it better."

  8. #8
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    It's a long process that only comes with practice. Once you move beyond asking "How can I solve this?" to "How should I solve this?".

    In general, I'd say applying a couple of principles to your code will demonstrate to you how to code is better. It's not immediately obvious what advantages they give until you've used them in real projects. The benefits come to you when you try to use your code and realise how flexible and easy to maintain it is.

    1) Favour composition over inheritance. I actually removed 99% of "Extends" keywords from my codebase and it became a hundred times better. It wasn't until I did it that I realised quite how much I was coding to work around inheritance and using it where I really shouldn't be.

    2) Make all class variables private and avoid getters/setters unless they are absolutely needed. This goes hand in hand with 1) but it will help you achieve better encapsulation, which is a fundamental principle in OOP.

    3) Dependency inejection. Once I started using a dependency injection container, I realised that most of the code I had was messy. Creating objects arbitrarily is messy! Try IoC (inversion of control) and you'll quickly see the benefits.

    4) Law of demeter: http://en.wikipedia.org/wiki/Law_of_Demeter Apply this and your code will become better. It's not immediately obvious if you don't understand it, but it forces you to think about the dependencies your classes have.

    5) Unit testing. Once you start writing code that's easy to test, you have code that's easy to isolate and therefore, reuse.

    That's my top 5 tips for going from "advanced" to "pro".
    Some very solid advice here.

    Unit testing is something that took me a while to really 'get'. The problem was that I'd write my code first and then throw some tests together afterwards. I didn't really see the point in it, so I stopped doing it.

    After reading about test driven development (TDD), all of that soon changed. With TDD, you write your test FIRST, before you even write your code. You then write the code and keep running the tests until they pass, and then keep going. If your code is hard to test, you refactor it until it's easy to test.

    Doing this massively improved my code quality + gave me much more of an assurance that my code worked. It's also crazy how many bugs you find while you're developing that you wouldn't have found until much later down the line. It also forces you to become a client user of your own code earlier, so you get a real feel for how it's going to work in practice, often leading to changes in the design and API you're creating.

    I'd highly recommend reading up on TDD and investing some time in getting to grips with PHPUnit.

    *Edit: Also worth a read: http://www.phptherightway.com/

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    @bit101010 ; Found this today, and thought you'd like it.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •