Archive

Posts Tagged ‘Programming’

PHP Classes

June 7th, 2005 No comments

I’ve been investigating PHP classes (the version 4 kind) over the past couple of days, and I’ve now started to rewrite this website so that I use them in a more effective way.

In the past, the site was made up of a mish-mash of functions, and a variety of functions to output data in different formats (read: HTML and RSS). By turning it into classes, I can make it a much more intelligent process, and can separate (not entirely, but more than before) the application logic and display logic.

As an overview, I can tell you some of the basic details.

I have created 2 simple hierarchies of classes:

The first is the “databaseObject” hierarchy – this creates a generic base class for anything stored in the database, and then a class for each record type (i.e. database table). Further to this, I have created “holding” classes – essentially array manipulation classes.

The second hierarchy is the “formatter” hierarchy. I’ve created a base class with functions to output each class type. I then inherit this class for each output format that I want (e.g. HTML, xHTML, RSS, and others). Each one of these classes overrides the base methods (only those needed) from the base class, and formats the output according to how the format requires. This does mean though, that I need to generate the base output in the “master” PHP file (i.e. the file being executed and viewed) such as the base HTML page – but this is kind of desired anyway.

Hopefully, in the future I should be able to add facilities better, and also add output formats quite simply (without having to completely rewrite chunks of my site).

I’ll try and generate some form of UML diagram to make it a bit clearer, and post it here.

Categories: Uncategorised Tags: , , ,

Biblical Programming

May 11th, 2005 No comments

At work, we have an error log that holds all of the errors that our programs produce, and we can also put messages into it so that we can debug our programs.

Today, whilst looking through, someone has obviously taken a near-biblical slant on debugging:Hello anybody there?
In the begining
Let there be night!
And man looked apon the darkness
And the darkness was good!
pre syschar900
post syschar900
So end’s the first book
Each one of those lines has been hand typed, in that order, and so must mean something to somebody!

Categories: Uncategorised Tags: , , , ,

Announcing PHPTabs!

May 7th, 2005 2 comments

Tonight, I’ve spent the evening working a new little project of mine. It’s quite small and simple, but it could just change your life.

I’ve created a very small library to let you create a tab-control using HTML. It lets you create a simple tab set using <div&gt elements and Javascript, all neatly generated from PHP.

Here’s a quick picture:

I’ll post some more about it soon, and perhaps create a project page. For the time being, please feel free to download from here and use in whatever way you feel like.

There’s no formal documentation at the moment, and eventually I’ll get around to writing some good instructions and putting some kind of decent description of how to use it. I’m also planning to release it under some GPL or BSD licence, but I’ll get to that in good time.

There’s a good example file in the archive called “index.php”, but this should probably not be deployed with your website! The other 3 files (phptabs.js, phptabs.inc.php and phptabs.css) are all needed and should be deployed. You should also customise phptabs.css.

Please feel free to poke around and use it however you wish. If you find any bugs, have comments, would like something changed, have improved it in some way, then drop me an email – it would be nice to see how useful other people find it!

Categories: Uncategorised Tags: , , ,

I don’t get it

May 7th, 2005 1 comment

OK, this is something that I just don’t get.

It was my understanding that XHTML 1.x STRICT was supposed to be just that – strict, and that all you were allowed to put in your XHTML file was the data and the tags that describe the rough positioning of that data, and that everything else should go into a style sheet.

So basically, rough presentation and data into XHTML; colours, fonts, background pictures, etc into CSS.

So why then does the <table> element still have the “border”, “cellpadding” and “cellspacing” attributes, even in the strict DTD type? Surely those are pieces of eye candy and should be rendered from the CSS file?

Don’t believe me? Then have a look at the XHTML 1.0 Strict DTD, and search for “cellpadding” – it’s certainly in there under the “table” element.

I even checked against the XHTML 1.1 Strict standard, and these attributes are not listed as having changed (I couldn’t see to find a reference to them in the DTD on that page, but there are listed in the modularised DTD for tables here).

Can someone explain this, or is this just some piece of random thinking that slipped the net?

P.S. Found this out from here.

Categories: Uncategorised Tags: , ,

Oh My God

April 19th, 2005 1 comment

Jesus, apparently this is designed to scare Newbies to the world of Regular Expressions, but it’s just ridiculous.

Apparently, the version in the Perl Library is actually broken down and explained, but this is just silly.

