Sunday, October 17, 2010

The danger of Javascript

As I use more and more AJAX on my applications, and thus more javascript, I am impressed by the power of the language, but have one really large concern.

With server side programs, one has complete control over the environment, and the client, other than some CSS issues, is not that great an issue.

However, with javascript, the code is being executed by the browser, which means one is at the mercy of a limitless number of interpreters. I have found numerous cases where one browser worked differently than all the others, with real consequences. Such as:

  • IE7 cannot properly create radio buttons with a pure DOM creation of the objects. There is a workaround, but it is bizarre, and I would never have figured it out. Luckily someone else did (You have to add html code the document.createElement call)
  • Safari returns the typeof on an array of objects as a function. All the other browsers I tested return the typeof as 'object'
  • IE7 actually throws an exception if you mispess lightgrey in CSS.
And that was all just last week. I'm sure others have more examples.

So, while javascript really does turn web programming into an interactive environment, it comes at a price. And a question: When do you stop supporting older, non-compliant browsers? IE6 is off my list already, and I would do the same with IE7 - but I have too many users that are trapped on IE7 due to large scale use of terminal servers.

Saturday, September 19, 2009

bluej

I'm taking a new class at Capella for java programming. The class uses an IDE called bluej. Of course, the text explains how to install it on OS X and Windows, but no mention was made of Linux. A little digging found out how to install it on Linux:

First, there are installation instructions for all non-OS X/Windows machine, which involves a straight forward java app instalation:

java -jar ./bluej-252.jar

The app asks for the jdk directory for your system. As a complete java novice, this is where I had to dig a little. For fedora it was /usr/java/jdk[xxx] (where xxx is your version).

Also - one should create a directory for bluej, and the obvious place is /usr/java/bluej

It's trivial, but it would be nice if the install app could figure out the jdk directory for you.

Friday, August 21, 2009

I had an interesting run in with mySQL corruption the other day. At about 1:00AM, under deadline, I was restoring a mySQL dump to a reporting server, when I got a message something like "illegal character '/'"....and the backup died.

I scratch my head, did a new save, copied it to the report server. Same result. Google searches were less than helpful. I started experimenting.

Long story short - the problem was (lightly) corrupted tables.

I went to /var/lib/mysql/[account] and typed: $ mysqlisamchk *.MYI | grep "ld be che" to find the corrupted tables.

I then ran repair table [table] within the mysql shell.

Resaved, and happy days, all was working.

mySQL needs some better error messages.

Monday, December 29, 2008

The power of eval

In my programming environment we use PHP and javascript as our primary programming languages. One very handy construct that both of these languages have is the eval statement, which essentially allows a text string to be converted into and executed as code.

An example in PHP:

if(strpos($cToolTip,'$')) {eval("\$cToolTip = \"$cToolTip\";");}

An example in javascript:

eval("day.onclick= function() {goToDate('" + xday + "');};");

In the PHP example, we are checking if the string $cToolTips has any embedded variables (which always begin with a '
So, if we have:

$fubar = 'abc123'
$cToolTip = "Once upon a $fubar night"

After the eval statement, $cToolTip = "Once upon a abc123 night"

The javascript example, while functionally similar, has another very important advantage when programming in js. Lets say you have a loop, and within that loop you are creating a new elements on a page, and are assigning onclick events to these elements. So far, so good.

However, in our example,

eval("day.onclick= function() {goToDate('" + xday + "');};");

Note that we are assigning xday as a paramater in the goToDate function. This is great, except for one thing. If we did not use eval, every time we incremented or changed xday, it would change in every function in which it had been used.

Thus, the eval statement lets us, in effect, turn a variable into a constant so that we do not have to worry about the value of that variable once the eval statement has been run. That can be very handy.

Saturday, August 9, 2008

I have always been of the opinion that words have meaning, but sometimes I am not sure if this view is shared. In particular, I am troubled by the meaning of the word 'science' in 'science fiction'.

I have always thought of Science Fiction as fiction that is based on the extrapolation of the impact of scientific and technological advances on the human (or alien) condition. Further, the science and technology should have some real basis in science, i.e., what is postulated should be theoretically possible.

Today I received a multi-paged ad from the Science Fiction Book Club. However, like the Science Fiction section of most book stores, it was only about (at best) 30% SF - the majority of the books were horror, fantasy, and semi-porn 'art' collections. Science Fiction is a vastly different genre than the horror-fantasy genre; the former is based on the reasoned application of science, the later is based on whatever the author wishes to pull out of their ass. They are very, very different.

Which takes me back to my point that words have meaning. I would kindly ask the book sellers of the world to take the horror-fantasy titles out of the SF section; I am tired of looking in vain through the SF section for SF books. It degrades the SF genre to associate those other titles with real SF. It confuses the general public as to what SF really is ("Just dragons and naked girls - sorry son, you can't read that!").

In this era where Science and Fantasy are so easily and casually confused in the public arena this would be a small step in making sure that we can distinguish between what we wish were possible and what really is possible.

Regards,

David

Sunday, August 3, 2008

Unsung Hero


Over the past several weeks I have introduced several people to Dia, and all of them were astounded and wondered why they had never heard of this program before - so here it is.

Dia is a diagramming program for Linux (has a windos port as well) that performs all of the basic functions of Visio(tm); Depending on one's skill, very complicated diagrams of any process can be created in this program and saved and/or exported to a variety of formats, including .png, .gif, and and a visio compatable format.

Dia has an extensive library of templates and the ability to import images. If you are a python wizard, you can create new extentions. Etc.

My main reason for using Dia is to communicate with non-technical co-workers. Many times a diagram can communicate technical problems in a manner that the non-technical can understand. It provides a common reference that does not have to rely on technical jargon.

There are other diagram tools for Linux, some of which have nice features, but I find that I always return to Dia because it is just easier to use. This may be due to the fact that I know it best, but I think not.

If you have another (Linux) diagram tool that you like better, let me know why!

Sunday, June 8, 2008

Its the little things

I have been a fedora/RedHat user for a long time, and still am, where servers are concerned. However, I've started using Ubuntu on the desktop, and I'm impressed so far.

I started using Ubuntu because it was the only Distro that would work on my new laptop, a Dell Inspiron 1525. I tried Suse, Debian, Fedora, and several distros that came free in some Linux mags; they would install but not boot, or boot but not recognize major elements (USB, network, hard drives, etc.). I went on line and found that Dell was selling this machine in Europe with Ubuntu, whereupon I downloaded the latest Ubuntu and the rest is history. It works very well.

With one small glitch.

When I use vim, there was no context highlighting. I googled around and found this vim command:

:syntax on

So my question is: Why, why would this function not be turned on by default as it has been in every other distro I've used. What is the reasoning?

There are other weird little things. For instance, Dia on Fedora: When one is exporting a graph as a .png or .jpg, on Fedora Dia will ask you to define the size the graphic file (pixel width x height). But not on Ubuntu, with the exact same Dia version. Why? There is a way around this, of course, which is to run the export from the command line.

These are very, very minor issues. But why do different distros have different defaults for these very common applications? This, at least, should be standardized across all platforms.

Regards,

David