Skip navigation.
Home
That which cannot be rendered in binary is by definition a delusion
 

Zend Eclipse

There is a school of coding that declares any IDE is a net loss: a lot of good coders insist on working directly with source, and can do a lot of great things that way.

I have to assume that they are also members of the anti-OOP school of thought; I cannot really see using OOP without an IDE. I have recently dragged a CTO kicking and screaming into the Eclipse IDE because it was impossible for them to digest my code without the introspection that Zend Eclipse offers.

I will be up front here: Eclipse has many down sides, chief amongst them being a fairly steep learning curve. Towards that end I wanted to highlight the features of Eclipse you need to know, and some of the features of eclipse that you should want to know because they are so ripping cool.

And a caveat. An IDE is for the most part, a text editor with benefits. Its not a substitute for coding ability and is frankly not going to "teach" you a language. This should be reassurance to those who fear or hate IDEs, and a caution to those who regard them as a panacea or a "crutch". Like a loan from the bank, the people who don't need them are likely to be the ones that benefit from them the most.

NOTE: i currrently MUCH prefer NetBeans to Zend Eclipse.

What you will have to put up with

Eclipse has a digestion process whenever it loads an existing codebase -- a build cycle that is achingly slow. The SVN module also has its own digestion cycle, wherein eclipse inputs and renders the SVN information into your file tree. The build cycle can crash the IDE. the good news: when Eclipse is slow it is "bring a good book" slow, but it is slow in blocks -- it is not consistently sluggish. Once its done its task, its response time on a significant system is pretty standard. That is to say, not lightning fast, but not terribly slow either. (It is, after all, written in Java...)

Eclipse is not by any means a streamlined application. Eclipse is an aircraft carrier. I would compare it to Photoshop or a CMS. There are huge tracts of features you will never use. Keep in mind that Eclipse is a language agnostic IDE -- it was designed principally around Java and adopted PHP late in the game. You will see many options that are simply nonsensical in the LAMP environment. For instance it has a Database layer that I just never touch, being happy with phpMyAdmin and the console. And SVN, as a seperate self-contained system, takes a bit of brilliance to integrate into your workflow. The sheer bigness of Eclipse means that it is best suited for those for whom programming is a lifetime pursuit.

What you get back

  • Eclipse gives you incredible insight into your objects, whethe through autocompletion or though the object menu (usually in the lower right). It gives you a self contained GUI for unit tests, and a wizard for creating them. The autocmpletion of object chains lets you very quickly navigate the nested tree of a complex cluster of objects. However, it is not completely automagical. Because of PHP's hybrid OOP/procedural nature, you must carefully annotate methods and variables for this to work flawlessly, and there are still going to be situations where despite your most careful annotation, the autocompletion fails.
  • Even when OOP autocompletion fails in OOP, it is generally pretty good for varialbe names. This is important becuase PHP is case sensitive (mostly). The only caveat here is that autocmpletion of variable names doesn't recognize scope; so, for instance, if your variable name resembles a variable of a code library you employ, you will have to do some deep typing to discriminate between the two variables.
  • It gives you powerful and flexible templates -- I've been expanding my template collection to write huge tracts of code consistently.
  • You can commit files directly inside the IDE and view diff's of them against the SVN repository.
  • The syntax highlighter can help you insulate yourself from thumbfingered errors.
  • Perhaps more imprtant than all of the above -- you can walk through your code with the debugger. I've only gotten this to work locally but it is a real lifesaver, as you can see system state completely at any given point in the code's execution.

What you need to know to use Eclipse

I am assuming you have some grasp of the whole LAMP stack, including Apache management. If you don't, you might find some related self-eduction is necessary to follow through on this.

  1. Before you do so: you should probably have an XAMP/MAMP stack on your computer. Eclipse comes with its own LAMP stack, but that stack is limited and more difficult to manage than a conventional LAMP stack. I'd suggest putting your projects under the control of your own local LAMP stack, so before you get going with Eclipse, make sure that you have a running LAMP stack on your desktop. For the Mac I prefer MAMP pro, because it gives me the ability to easily create local projects in any folder I want without having to mess with Apache settings.
  2. Once you have a running LAMP stack, go get Eclipse. Zend gives you a 30 day trial to play with. Download it. It has the usual install wizard -- accept the defaults.
  3. Presuming you are working in s SVN encased project, import a new project from svn to your computer. Although it has a default directory that it uses to store projects in, I'd suggest putting it somewhere accessible. There's no bad place to put a project folder -- I keep mine in my home directory. Just be sure you note where it is so you can configure your LAMP stack to redirect to this folder. (XAMP/MAMP has a default "home" folder inside its directory, but creating "virtual directories" for each independant project is fairly painless.)
  4. If for some reason you are not working with SVN you can use the "New PHP project" to start the project out. Both paths lead you through the same wizard. Other than the project name and the directory root choices, the options the wizard presents really aren't that important.
  5. Once your project builds (and builds, and builds) you will get a file structure tree showing your files. Note that while you can create folders and files and even rename them using this widget, moving a file is best done with console/SVN commands. If you ever do move a file, right-click refresh the tree in Eclipse to bring your IDE up to date.
  6. Congratulations! You now have a ten ton text editor.
  7. To get the most out of your system, make sure to add type comments to all your classes and methods. Check out the Zend Framework libraries for good examples of comment formatting.
  8. Pay attention to the red squigglies. These demarcate syntax violations. Your code WILL not run if it has any of these. They are visible at the higher level -- red boxed will appear near your file--and ALL of its parent folders -- if you have a bug. Now -- here's the fun part -- HTML violations will also kick off this warning and if you mix HTML and PHP you will often see nesting "errors" due to "bad" html when the HTML really does render validly in the context of the larger application.
  9. The Yellow "Hazards" are logic warnings. You should eliminate or at least understand all the logic warnings in your code. The chief cause of these warnings is the use of a variable in an expression without an explicit initialization of that variable somewhere in the code. There are a few legitimate/semi-legitimate ways to create these warnings -- the extract() method, for instance, will pull variables from a hash array which when used will trigger a warning, and global variables in the parent context will also not be known to the parser. (The latter is a "Best practices" violation anyway).
  10. You can right-click on a file to submit it to SVN. Select the "Team" item on the context menu to submit or update a file, with comment. Don't worry -- if there is a conflict, the process will choke, and give you a chance to update it before you submit the file.

