Friday, September 16, 2011

Eclipse PHP XDebug

Error launching 'test'. The session could not be started. In order to generate debug information, please make sure that the debugger is properly configured as a php.ini directive.

I've been developing in PHP recently, and the code base is getting large enough that debugging by using print statements is getting unmanageable. I decided to try the Eclipse IDE for PHP.

I went to the Eclipse PDT page and downloaded the windows Eclipse IDE package for PHP which is supposed to contain everything you need.

Should be quick, right? This is what I did:
  1. Unzipped the zip file
  2. Start up Eclipse
  3. Created a PHP project, and imported some of my existing php files from the file system (in Navigator, right click on the project node > Import > General > File System etc).
Then came the part where I had to tinker with all kinds of settings. After a lot of tweaking, I wound up with this setup under Preferences > PHP:
  1. PHP Interpreter is "5.1/5.2" (I have 5.2.5 installed).
  2. PHP Executable fields are:
    1. Executable path: C:\Program Files\PHP\php.exe (THIS IS WRONG!)
    2. PHP ini file (optional): C:\Program Files\PHP\php.ini
    3. SAPI type: CLI
    4. PHP Debugger: XDebug
When I went to PHP > Debug I had some trouble. I'd originally tried the Zend Debugger, and wasn't able to get it to work. When I switched to XDebug, I couldn't get the PHP Debugger window to give me my configured PHP Executable as an option; the only option was "Not Defined". I had to restart Eclipse to get the correct option (my configured executable) to appear.

Then I right-clicked on a standalone test php file and tried to debug it as a script. No joy, I got a pop up dialog with the message "Error launching 'test'. The session could not be started. In order to generate debug information, please make sure that the debugger is properly configured as a php.ini directive."

I then spent about 2 hours trying to figure out how to get this to work, and nearly gave up.

I finally solved the problem by setting the "Executable path" above to C:\Program Files\PHP\php-win.exe. Yeesh. I don't know how you're supposed to figure this one out other than trial and error. Running php.exe -i from a DOS prompt works, although it does cause an error window to pop up. Running php-win.exe -i from a DOS prompt works without error.

Once that was changed, I was able to run and debug my script with breakpoints set!

Labels: ,

Thursday, June 02, 2011

android development

I'm trying out android development for fun. I had added a subclass of Activity to my app, but found that the app was crashing because findViewById returned null when I tried to get a View in my Activity constructor:

myBlah = (Blah) findViewById(R.id.main);
myBlah.etc ... <== throws NullPointerException


I guess there are numerous ways this problem can occur, since I searched around on the web and found several different solutions, but none of them helped me. In my case, it turned out that I had called setContentView on the wrong xml file in my Activity constructor. For example: setContentView(R.layout.main); instead of setContentView(R.layout.view1);.

Once I fixed this, I was able to get beyond the problem and start debugging the next issue! I don't know what I'm doing yet, so I don't understand why I got a null return value here.

Labels: , ,

Tuesday, August 03, 2010

Aptana IE quirk

I'm working on a small application using Aptana Studio 2.0.5.

There's an html page which imports a Javascript file near the top. I decided to reorganize my Javascript file, and blam! the page stopped working in Aptana's "IE" view (the tab that appears next to the "Source" view). I checked out the page in Firefox 3.6.8, and it worked fine. Then I checked it outside of Aptana, in IE 8, and it worked fine there too!

Aptana's IE view is not a necessity but it is kind of handy. So I wanted it working again. Plus the fact that it wasn't working might mean there's an issue in other browsers.

By trimming the Javascript file and throwing in a couple of alerts, I figured out the problem: an extra comma. My original Javascript file ended like this:

manager = {
xMax : 12,
yMax : 12,
}

It was the trailing comma that killed the script in Aptana; once I removed that the page worked fine again. Do you want to play "spot the Java programmer"? In Java, trailing commas are allowed in arrays, and I sometimes use them when coding in Java.

So: are trailing commas forbidden in Javascript arrays? Way back in December of 2009 (practically prehistory), Amaxus said:
The most common IE problem we encounter is trailing commas in arrays. It doesn’t cause problems with Firefox, but it’s syntactically invalid and crashes IE.
That discussion was about IE 7, and apparently IE 8 is more lenient. However, the JSLint page says that trailing commas are a no-no in Javascript, also. I should probably run my Javascript through JSLint at some point.

Labels: , , ,

