Archive for the ‘web’ Category

Local Web Apps

Wednesday, April 27th, 2011

I think I’ve finally settled on the architecture that makes the most sense for data collection types of applications for the iPhone. I just do them in HTML and use the webkit control everywhere.

Of course I need access to sqlite and so I’ve found I can add new subclasses of NSURLProtocol to provide handlers to access different parts the local machine’s resources.

The first and most useful one I did works with urls of the format sqlite://database/table?a=&b=&c= where a,b, and c are field names. If this is used with a form that has its method set to POST, then a table that can hold all those fields are created and an insert statement is generated to save the record. The response is a JSON dictionary of the resulting record (done to provide the generated primary key back as well as any set default values).

If it is used with a form whose method is set to GET, then all the mentioned fields are fetched, and the ones that have values are used as filters. The response is again a JSON array of dictionaries. This makes a quickie search form easy, however I also look for a field named sql and if that is present, I just execute that as the query instead. Sometimes only SQL will do.

If the form method is DELETE, then the matching records are deleted. Since responses are JSON, using jquery is a no-brainer.

The entire NSURLProtocol subclass is about two pages of code and works with RAILS style form serialization naming conventions to allow saving/retrieval of hierarchies. It also uses ActiveRecord naming conventions and requires a primary key field of id on each table. The primary key is generated as a guid.

Works great. Dead simple. Don’t even need a server. I will be exploring this architecture more.

I’d forgotten what a lame pile J2EE is

Sunday, October 5th, 2008

I’d kind of sworn off doing Java a few years ago but a little contract fell into my lap that seemed like it would be some quick cash for not too much work. I already had a lot of code in the can that would help me do it quickly. Also, I still have IntelliJ 6, which can make Java almost tolerable.

Unfortunately, part of the system required a servlet to handle http requests (using http as an RPC mechanism). I’ve used Jetty in the past with good results so I downloaded it. Despite the existence of a “plugin” for IDEA to work with it, the debugger never worked.

So I moved on to Tomcat. I finally got IDEA configured to use Tomcat, the debugger worked, but the servlet was ignored every time without any kind of error message being logged. Did it fail to link or something (it used a lot of external libs I had to bring in). No clue. I simplified the servlet to just printing “Hi there” and still it refused to load.

This resulted in a refamiliarization with web.xml files and all the rest of it. In disgust I switched back to Jetty. Jetty at least logged the errors to the console and I fixed all the link issues, but still no debug. Back to Tomcat but it still wouldn’t load my servlet at the url I wanted. Eventually, I found the invoker servlet settings, turned that on, and the servlet began to work.

The bottom line is that the entire J2EE architecture, the servlet containers, the zillion xml files specifying garbage I never want to change anyhow, all of it is MUCH TOO FRIGGIN COMPLICATED FOR WHAT IT DOES. Too many descriptors. Too much config. Too much cargo cult xml.

Compare to PHP where I just drop a file in a folder under document root and I’m good to go. Or rails, which is pretty much the same deal – just putting the file in the folder ought to be all that’s required to make the thing work.

I think this will be my last foray into Java hell. At least for a few years until I forget how stupid it all is again.

Summer of Rails

Sunday, September 21st, 2008

I’ve now worked on three different Rails applications. One of them was from scratch, the other two I took over from someone else. The thing I like most about Rails is Active Record – it just works and it is easy to use – even for existing databases (although it takes a bit more work to specify the mappings).

I have a project coming up that would probably be a great Seaside candidate. The database has to be postgresql (according to the client). There is a native cocoa component – I’ll probably give BaseTen a try. For the web component, the obvious candidates are Rails (although I don’t know the state of Rails with PG – only mysql), and Seaside/Glorp – but I need to use Glorp to work like Active Record since the DB will be the master source of record for the schema.

Sadly, it doesn’t look like Glorp’s ActiveRecord on Squeak is ready for prime time, I might have to kind of finish that implementation.

Rails is Magic

Thursday, May 22nd, 2008

And I hate magic. First, I confess that I probably still don’t have a full command of all ruby’s features – I’m just getting the hang of mixins and some of the wacky compositional capabilities.

I’ve just deployed my first soup to nuts rails application. Well, nearly. It certainly starts fast. Generate ActiveRecord classes for your tables using scripts and you’re off and doing basic CRUD.

