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.
If you're looking for learning material, I recommend [From Flat PHP to Symfony2, [URL="https://github.com/fabpot/Create-Your-Framework/tree/master/book"]Create Your Framework book, and [URL="http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X"]PHP Objects, Patterns and Practice](http://symfony.com/doc/2.0/book/from_flat_php_to_symfony2.html). Beyond that, continue to look at the code from the best and popular frameworks, such as Symfony, Zend, Cake, and CI.
Many of the modern frameworks use [database abstraction layers and [URL="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html"]object relational mappers](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html). Although these tools may be more than you need right now. Perhaps we could help you tighten up your PDO code.
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.
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, [URL="http://www.youtube.com/playlist?list=PL5586336C26BDB324"]speak, [URL="https://twitter.com/dalmaer"]tweet, and [URL="https://developer.mozilla.org/en-US/learn"]an assorted collection of other high quality resources. And of course there's always the [URL="http://php.net/manual/en/index.php"]manuals and [URL="http://www.w3.org/TR/html5/"]specifications](http://fabien.potencier.org/).
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.
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.
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.
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".
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.
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.
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/
@bit101010 ; Found this today, and thought you'd like it.
This topic is now closed. New replies are no longer allowed.