Don’t forget

Tourism.

Work to put websites up for lots of local businesses.  Promote hotels, restaurants, artists, shops, tours, and property.   Once I get income, I can experiment with real estate, and get a house in Cuenca, a house on the beach, and maybe a hotel or hostel.

One small leap

I was reading Gavin King’s spec preview for web beans and started thinking, I should implement something like this in perl or php. Yeah, I know, crazy. I started thinking more about it.

JBoss Seam has a lot of good points. But a lot of baggage that comes from Java frameworks. A lot of that baggage comes from java, from static variable typing, from it’s automatic garbage collector. Reference counting and shared nothing statelessness, or apache MPMs (thinking perl modules, remember for a while, create at leisure, destroy at leisure statefulness) have a lot to say for it (them) in terms of stupid memory management. And I’m stupid.

I started thinking about using Python, because lists are great, remembering GNUEnterprise code that was very clean. But mod_perl beckons. Why can’t there be good Apache Modules. Maybe a master server (Apache) launching a pool of custom python or ruby servers (fastCGI) with application state is the way to go.

Anyway, I started thinking simpler. I know I don’t want to implement a complex J2EE spec. But a few crumbs of goodness would be nice. Like, for instance, a payment handler annotation. Or a data transfer annotation. Admit it, we all love DTOs, because it really is the right way to do things. ORM tools create DTOs, they’re just more complex, slow, and imprecise.

The beauty of Ruby on Rails is in ActiveRecord, but it’s just too inflexible. You end up hand coding anyway, and fighting it and start thinking about designing your DB as a collection of rows of objects. And then start iterating to search. Bad!

But a good DTO can be a poor man’s stored procedure and ORM. But who wants to maintain it. Now, of course a framework to do alot of the heavy lifting, and another one to only load the code you need is nice too, but we can start with a simple annotation. I know this isn’t revolutionary, but what if you added annotations to PHP? A quick search finds I’m not the first to think of this.

Really, DTOs aren’t specifically what I had in mind, but they’d be the most popular, and easiest to implement (naively.) But what got me going was the idea of @RequestScoped, @SessionScoped, @ApplicationScoped, @ConversationScoped (would this be a cross-application transaction) — those would be really nice. A simple include, and annotations, and your PHP Web HaX0r becomes an enterprise developer overnight. And Session scopes can be interchanged.

I know this is the path of madness Java went down, but really, a take it or leave it approach, and keeping it simple could really improve the quality of a lot of PHP code out there.

SCA_SDO looks promising, but too complex, too correct.

And another thing

I actually prefer a unit test to a type system hierarchy. That’s the tester coming out for sure.

If a foo can do something with a object of type bar or baz but not a quux, how do test that:

class Foo
{
//…
public Fooible get() { return lookupAndInstantiate(“object_id”); }
}
class Bar implements Fooible {}
class Baz implements Fooible {}
class Quuz {} //does not implement Fooible

assert(foo.get(id_of_a_bar) instanceof Fooible);
assert(foo.get(id_of_a_baz) instanceof Foobile);
assert(! foo.get(id_of_a_quux) instanceof Foobile);

I want to do this, but my compiler prevents me from testing it. I could cast, but that’d be pointless. I could build an ugly mock that has no point other than to get around the type system, but still not good.

I’m going to score 1 for dynamic languages, because in the real world, you end up getting Quuxes, especially if you want to use something like ActiveRecord; and you’ll write a lot of code to prevent it and a lot of code to get around those compiler checks, otherwise.

A simple junit rant

I’m going to make this very simple. My last junit rant (online — I think on theserverside.com) resulted in a nice email from Cedric Beust about this new thing he was working on called testNG. Oh how I wish I could use it at work. Luckily, that will be an option in 3 days, as I will retire and work for myself full time. JUnit 4 has been a blessing over 3, though dependencies and useful annotations are still sorely missed. @BeforeClass is also mostly verboten, but is allowed in special cases when it shouldn’t be used!

Anyway, this is a very simple rant, though I’m very curious about how I uncovered it.

No assertNotEquals() yet!?!

I’ve wasted time trying to find a rationale. Of course, I have found the junit addons package, but I’m not going to force my employer into that dependency. Maybe I’m missing something, but this is probably the most valid unit test. The likelihood of two things being equal when you expect them to is pretty high, and the likelihood of something being true when you expect it to is even higher. What you really want to know is when something isn’t true (not difficult, even without assertFalse(), which for some reason is religiously implemented) or more especially when two values aren’t equal.

Roundoff errors immediately come to mind, and are an ideal candidate for the architypical unit test. Date handling is another example, and string munging also makes sense. So would image manipulation, though Java isn’t a good language for that.

Anyway, how I came across this, and I’m probably just stupid, is with temperature conversions. Here’s my test that I would expect to fail:

Temperature t = new Temperature(-40.0, ‘F’);
assertEquals(-40.1f, t.convert());

And here’s the code that is being exercised:

public float convert()
{
if (scale == ‘F’) { return 5 * (temp – 32) / 9; }
else if (scale == ‘C’) { return (9 * temp / 5) + 32; }
else { throw new RuntimeException (“unknown temperature scale”);
}

Maybe I’ve spent too much time in scripting languages that do a better job of casting or something. Anyway, it’s not a big issue what’s causing my bug, but I want my test to uncover it.

NOTES:

1 – It looks like there is no assertEquals(float, float.) So it is calling assertEquals(Object, Object). Behind the scenes is it treating them as doubles, integers, or strings?

1.5 – It looks like assertNotSame() will do the trick for this particular case. Is this the answer to checking round off errors? Still, it wouldn’t work on more complex arrangements, or on bit arrays (images), right? I guess it’s fair to write your own assert for comparing images, but surely someone’s done it before.

2 – It also looks like TestNG doesn’t have assertNotEquals either. I’ll probably get another note from Cedric that it was added to and and released yesterday or something.

I admit I was a bit star struck and felt ahead of the curve too that someone with reputation responded to my message. I should start a geek celebrity sighting scrapbook. I still remember when Havoc Pennington responded to an simple question about Metacity code. He dismissed it at the time as a pet project he’d abandoned and then a year or two later it got adopted as Redhat’s default X window manager. I seriously doubt my asinine patch was ever included. But I’ve got (or had) code in docuwiki. I wanted prettier table layouts and hacked a few features into it. I think that was the point I realized that I thought I could really code, submitting a patch and getting it listed on the release notes.

Web hosting and Email VAR

I could enter the email hosting market right now if I know how.
Maybe I should pass it off to Fastmail.fm or Tuffmail.com?
Maybe I should get Exchange running or I mean get a hosted Exchange and then be able to develop apps off of it.

43 things

Top three on the page when I visited:

Travel the World

Learn Spanish

Drink More Water

All three of those are high on my list (okay, I don’t really want to drink more water, just less cokes.) So I must be keeping with the trend. I am so herd instinctive.

Focus

I need to limit my goals.  Last night’s post was good, and I’m glad I reminded myself of the bigger picture this morning.  But the real trick will be learning to pace myself and see what I’m capable of.  I tend to bite off more than I can chew and not follow through.  It’d be nice to have infinite time and resources, but I need to focus.  Saying that, I don’t want to back my self into a corner and just do something simple.  This six months will be an incubator, and after 3, I will decide whether it’s time to monetize or hunker down for a bigger investment.  I won’t make a huge investment in time or money until the 6 months is up.  I might come straight back to Ecuador and throw $20,000 into wages or even get big financing.  Or I might decide to take it easy and brew again.