Feeling the Power

There is a lot you can do to add to your Eclipse experience; perhaps not on your first day out, but soon and when you are ready to add to your efficiency.

Add Custom Templates

Templates will allow you to create lines of code with a single typed word. I have get/set templates, and there are built-in templates for things like loops, functions, and other common language elements

Unit Test in the IDE

You can create a unit test for a class with the built-in wizard. You will have to have some understanding of unit testing before you take this step, but if you are "already saved" this will be a reall wiz-bang thing. You will get tests for all your accessors so get prepared to wade through a lot of "junk" code for tests you will never really want to run. But its all worth it once you hit that "go" button and see code coverage inside the IDE.

The Zend Debugger

Being able to run the debugger inside your IDE will be the greatest change in your experience as a PHP developer since you found the error log. The Zend Debugger gives you the ability to stop your code at any point and inspect all the variables at that scope. You will even see error messages about things like faulty inteface implementation that you just won't find anywhere else.

Visual SVN

You can use the team menu to do much more than just submit files. You get a complete differential history against any version you want. You can easily revert, or revert tactically, some or all of your document using the GUI.

I shoud point out here that SVN saves a limited "Local history" of your work too -- if you save often, you can get a comparison of your current file against any file saves if you need to go back to a point between the current version and the last SVN save. This is useful if you are trying to keep SVN clean and have to do a lot of local development outside the repository.

Instant "Best Practice" formatting

Control shift F reformats all your code to standard PHP indentation. While this is nearly always flawless, of course, save your work before trying this out. Its a great tool to un-spaghetti someone elses' code. The code style it uses is part of the project/IDE's settings and can be chosen and customized to your liking in the eclipse preferences.

Library Bridging

If you use large code libraries like Zend Framework, you can leave them out of your project(s) and reduce your build overhead (and the load on your SVN repository). Attach the libraries to your projects and you will have read-only access to the code while keeping your projects small and easily digestable by the IDE.

The Zend Framework, or why I got into coding

The best library I've found in years is the Zend codebase. It brings ruby-style Active Record coding to the LAMP world and has a bang-up MVC system. It also has briges to a lot of web services and other tools. Fair warning: this is not Drupal/WebPress/Joomla; it gives you the tools to create web applications but doesn't come with any pre-built solutions, CSS, templates, etc. It is of course integrated with the Zend Eclipse IDE; you can create a framework project and many stubs for components quite easily but you must hit the books to use this framework effectively. One side effect of using the framework is it gives you a great kick-start into Dojo as well, a really great Javascript Web 2.0 framework. You won't find the IDE much help here, but it is worth noting what comes with the package.

The War on Carpal Tunnel Starts with You

Eclipse's fairly successful autocomplete is a big brain-saver. As long as you have successfully identiified your variables by instantiating a class in context

$my_bunny = new Wonderland_Bunny();

you can type

$my_bunny->

and pause, and a dropdown appears, listing the methods and properties of Wonderland_Bunny; clicking on one will type it out for you, and you can filter by typing the first few letters.

If a variable is out of context you need to identify it in comments:

/**
* @var $my_bunny Wonderland_Bunny
*/

$my_bunny->

But to be honest this has unreliable results. Type hinting for parameters also gives you autocomplete access, as does commentary on methds:

/**
* @return Wonderland_Bunny
*/

public function get_bunny(){ return new Wonderland_Bunny(); }

The templates below give you extra power for fast code creation in Eclipse.

How the other 0.5% live

I have tried recently switchint to the NetBeans PHP IDE; frankly I am finding it a step up (on day one at least) from Eclipse and as an Eclipse power user I find that interesting to say the least.

0
Your rating: None

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <p> <span><small> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options