The Well-Tempered PHP Developer
The first plugin you will need for serious PHP work is named, appropriately enough, PHPEclipse. PHPEclipse has been around since 2002, and although the current stable version (1.1.8) is from 2006, there is work currently on version 1.2, and there has been a steady flow of updates, so the project still is quite alive. Getting PHPEclipse is easy; simply use the Eclipse update method, and add a new remote site (see Resources).
PHPEclipse provides not only basic editing facilities, but it also adds syntax coloring and bracket matching for easier reading; code folding, so you can hide a block or function; parameter hints and tooltips—for example, if you don't remember the parameters for the stristr() function, a little pop-up will remind you; and syntax checks (if you make a syntax error, you will get a wavy red underline at the place of the error and pop-up help, Figure 3). PHPEclipse also offers debugging (with either XDebug or DBG) and version control (CSV or SVN)—more on this below.
When you edit a PHP source file, several shortcuts and functions can speed you along. Need to find the declaration for a certain function or variable? Right-click on any reference to it (or press F3), and you will be taken there. If you are unsure about a certain PHP function, pressing Shift-F2 produces a manual—although you usually can get by with hovering the mouse over the function name.
For more prolix coding, there are several formatting functions. You can re-indent any portion of code simply by selecting it, then right-clicking and choosing Format, or by pressing Ctrl-Shift-F. You can turn lines into comments (and vice versa) by right-clicking and choosing Source→Toggle Comment, and all selected lines will get // added in front. (From now on, I skip the shortcuts; unless you are a die-hard Ctrl and Shift fanatic, you probably will use the mouse menus all the time.) Adding or removing larger comments (for example, ones like /* ... */) also is simple with a right-click, then selecting Source→Add Block Comment or Remove Block Comment. A Refactor function can help you change a variable or function name globally; there's no excuse for shoddy names anymore.
PHPEclipse is fully configurable. On the main menu, go to Window→Preferences, and select PHP. You can set your own specific preferences for most of the features I've covered (and even more that I didn't touch on here), so you can set up project standards. If more people are working on the project though, make sure everybody uses the same set of parameters. It's no fun having to reformat other people's code just because of a tabbing configuration difference. Collaboration and version control plugins are discussed below.
When your code is ready, you get Run As..., Debug As... and Profile As... commands. You can create profiles (including runtime parameters, environment variables, directories and more) and use them later with a single click. The results of the run will appear on a console, integrated within Eclipse.
When do you test your code? After everything is done? How quaint and old fashioned! Modern development methodologies suggest an iterative way of working, which combine developing automated test cases even before the actual programming is done. Having the tests available before actual development starts ensures quick feedback after any change, and it also provides design-level documentation, for each test serves as an example of what the code should do. Even more important, putting all the tests together in a test suite provides for regression testing—before any new code is committed, all pre-existing tests should pass. If a programmer makes any mistakes, changing the way a function should have worked, a well-designed test will catch the problem and alert you.
This way of programming has been named test-driven development (TDD) and is a part of many modern agile development techniques. The basic idea is simply preparing an automated test (automated means it can be run on its own, without users having to do anything, which implies that running the same tests several times a day is no chore) that exercises your code and tests the results it produces by checking assertions that are either true or false. If any assertion fails, some piece of code isn't doing its expected thing. Writing (or at least planning) the tests before writing code, makes the developer pay attention to code requirements and modularity—two important quality factors.
There are several tools for testing, generically named xUnit—for example, JUnit is used for Java development, cppunit for C++, PHPUnit for PHP and so on. Although the specific details logically differ between tools, they actually are quite similar. For our purposes, we work with SimpleTest, which is a plugin that provides PHPUnit tests within Eclipse.
SimpleTest is available as open-source code, and its latest version is 1.0.1 (from April 2008). You can download it from SourceForge (see Resources) and install it with Eclipse. After you install and configure it, a new option will be added to the Run As... menu, allowing you to execute PHP unit tests. You can run tests on their own, so you can test only a single routine, or you can build more complex test suites, so you can run lots of tests at the same time. You probably will use individual tests while coding and suite tests before uploading any code.
When testing, a simple console with a colored bar will show up. Red means some test failed (your code doesn't do what was expected), and green means your code passed all tests (Figure 4). If you get a red bar, you can click on the offending test name, and you will be taken directly to the problematic test code (Figure 5).
Due to space constraints, I won't go into how to write tests or use mock objects; check the documentation for more information. In any case, for each project you work on, you should create a second, parallel, test project. (Of course, use version control for it, as well.) Getting used to automated testing takes some time, but the rewards are high, and you may even become, as it has been said, “test-addicted”.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Stunnel Security for Oracle
- SourceClear Open
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Tech Tip: Really Simple HTTP Server with Python
- Non-Linux FOSS: Caffeine!
- Google's SwiftShader Released
- Doing for User Space What We Did for Kernel Space
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide