Sunday, September 4, 2011

When to use "have had"

I have occasionally encountered people who use the phrase "have had" improperly.

I do not say that they use it "wrongly" but "improperly" because I always remember my days as a kid, of one of my English teachers' admonition - "there is no such thing as wrong English".

I know that some people of purer linguistic species also prefer that there should be no such thing as "no such thing". Anyway, the admonition was there is improper usage, inappropriate usage of English but never "wrong English". The only possibility of having "wrong English" is getting married to the "wrong English" man/woman. Or, "wrong Russian/French/Chinese/etc". The usage of English, no matter how bad or unacceptable, is always "correct" as long as the grammar used is consistent so that a set of gramatical pattern could be formed.

Therefore, statements such as "thar ain't nobody who loves me", regardless its double negatives, are "correct" English according to the grammatical patterns of those who speak it.

On the other hand, many of us, myself included, prefer to use patterns of communication in English that are acceptable to either the Queen of England or the President of the United States (except for the years between and including 2001 and 2008).

I have occasionally come across people who use the possessive-past participle "have had" or "had had" in patterns such as

"I have had played football."
"I have had eaten my lunch."
"I had had been to Tokyo."

I have a vindictive feeling against such masterbaiters of the English language that they have fallen into the trap of attempting to impress their listeners with their "ability" to use the phrase "have had".

Alright, OK, super-mega-tov - if you wish to impress people with your "ability" to use the phrase "have had", at least do it properly and acceptably.

Let us look at the case of "eat lunch".


Simple Continuous
Present I eat lunch I am eating
lunch
Future I will eat lunch I will be
eating lunch
Past I ate your lunch I was eating your lunch

Present
perfect
I have eaten
lunch
I have been
eating lunch
Past
perfect
I had taken
lunch
I had been
taking lunch

And the past perfectly imperfect is - I have had eaten lunch.
Which is "unacceptable/abnormal". Let me tell you why.

The word "had" is the past tense of "have". "Have" is often used in place of words like "eat". Have is a possessive. I have a friendship with the President. I have a friend.

"I am having lunch" is the same as saying, "I am eating lunch".

Tensewise, saying "I have had lunch" is the same as "I have eaten lunch".

Therefore, saying "I have had eaten lunch" is equivalent to saying "I have had had lunch."

With this in mind, you can safely use the phrase "have had", when "had" is meant to replace a verb such as "eaten", "taken", "seduced", etc.

"Have" in place of these words has a special effect. For example, a seductress in the office boasting her exploits would say,

Statement Implication
I have the boss the boss is mine
I am having the boss at this hour, the boss is mine but tomorrow you may have him
I have had the boss I managed to conquer all odds in demolishing the boss and that had been a great experience, but now you can have what remains of him
I had had the boss once upon a time, before having the current one, I had managed to have the boss - I am no longer interested in exploiting him now.

Should you say, "I have had a friend"?

Normally, you would say "I had a friend". However, when you say, "I have had a friend", it bears negative implications of what you might have done to your "friend".

I have had a baby = I have experienced pregnancy.
I have been had = I have been taken advantage of.
I had had lunch = I had taken my lunch.


Let me tell you what is worse than hearing "have had eaten" - hearing someone say the malapropism "had have". And, worse than the worse is, of course, hearing "I had have eaten lunch".

I had have lunch = I had eat lunch.

Holy cow!

Friday, September 2, 2011

PointConfigurator in GWT HighCharts


This is a special post written specifically as an illustration to an enhancement request for GWT HighCharts project in sourceforge, because unfortunately, I have not found any way that sourceforge discussion editor could allow me to insert pictures. However, it might also be informative to anyone interested in deploying client-side/javascripted charts within GWT.

I need to be able to configure Points while the Points are being created/loaded into a Series object. I would set out to extend the Series class and over-ride the addPoint method. Unfortunately, the lone constructor of Series class is protected by package-private (aka default) access restriction.

I have no-eye-deer over why we should not use protected constructor rather than package-private, except in the case of putting up an ineffective barrier against any extension to the class. Which is pointless because I simply spoof the package namespace. Alternative explanation could be, to catch the exception that if someone had caught a good-eye-deer, to encourage that good-eye-deer be placed into the pot of roast for everyone else to enjoy. Alright then, here is the good-eye-deer that the general public should enjoy.
package org.moxieapps.gwt.highcharts.client;
import org.moxieapps.gwt.highcharts.client.Point;
import org.moxieapps.gwt.highcharts.client.Series;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONValue;

public class QSeries extends Series {
  public QSeries(BaseChart <Chart> chart, PointConfigurator cfgr){
    super(chart);
    this.cfgr = cfgr;
  }

  private PointConfigurator cfgr;

  @Override
  public Series addPoint(Point point, boolean redraw, boolean shift,
      Animation animation) {
    cfgr.configure(point);
    super.addPoint(point, redraw, shift, animation);
    return this;
  }

  public interface PointConfigurator {
    public void configure(Point p);
  }
}
The main eye-deer behind the class extension is the PointConfigurator interface and code inserted into the addPoint method to run the configure method just before the Point is added into the Series object. So that, I could define a PointConfigurator implementation - for example, the following implemetation that would colourise any Point or modify the Marker of any Point that falls into an "interesting" range.
  public class RangeConfigurator
  implements PointConfigurator{

    @Override
    public void configure(Point p) {
      double region =
        // inequality of area within a circle/ellipse:
        Math.pow(p.getX().intValue() -50,2) +
        Math.pow( (p.getY().intValue()-100000)/2000, 2);

      if (region< 100)
        p.setMarker(m1);
      
      else if (region< 300)
          p.setMarker(m2);
    }
    
    final static private Marker m1 = new Marker();
    final static private Marker m2 = new Marker();
    final static private Color red = new Color(222, 63, 63);
    final static private Color green = new Color(63, 222, 63);
    {
      m1.setFillColor(red);
      m2.setFillColor(green);
    }
  }

As a side dish,
  final static private Number[][] mkRandomArray(int count){
    Number[][] ranarray = new Number[count][];
    for(int i=0; i < count; i++ ){
      ranarray[i] = new Number[]{(int)(Random.nextDouble()*100), Math.abs(Random.nextInt()/10000)};
    }
    return ranarray;
  }
The following resulting plot illustrates what HighCharts GWT does not currently do, but why I made the modification to make it do.