I’ll give you a small quote (it’s about 80 lines long, so I’m not going to quote the whole thing….)(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|”(?:[^\”\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\\”.\[\]]))|”(?:[^\”\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\”.\[\] \000-\0

Hmm, seems I knackered this post earlier on when I did a bit of minor editting. I’ve should have restored it, but I’m not sure whether there was anything on the end. Will have to wait until tomorrow until I can be sure!
Categories: Uncategorised Tags: , ,

Grrrr!

March 18th, 2005 No comments

This must be the worst user interface that I have had the displeasure to experience.

Yeah, I’ve experienced bad looking and unfriendly interfaces before, but this is just annoying.

Check out the instructions:Use your mouse wheel to rotate the screens.And what if I don’t have a bloody mouse wheel? Huh, Genius? Oh, so I have to go through the pain of randomly clicking things? Brilliant. Tell you what why don’t you stick to your “designing”, and I’ll stick to thinking about what people may be accessing my website with.

What makes it worse is the pictures on the left don’t logically match up with the pictures on the right, and the site is painfully slow to load some really quite small images.

Just give me a list of sodding pictures and a description. It’s quicker, will work better and I don’t have to worry about which wheel I’m moving!

That’s why we shouldn’t let “designers” play with websites and software. Leave it to the people who have a rough inkling of what’s going on.

Categories: Uncategorised Tags: , ,

Software is from Humans

March 17th, 2005 1 comment

This reminds me of something that we did last Friday for Red Nose Day.

Because of the way our product works, we are able to change parts of the system quickly and easily at will (e.g. Through CSS). We decided last Friday to get into the spirit of things, and change the menu that appears on the left of the screen to be red, and have the Red Nose Day logo at the top (usually it holds the company logo). So I spent a bit of spare time here and there over a couple of days, achieving this minor miracle.

We thought we would just do this in our Development environment, and in the Testing environment for the people that do our testing, but in the end we managed to get it (with permission) into the “Live” environment which large numbers of people have to use daily.

I think it must have been something new to the company, to do something like this, but strangely we didn’t receive any major resistance to our plans. Sure, they wanted to see it before we sent it out, and they wanted to make sure that it was not damaging or unconducive, but other than that, they gave us the go-ahead. Strangely, we didn’t seem to receive any complaints about it either (I was expecting 1 or 2 from some managers, somewhere).

My worry now is that we have set a precedent for things to come…..

Categories: Uncategorised Tags:

AJAX

March 8th, 2005 1 comment

Having spent ages writing a post on Adaptive Path’s description of what AJAX is, I’ve discovered that my friend Richard is also in on the game, and has managed to write a back end for it using Lisp.

I’m still not convinced that it is the be-all and end-all of the Web, but it’s certainly a step in the right direction. To illustrate what I mean, you have to look at some of the things that I was working on today. Somebody had introduced a bug into our system because they had not considered what happened when an incorrect value would be entered by the user. This causes a load of fields to appear, which shouldn’t have appeared (they should have appeared based on the properties of an item they entered into a different field). It then took me the best part of an hour and a half to rectify this simple slip up.

OK, you’re going to get issues with this in “real” programming (I’m talking native stuff here), but never the less, the chances of it happening are increased using this method.

Interestingly, there is already an Open Source package to do a lot of this interaction for you, in the shape of “SAJAX

Categories: Uncategorised Tags: , ,

Interesting Article from Adaptive Path

February 26th, 2005 No comments

Adaptive Path appears to be some company which specialises in web software.

They have created this article which talks about a new combination of technologies that they are referring to as “AJAX” for use on web sites to make them interact more with the user.

So instead of filling in some information on a web page, then clicking submit and waiting for the web page to load before you get told that you have entered a field in incorrectly, you would fill in the form, wait a couple of seconds for the data to be validated, and then would be told on the same page that the field was wrong.

This is interesting, because we use a similar technique at work, except we go a little further with this approach. N.B. I should point out now that I don’t want to go into too much detail about this, because I’m not sure of intellectual property rights, and how happy my company will be for me to reveal certain information! i.e. I don’t want this or this to happen to me!

Basically, we have a browser application, based around the Internet Explorer ActiveX control, and then have a series of ActiveX controls which maintain and control the interaction of various input boxes on the screen, and can present data on the screen using DHTML and DOM. This can then communicate with a database using HTTP.

This approach works very well, and we are actively developing (and have deploye) several solutions using this technique. There are disadvantages though, you’re limited to the layout properties of your chosen HTML engine – which sometimes can’t be specific enough (e.g. we get “twitching” – where the layout changes by two or three pixels but this affects all the page), and some of the easy things that you would normally do in an “native” application you just can’t do.

It’s a good technique, it has it’s disadvantages, but it’s also very powerful.

Categories: Uncategorised Tags: , ,

Design By Contract

January 11th, 2005 No comments

Now here is a seemingly good idea.

Originating in the language Eifel, Design by Contract means that with each function you specify a series of predicates which dictate a class’s (or procedures) pre- and post-execution states. E.g. for a function which guarantees that an integer parameter is the absolute value of a number, you specify the pre-condition as being the input number is an integer (i.e. param.IsInteger()) and the post-condition as the return value will always be greater than or equal to zero (i.e. return >= 0)

Before and after the code executes, the contract between the calling procedure (the client) and the procedure is checked, and if either side breaks the contract an error is raised as the program has a bug.

It’s probably best if you read more about it – I probably haven’t explained it very well!

Wonderfully though, Microsoft have taken notice of this technique and are researching a language called “Spec#” which works along side the next release of Visual Studio .Net and the .Net framework.

Categories: Uncategorised Tags: