3 Ways PHP can make you a better programmer.
Posted on 10.09.2010 06:51 pm
I officially entered my programming world with PHP in October of 2001. I actually took a simple "blog" script I found online, took a whole weekend to get it to work and turned it into a site for a Counter-Strike clan I was in at the time.
Later I got better and I ended up working as a PHP programmer for a small web development company here in Iceland. For all that time I knew nothing but PHP. I had tried some other languages but not something to write home about.
So when I started studying Computer Science, I had to work with C++, C# and Java, languages that can be called similar to PHP in syntax alone.
C++ came pretty quickly too me, it's still a huge mystery but I was able to do a prototype tower defense game relatively quickly. C# and Java came even quicker and I think I have PHP to thank and here's why.
Duck Typing teaches you to manage variable types in your head
With PHP, you create a variable like this.
$var = 5;
$var = "String";
$var = array("Array", 5, array("Fun", "Stuff));
You'll notice that I do not define the type of $var anywhere and I can send into it whatever I please. I can even mix the array with whatever type I want.
When you have a programming language with a feature like this, you start storing the type of all variables in your head. I did this a lot back in the day and thought nothing of it.
Now when I'm doing C++ work I can see some fellow students struggle with managing types, get types confused with others and relying on hints from the editor.
So I think working in a language that forces you manage types yourselves is a boon later in your career.
PHP makes you appreciate having a large set of built in functions
PHP has A LOT of built in functions to aid you in solving whatever problem you have in a relatively simple manner.
Need the unix timestamp for next monday?
$var = strtotime("midnight next monday");
Need an array of the common values of two arrays?
$var = array_intersect($array1, $array2);
And so on.
So when you work with a language like C++, the number of handy functions drops significantly, also having functions like that simplifies your program to a degree. So you have a tendency to create the simplest solution with what you have, since that is what you did in PHP.
This of course does not always work but you try to enforce this tendency to create simple things and end up abstracting heavily to keep things as simple as possible.
PHP never got in my way of solving a problem the wrong way
I'd think up a way to solve the problem, blurt it out to PHP and more often than not, I'd be 80% of the way there. It wouldn't be the most elegant solution but "what the hell, the server can take it".
Looking back on it, wasn't the best code but that's how you learn, by laughing at your old code.
So when turning to big bad monster C++, I had gotten to know most of the wrong ways to make things since it made PHP cry. So you might think of PHP as training wheels for programmers.
P.S.
This can of course apply to many other languages, PHP just happened to be my first love.
5 9 Like it or hate it? - Comment (4)
Dirgo
0 3 / Posted on 06.10.2010 09:57 am
I actually enjoyed the post until I got to the part where Jimmy and Dupolec commented.It amazes me how arrogant most coders are (pardon me, "programmers and computer scientists"), it makes me itchy (Oh GOD! Take the code out of my clothes!!!).
jimson
9 0 / Posted on 10.09.2010 09:55 pm
Funny how the title says 3 ways and only 2 are mentioned. Like the php solutions, 66% there.dupolec
4 0 / Posted on 11.09.2010 07:46 am
One way PHP can make you worst programmer in team:$var = strtotime("midnight next monday");
$var = array_intersect($array1, $array2);
wtf dude? use:
strtotime, and arrayintersect, or str_to_time and array_intersect. code should be easy to read, and it just creates mess
Ólafur Waage
0 3 / Posted on 11.09.2010 11:44 am
@dupolec those are built in functions.Yea PHP's naming conventions for functions are not great and there is a lot of negative things you can say about PHP but those have been said a thousand times before.
I wanted to shine a little positive light on how PHP made me a better programmer and how it possibly could for others.
There are bad PHP coders and there is a lot of bad PHP code, but this is not always the case and a little positivity these days can't hurt.
Process time: 0.007981 seconds