However, its the little things that made the experience less than satisfactory. First – the changes in behavior moving from development to deployment were nerve wracking. I have rails running under apache on my laptop, no problem. On my production server, I cannot get byte one to come out of rails. Webrick works fine. Mongrel works. Rails cgi produces no errors, and no output. Even apache logs are totally silent. I don’t get it. For now it is running under mongrel – but I’ll have to put that behind apache and front it using modproxy. Irritating as hell.

Second, I set up memcachedкомпютри втора употреба on the advice of friends and was going to use it for my session cache. But it turns out that objects don’t get saved in the memcached – apparently you can only store plist kinds of structures. Objects get dropped. I spent several hours beating my head against this using the usual hammer for this nail – require_dependency. However, after listing every blessed model class as a dependency, it was still dropping a collection of objects. Back to the file based session cache.

Another thing that drove me nuts is all the magic values you can’t use for attribute names. I inherited this database and admittedly a bunch of columns and tables are stupidly named – however I kept running into problems with collisions with ActiveRecord extensions.

Another thing – camel vs underbar lowercase. You generally specify relationships as lower case names, that ActiveRecord uses to infer a class name. For instance, you specify the relationship as purchase_order and it figures you have a class PurchaseOrder that keeps its data in a table called purchase_orders with a foreign key purchase_order_id. This can all be overridden, but understanding which form to use where got pretty trying.

Reciprocal relationships – at some level of circularity, ActiveRecord falls over with stack level too deep on save. It isn’t even a very complex graph that does it in. It became necessary to remove a bunch of back references to get a save to work properly.

Overall, I’d say towards the end I spent more time debugging magic gone awry than I did building application functionality. So I have to chalk it up as a real learning experience, but not one I’m looking to repeat anytime soon. The lack of decent debugging facilities was really crippling – especially coming from seaside. ActiveRecord is cool, but it isn’t trouble free. Doing basic inheritance was a huge exercise in wackiness I’m not eager to repeat. If I hadn’t had a big old mysql database to build on top of, I probably would have used seaside instead.

So enough slamming – its not all bad. One thing that helped a LOT was the discovery of ActiveScaffold AS is AMAZING! I was able to throw together a coherent admin interface with it very quickly – its customization options are very powerful, and in the end I think the back office app will be about 80% AS and 20% task oriented workflow. That’s brilliant. A data driven sensible ajax interface almost instantly. Very cool.

I may do more ruby apps, there are some seriously powerful go-fast kinds of technologies, but much of the time savings this go-round was lost to flukey behavior that changed from environment to environment, and really lame debugging tools.

Rails is definitely a very mixed bag.

Quick Ruby Thoughts

Tuesday, April 29th, 2008

I have to say I’m liking a lot about Rails. Ruby, not so much. Probably the most annoying thing about Ruby is the syntax. It is MUCH too complicated and after working with it for awhile, I still don’t quite understand all the rules. Things that puzzle me:

dot notation vs non-dot notation. When to use which?

collection.select {| x | x > 5 }

vs

collection select {|x | x > 5}

they both seem to work. Also, use of parens around argument lists – also seems to be optional. Two different block definition syntaxes is also annoying.

Less syntax would be most welcome.

Hoppin’ on the Rails

Friday, April 4th, 2008

I’ve got two new clients – on is taking over expansion of an existing Ruby on Rails application. The other is the replacement of the application I wrote in the previous article. I want to stick a new codebase on the existing database. Since rails excels at CRUD and I’m short on bandwidth and hand-off-ability is a concern with the new development, I’m going to use rails for that one too.

I mean, I can only learn so many frameworks at once. So here we go – working through Agile Web Development with Ruby on Rails.

Software Design Tip: Minimize Number of Languages

Tuesday, April 1st, 2008

I was recently asked about taking over support for an existing application. I’ll leave out what it does – suffice it to say it is web based, has a simple 3-5 page UI for the public to buy something, and about a 15-20 page set of back end interfaces for trained customer service and admin people to use. So less than 30 screens overall mKay?

The application was said to be written in Java. I know Java – I don’t like it, but I know it. If its small, I could be persuaded to pick up the maintenance.

