And I’m going to learn it.
You are currently browsing the blog archives for July, 2013.
So tonight I decided to try and use Composer, a “dependency management” tool for PHP. I’ve had my eye on doing this for a while, and finally got to it tonight.
I use a custom rolled version of PHP 5.5, because I want to actually use the new functionality that PHP has
finally added. So, on to the install I went.
curl -sS https://getcomposer.org/installer | php
Already, the first critique here, I’m downloading a file and piping it right on into PHP. I’m not going to go into that, because this guy already has. So, on to the next step, after I took a quick poke through the installer code I downloaded.
Woops, need to recompile my PHP binary without
--disable-phar. Now, done that, I ran the installer again, and had a clean install this time.
Next step, create a composer.json file after running through the Composer install steps. I wanted to use Zend Framework, so I copied the snippets of composer JSON from this site and assembled them into a coherent composer file (not the easiest thing, since the Composer manual didn’t seem to have a nice example file linked somewhere that I could find).
My basic composer.json file:
Next, ran a
composer validate composer.json on my file, and got this output:
composer.json is valid for simple usage with composer but has strict errors that make it unable to be published as a package:
See http://getcomposer.org/doc/04-schema.md for details on the schema
name : is missing and it is required
description : is missing and it is required
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
After a quick look over the messages, I decided to soldier on anyway, crossed my fingers, and ran
The installer seemed to laugh at me after it downloaded the files, and told me that I needed to
--enable-zip before I could install the packages. THANK YOU COMPOSER, for mentioning that on install.
Another recompile, and finally I managed to get Composer to behave.
- Composer needs both PHAR and Zip enabled to work, but doesn’t like to mention those things
- Custom PHP is fun to do, but can be a pain when you need to turn things on that you didn’t plan on using
Global variables are a code smell. This statement is both true and false. What is true is that they are a problem when they are no longer the right variables to be global.
Today I had to re-factor a function to be able to use multiple servers inside one script instance. Initially, the server connection was created and stored in one variable that was then referenced. This worked well, because the code that called this function didn’t have to worry about what server connection was involved.
Of course, the problem started when I added a second server into the mix. Now, this function had to be able to access either server, selected by the code in some of the places that called it. The easiest way to solve this would have been to keep the global and add a second optional parameter to override it, but that would not be as clean a fix as just fixing the global.
And so I re-factored the function call to pass in the server connection to use. This makes the function more flexible, because I can add new servers to the mix and just pass in the variable for the one I want to use. The other benefit is that in eliminating the global, this function is now finally completely self-contained, making it that much easier to test and fix.
Globals can be useful, but will make it harder to properly test a function, and complicates matters if the function that uses them is widely used and has to be changed.
Choose carefully how to use them.
Yesterday’s lesson was that the better solution to a problem usually only becomes obvious when you’re almost done solving the problem.
Sometimes, in fact many times, we are faced with the difficulty of what to work on. With so many projects and tasks, and so little time to complete them, it becomes as much work to decide what to do as it is to do it.
Today, I’m faced with that decision.
Do I work on the projects that I have been working on, that is a ranked and prioritized task in my current contract work list?
If I do this, then I make money, and I get one step closer to closing this project.
Do I depart from the list completely, try to take a step to freeing up time later on by working on automating some server build processes?
If I do this, then I make money, and I get to reduce the time I spend next time I have to build these servers.
Do I depart completely from paid work and instead put the time into my own project?
This would give me personal satisfaction and maybe down the road I might earn money.
Do I even want to spend this time behind the keyboard? Should I instead go do something to make the place I live a little better/cleaner?
Well, it’s house tasks, so I have to do them eventually. If I do them now, when I’m a little tired, then I can focus on work when I’m awake and rested again.
Or do I slack off and watch some TV, take a small mind vacation?
‘Nuff said about this.
It’s these decisions that we make every day. This isn’t even a developer thing, but rather just an everyone thing. We all have to make these kinds of decisions all the time, working out the benefits and costs in our head to decide where to direct the time we have.
Tonight, I think I’ll be a little productive and work on actual paid contract work.
This is part of being a contractor, working whenever you can focus enough to get some time done. And that leads into the next thing to write about.
One of the challenges we face every day is getting work done. It’s kind of different from working in an office, where just showing up is enough to get paid. As contractors, we have to focus and work, and we only get paid when we do. Sometimes it requires so much discipline to sit down and write code, to grind through the problem we are on, instead of gaming for a few more minutes, a few more hours. The benefit and the drawback of working from home is that you can do whatever you want.
Work in a towel after just stepping out of the shower because I didn’t want to put on pants? Did that.
Take a phone call and play with my cat at the same time? Have the scratches to show.
Play Minecraft for 3 hours because the code I was working on was boring and I got stuck? Absolutely.
Volumes have been written about this, about how so many people burn out doing this kind of work and have to go back to an office job.
I’m proud to say I’m a freelancer, and that I work from home.
It shows I have the discipline to keep logging hours.
Speaking of which…