Thursday, April 30, 2009

What's wrong with HTML and CSS??

W3C says:

Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. Additionally, when used with graphics, these tables may force users to scroll horizontally to view a table designed on a system with a larger display. To minimize these problems, authors should use style sheets to control layout rather than tables.

But style sheets are not capable of reasonable layout. Not only is the design of CSS layout overly complex and obtuse, but the specification is so poorly designed and written that no two browsers are consistent in their implementation of it - not even two subsequent versions from the same vendor!!

What makes this even more bizzare is that before designing CSS there was a working model: HTML tables. It would have been easy, and sufficient for most purposes, to provide in CSS the layout capabilities already present in tables. This need not have precluded other layout options, but at least there would then have been one reasonably sane and reasonably well understood (i.e. amenable to consistent implementation) means of laying out pages with CSS.

As it is, I will continue using tables for the foreseeable future.

Wednesday, April 29, 2009

It's hard to be helpful

It struck me again this morning how difficult it is to be helpful.

Comments and suggestions may be taken as criticism, particularly if they relate to someones core beliefs, values, passions or achievements. And criticism, perceived or actual, often elicits defensive reactions that inhibit further communication and learning.

As a result, it can be difficult to get someone to think about and understand a new or different idea and more so to get them to accept that it is valid or has merit.

I quite like the quote in this post. on PerlMonks. If I understand correctly, this is a quote from Tagakure. I will have to read this to see if it is the true source and if it is generally of the same quality as the quoted passage.

There are recent translations of Tagakure available from Amazon and elsewhere. There is also this version, which purports to be a copy in the public domain. I Don't see it on Guttenburg or Internet Archive, which makes me wonder if it is actually in the public domain. The Wikipedia article also has a link to an on-line copy, though I don't see any statement about copyright there.

Wednesday, April 22, 2009

Perl Objects

Perl Objects

What is an object in Perl?

An object is a reference to an item (anything that can be referenced by a reference) that has been blessed.

An object is created by first creating a reference and then using the bless function to bless the referenced item with a package name.

For example:

$reference = {};  # here a reference to a hash but it could be to anything

bless $reference, "Some::Package::name";

The bless function requires a reference as an argument but it modifies the referenced item rather than the reference itself. It sets a flag in the referenced item that indicates that the item is an object and it records the package name as an attribute of the item. With this done, any reference to the item can be used with the arrow operator (a.k.a. dereference operator) for method invocation.

It is the facility of method invocation that makes objects different from other variables.

Method invocation is a means of calling a subroutine. It differs from regular subroutine invocation in two respects:

  1. the package name with which the referenced item was blessed is passed as the first argument to the subroutine, followed by any explicit arguments; and
  2. a runtime lookup of the method name is performed to determine the subroutine to be called.

For example:

$ref->method($arg1, $arg2);

$ref->Package::method($arg1,$arg2);

The method name may be unqualified or qualified with a package name. If it is unqualified, lookup of the subroutine begins in the package with which the referenced item was blessed. If the method name is fully qualified, lookup begins in the specified package, regardless of the package with which the referenced item was blessed.

If the package has a subroutine with the same name as the method name then this subroutine is called.

If the package does not have a subroutine with the same name as the method name then lookup is repeated in each package in the list (@ISA, 'UNIVERSAL'). The @ISA array is a package global and 'UNIVERSAL' is a package that is part of the Perl core distribution which defines several basic methods. As each package may have its own @ISA array, a depth first search of these arrays is performed.

If no matching subroutine is found after this search then the search is repeated but searching for AUTOLOAD rather than the named method and if an AUTOLOAD subroutine is found then it is invoked for the method.

These mechanisms are simple, but the ramifications and possibilities are not.

Because methods are resolved to subroutines at runtime (a.k.a. dynamically), interesting things can be done. Sometimes these are interesting in the sense of wonderful, amazing, powerful and good, but sometimes they are interesting in the sense of the curse: may you live in interesting times. 

Wednesday, April 15, 2009

perl system on windows

On Windows systems, if the first argument to "system" is a number or integer and not a string it is taken to be the mode of the spawn call that creates the process to run the command which, in this case, is specified by the second argument to system. Allowed values are P_WAIT or P_NOWAIT as defined in process.h. These are usually 0 (synchronous execution - calling process waits until the spawned process terminates) and 1 (asynchronous execution - calling process continues to execute concurrently with the spawned process) respectively. Other values are not supported by perl and will result in system returning an error (-1) without running the command. The default is synchronous execution (P_WAIT).

Labels