However, I got a source drop and I was totally appalled. First, it suffers from the usual Java framework-itus.

Its J2EE – so we got Jetty container. They used Hibernate – so we have generated Java code based on some XML schema files. There’s also a mysql database – which duplicates the information in the Hibernate XML schema files. It uses cocoon – cocoon make use of xml and xsl to define navigation and transformations. There is also reporting that uses xsl. Workflows use flow – more xml only they used the Javascript extension so the workflows are actually defined using server side javascript.

Got all that? We have Spring, Coccon, Flow for Javascript (flowscript), Hibernate, Jetty, Javascript, Html, CSS, SQL, XSL and god knows how many dozens of distinct flavors of XML. For a 25 page web app. Wait, did you notice I didn’t mention Java? There is Java – the Hibernate generated classes are used – but indirectly – they may as well not exist at all since all the application code is some fractured XML or Javascript fragment stashed who knows where.

It seems we’ve lost track of something here. “Locality of Reference” In general, all the stuff that deals with the product selection page ought to be visible by looking into the file representing that page, then maybe drilling into components. The problem here is that, everytime I have to drill down, I have to switch languages. And context switches are bad for programmer productivity – mKay?

I’ve turned down the job. I don’t have time to learn all that junk for this little app. The client needs a new installation – for 25 pages that do mostly CRUD to mysql. If I do it, I’m thinking plain old PHP with an ORM. If I can find an ORM for PHP.

So far I’ve looked at Doctrine (not yet ready for production but it looks cool), Propel – and some others. The really off-putting bit is their slavish insistence on creating the xml mapping file – just like Hibernate. Of course, I have an existing database. The XML file they want is in the db. It just isn’t XML. Still, all the information is available for query – so why are they bothering me with this junk? Read the damn schema and make me some classes. I’ll eliminate the many to many mappings by hand. Sheesh. No wonder there’s a software crisis.

Hey framework people, stop making me write monkey code – figure out how to eliminate extra work – not make it. One meta model is enough.

Who do ya gotta do at Google

Tuesday, March 25th, 2008

Google wouldn’t know harmful content if it sucked them off for $50.

Google! Fix this stopbadware flagging nonsense!

They are totally unresponsive despite repeated requests for review. They don’t even mention what they object to – I’ve read their guidelines – I see no problems. As far as I can see – Google IS the badware.

Google boycott starts now. Because this is evil.

Mike Arrington, Software Pirate

Monday, March 24th, 2008

The ever clueless and abrasive Mike Arrington says something even more ridiculous than usual. I can see both sides of the Bebo thing and frankly, social networking makes me yawn. I have no patience or interest in it. Seems like a phenomenal waste of bits to me. Musicians uploaded their music without expectation of compensation. So sure, they’re probably not ‘entitled’ to a payout. OTOH, Bragg’s point is well taken – the musicians made them successful and it would be a nice gesture to give back. But I wouldn’t hold my breath on that. They’re internet entrepreneurs. Thus greedy bastards by definition.

OTOH, the thing that really ticks me off is this little comment by Arrington.

…it costs exactly the same to produce one copy of the song (the first one) as 10 million copies. Simple economics takes over. Free.

Which, if true, implies that Microsoft ought to be giving away Vista, Office, and everything else. Because Music is Software. It costs as much to develop as software, it takes every bit as much time, talent, and skill.

Just because you can make a second copy for a buck, doesn’t mean that’s all it is worth. If it costs $30k to record a song (which is kind of typical these days), and we are expecting to sell 100 copies, then this song needs to make $300 per copy to break even. If its 10 copies, then its $3000 a copy. The same economics apply as software. Just like there is free software, shareware, and commercial software, there are many business models around music. No single model is right all of the time.

Arrington should stick to his little blog about the shiny things – he obviously knows fuck all about the economics of creation.

Curse You Google!

Thursday, March 20th, 2008

A friend sent me an email telling me my site has been blacklisted by Google – largely because some spammer (die, spammers, die) hacked a message and put a bunch of link spam in. I really have to question the security of wordpress. If they can’t keep it clean, I’ll have to migrate to something else.

There is an interface to request removal from the blacklist, but while you can be blacklisted in seconds, it apparently takes several days to get off of the blacklist. Nice.