Tuesday, September 15, 2009

NFJS: the final word

Overall, for my 2009 conference experience, I was slightly disappointed compared to last year, when I also attended and was pretty much blown away.

As a reminder, I had come down with a cold a few days before attending, so that colors my experience. I missed two sessions because I was sick, and that didn't help. Since I wasn't feeling well physically, I wasn't as alert in many of the talks as I normally would be. Also, I didn't feel like I could very effectively take advantage of the networking opportunities offered by the conference.

Even taking that into account, I still think there were some minuses this year. I think part of the problem was that there were five competing sessions planned for each hour, but one of them was pulled a few days before the conference started, for economic reasons. In some of the sessions, with just four choices (yeah, I know, "just" four choices), I didn't feel strongly about attending one or the other, and wound up being disappointed.

So here's my advice for NFJS: if you're thinking of attending during a recession year, just keep in mind that the number of sessions might decrease after you've studied the schedule! In any case, make an effort to study the slides before each session. I did this for some of the sessions, but not all, and I wound up regretting it.

To be clear, my experience was positive, overall. I still think this conference is much better than others that I've attended (not that I have much to compare it to). However, now that it's over, I do wonder if I should have skipped this year and spent my money on something new, perhaps a couple of smaller conferences. I'm glad I attended, but there's a niggling doubt about it.

Labels:

NFJS Day 3

On Sunday, I attended Day 3 of NFJS. I went to three talks by Nate Schutta. The first was a Javascript review ("JavaScript: the Good, the Bad, and the Ugly"). I've always leveraged my Java skills to get what I needed done in Javascript. It's not something I use a lot. So this talk fit my interests pretty well. I think someone with strong Javascript skills would have found this to be a snooze, but that was pretty clear from the description of the talk. It was "just right" for me.

The next talk I attended by Nate was "Seven Habits of Highly Dysfunctional Teams". I didn't enjoy this talk so much. The title and description were misleading. The first item on his list of seven was "Planning the Plan". The topic revolved around how management insists on a fixed date for when the project will end, and how hard it is to plan that. However, that is not a habit. I don't think he meant to say that planning is a dysfunctional habit, and I'm not really sure what he was getting at. For this item, he also spent an inordinate number of slides describing how, despite numerous safeguards, the plan for building his own house met various obstacles. That metaphor was way too extended.

The next item on his list was "Solutions vs Problems" - how the client often comes to you, asking you to build a particular solution. They don't tell you what the problem is they're trying to solve, and their solution may not be the best one. It's up to us to extract the problem, and then help them find a solution. That's all fine, but I already knew it, and how does it relate to habits of a dysfunctional team? Overall, I didn't find this talk worth attending. I'd recommend you skim the slides before going to be sure this is something that's worth it for you.

I also attended Nate's "Hacking Your Brain for Fun and Profit". This was one of the talks in the last session. I thought it would be a nice way to wind up the day, since I was feeling pretty overloaded by then, and didn't want to think about anything too technical. Unfortunately, again, it just wasn't very useful to me. Most people who pay attention to these things will know the drill already: you need plenty of sleep and exercise to function well, context switching is deadly, etc. Some of the references and links from the slides might prove useful, but after sitting through most of the talk, I wished I'd attended a different one.

The best talk of the day was Stuart Halloway's "Agile Retrospectives". Stuart is a very dynamic and intense speaker, so I stayed pretty alert throughout the talk. He used part of the session as a retrospective about the conference, to help demonstrate how retrospectives work, and to get feedback on the conference. This was useful to me, since I've never been involved in a retrospective, and it may be helpful down the line if I ever am. It was also just useful in pointing out ways to keep people involved during meetings - have people move around, break out large groups into smaller ones, etc. This was all good stuff for me. I was familiar with some of it, but it was a good reminder, and there were a number of tips I hadn't encountered before.

Labels:

Sunday, September 13, 2009

NFJS Day 2

Two of the three NFJS sessions that I attended yesterday were great, for different reasons.

One of these was "Testing with dependencies", presented by Venkat Subramaniam. It was great because it was a useful talk, well done, one that might actually help me in my work. The focus was on using mock objects in your tests so that you don't have to rely on external resources (like the file system, or database connections) to run them. He explained why you might not want to rely on such resources, gave some nice concrete stories to illustrate how he had used mock objects on real projects, and knuckled down with some code examples. He did the coding live, during the presentation. Normally I think this is a mistake - it takes too long, and too many things can go wrong. But he handled it very smoothly and quickly, so it turned into a plus. He made the point that you can "hand toss" your own mock objects - the talk focused mainly on this kind. So you don't have to work with a framework such as EasyMock or Mockito if you don't want to. He wound up by showing a simple example from EasyMock.

