I know. That's a kinda fluffy title isn't it? You're going to have to trust me when I say that this is important stuff. This chapter is about your confidence as an up and coming developer. Learning is hard, but don't worry; I'm going to help you through this.
Developers are robots.
Why did you decide to pursue development? No, wait! Let me guess. You saw a rockstar PHP developer swagger out of a Limousine into one of New York's hottest night spots, order 5 bottles of Cristal and spend the evening chilling with Jay-Z and the ghost of Tupac.
It's true, a developers life is a glamorous one. I have to write these chapters within my 5 hours of sobriety a day. You've probably seen a developer writing some code and thought...
Oh man, that dev must be a robot. They know all of those code words and functions and how they all work.
When people without development experience approach developers they assume they are genius types with mathematics honour degrees. Perhaps this is true for some developers, but it's certainly not true for me. I'd like to think that other developers would agree.
The truth is, we're not perfect. We're not even close to perfect. If you think that developers know all of these PHP functions and snippets from memory then you are fooling yourself into thinking that you will never have the capacity to keep up.
It's just not true. We don't memorise everything. In fact, a majority of the code that we use day to day is from reference. We are google warriors. There are functions in PHP that do the most simple things to lines of text, and I look at the PHP documentation almost every week to find the order of the parameters that I pass into them.
When I'm completely stuck I'll try using Google to see if another developer has found a similar challenge. Often I'll find a suitable solution that another developer has discovered, or enough information to point me to a solution. Of course this works both ways, I'll try and give my solutions back to the community. I'll post answers on Stack Overflow and I'll contribute to forums or discussions. It's important to give back to the community.
So you see, we aren't robots. We don't know everything about the language, and we don't have a solution to every problem. However, we are fantastic researchers. We are opportunists. We are resourceful problem solvers. We are developers.
The art of Googling
When people tell you to Google something, it's easy to take it as an insult. Or perhaps sarcasm? It's not. Google is our homepage for a good reason. Let's learn how we can find answers to common development issues.
We're writing a program, and somewhere we need to reverse a sentence so that 'Pandas rule!' becomes '!elur sadnaP'. We have no idea how to approach this task. We're just getting started with PHP.
We know that in PHP a sequence of text is called a 'string'. We know this because we didn't give up on this crazy book with the Panda examples, and we discovered this fact in a later chapter. Right?
So we know what we want to do. We would like to reverse a string. Let's construct a search query for google.
reverse string
Nope, wait! The problem here is that there are thousands of programming languages. Seriously, computers have been around for a while!
If we search for 'reverse string' then we're going to get answers for C++, ASP.NET, Erlang, you name it. Our focus is on PHP. We don't care about these other languages. We'll have time to play with them later when we become PHP masterminds. Let's fix this problem by adding the language to the search query.
php reverse string
Perfect. Let's take a look at the results that we get back from our Google search. This might be a good time to mention that I don't work for Google, and I'm not working for commission. Feel free to use Bing if you prefer it, but you might end up buying a used horse trailer rather than finding a string reverse function. So where are those results?
Reverse a string - PHP
http://www.php.net/manual/en/function.strrev.php
Reverse a string with php - Stack Overflow
http://stackoverflow.com/questions/11100634/reverse-a-string-with-php
By asking the right question, we receive some useful resources in return. The PHP Manual (sometimes known as the PHP API docs) and Stack Overflow are two of the most useful problem solving resources for PHP available on the internet. I'm not saying they always have the right answer. There are other great sites too, but I'm sure you'll see a pattern in how often your searches result in browsing pages on these two sites.
Right now we're looking for some sort of tool to reverse a string. We're not really looking to solve an abstract problem, we know exactly what we want.
Go ahead and click that first link, we'll be greeted with the lovely PHP manual page for a function called strrev()
. You don't need to know what a function is yet. Don't worry if this is over your head.
Once you're up to speed with functions you'll see that this PHP manual page offers all that we need to know about using the strrev()
function, and examples of how to use it.
You see by asking the right questions we received all the help we needed to continue with our work. We had no prior knowledge of the strrev()
function, but instead we knew the problem that we had to solve. That was enough to lead us to the solution. It doesn't matter if we have to go back to this page later.
Perhaps we don't use the function frequently enough to need to remember its usage pattern. Although, you'll find that if you begin to use the function more and more, and that you frequent the manual page, then before to long you won't need guidance for that problem. You'll instantly think 'Hey I should use that strrev()
function that I use all the time, and I know exactly how it works!'. It will become muscle memory, and will be part of your toolset.
So the lesson that I'm hoping you have learned from this chapter is that you shouldn't panic. You don't need to remember everything, and it's perfectly natural to ask for help. In fact, it's human to ask for help, and it's human to learn from your experiences.
Congratulations! You're a human, not a robot.
My books are available online for free to encourage learning. However, if you'd like for me to keep writing, then please consider buying a digital copy over at Leanpub.com.
It's available in PDF, ePub, and Kindle format, and contains a bunch of extras that you won't find on the site. I have a full-time job, and I write my books in my spare time. Please consider buying a copy so that I can continue to write new books from the comfort of my sofa!