The other great talk was Ted Neward's "The Busy Java Developer's Guide to Java7". The talk is probably not going to be useful to me, except if I go on an interview where they ask about exotic identifiers. However, since I'm usually buried in work, I don't spend much time keeping up with the latest developments. This was a nice review of what's to come. On top of that, I find Ted's talks very entertaining - he's not shy about expressing his opinion, and I like his sense of humor.

In addition, I attended Craig Walls' talk about Spring 3.0. This talk was not up to snuff when compared with the others I'd attended. I think it had more to do with the way he presented things than anything else. The other speakers had a vibrant enthusiasm for the information that they were dispensing. With Craig, I got the feeling that he was either tired or not very interested. It may have been the former; he mentioned that he had arrived at 5 am that morning, which couldn't have helped. So I wouldn't write him off as a speaker based on this experience.

The last session I attended was the Birds of a Feather (BoF) session. There were two this time, "Architecture" and "Languages". I chose the "Languages" session, with Scott Davis and Ted Neward, mainly because it was the end of the day and I knew that I'd find Ted Neward entertaining, no matter how tired I was. And I was right. After sitting in on this session, I may even give Scala a try.

Labels:

Saturday, September 12, 2009

NFJS

Last year, I attended NFJS, even paying my own way. I'm back again this year because it was such a good experience.

This year, my only disappointment so far is that I happened to catch a cold right before the conference began. I'm snuffly, sneezy, and tired. I missed the last session and the dinner yesterday, because I was too tired, and went home early. I'm missing the first session this morning as well.

It's especially disappointing because I like to spend time speaking with other attendees. But right now I feel like a plague carrier, so I'm trying to stay away from everyone as much as possible. Oh well, there's always next year.

Yesterday, I attended the first two talks by Brian Goetz - "Effective Concurrent Java" and "The Java Memory Model".

In "Effective Concurrent Java", the first suggestion was to document thread safety in your code, perhaps using annotations. I think that wouldn't fly where I work... Later, Brian delved into things that I might be able to use, like making more objects immutable, where possible. This was a good talk, with lots of food for thought.

The same applies for "The Java Memory Model" talk, which revolved around how multithreading can result in weird, scary stuff happening at runtime. This is another talk where I'll have to run through his slides a few more times to really absorb it. There's one problem with this talk. When giving examples, only very simple code snippets are used. It's hard to imagine how or where you would come across these problems "in real life," especially if your current application is running smoothly right now.

While listening to these two talks, it occurred to me that Java applications can be run in many different contexts - within a container, as a standalone application, on machines with a single processor or multiprocessor systems, etc. Brian should put more emphasis on the context in which we need to worry about these problems. He did mention it in a few places, but I think it should be emphasized and discussed more. His later talk, "Are All Web Applications Broken?", might have gone into this more, but I missed that.

Brian is a good speaker, although he's not as dynamic or splashy as David Hussman or Ted Neward. His speaking style is similar to Paul Krugman (to be clear: style, not content!). His talks are more like academic lectures. Don't get me wrong; they are not boring! I think his topics are among the more hardcore ones at the conference, with lots of really useful information. I attended a couple of his talks last year, so I was expecting to get high quality, useful tech talks again. And that's what I got!

Labels:

Friday, May 18, 2007

file date comparison in perl

This is a little sample code that shows how to compare the last-modified time for one file with that of another in Perl:

#!/usr/bin/perl
use strict;
use warnings;

my $ofile = "/home/wereldmuis/oldfile";
my $nfile = "/home/wereldmuis/newfile";
open(FO, $ofile);
open(FN, $nfile);

my @info = stat FO;
my $oftime = $info[8]; # file modification time in epoch seconds

@info = stat FN;
my $nftime = $info[8];

my $current = time(); # current time in epoch seconds, just an example

if ($nftime < $oftime){
 print "$nfile is older than $ofile\n";
} else {
 print "$ofile is older than $nfile\n";
}

Output is "/home/wereldmuis/oldfile is older than /home/wereldmuis/newfile".

Labels: ,