Reality is a perception. Perceptions are not always based on facts, and are strongly influenced by illusions. Inquisitiveness is hence indispensable

Thursday, September 25, 2008

Global Singletons, Good and Bad

I am just quoting my opinion someone elses article. The actual article can be found at:
singletons-are-pathological-liars


Why is global bad? Yeah, I know what your are thinking, and no, I am not joking. There are certain languages like JS which are quite powerful and yet have limited ability to comeup with walls (modularity).

Global is bad because:
a. It causes namespace conflict
b. It exposes the state in a unwarranted fashion

When it comes to Singletons
a. The explicit OO way of calling them, prevents the conflicts, so point a. is not an issue
b. Singletons without state are (like factories) are not a problem. Singletons with state can again fall in two categories, those which are immutable or write once and read many (config/property files). These are not bad. Mutable Singletons, which are kind of reference holders are the ones which you are speaking of.

Now if they are designed to act as application cache, you may see a lack of adequate cohesion. So what do we do! Using the pathelogical lies analogy, hide the unpleasant details, in private methods or in interfacing Adaptors (IOC). Make sure that these kinds of singletons are restricted to above sections of code and for the rest of application they become person-nongrata. Finally when you test the application, you won’t see the singletons. Not fool proof, but just makes it a wee bit difficult to accidentally modify things.

If we are exposing state of instance to Singletons in any other way, it is a bad OO design.

Quoting Dalai Lama, “Know your rules well, so that you can break them”.

Appreciation and Irony

Today my mail box is bombarded with mails, all showering appreciation for some work I did last week. Am I happy? yes I am guilable. On the other hand, I am still trying to maintain the vulcanistic composure, I have quite a few good reasons too. After the toil of working for 5 years, this is the first time I am put in limelight! The unfortunate part is that, I did quite a few things in the past which would exceed the current 'achievement', if it is the right word. Most often, my peers and superiors would show their admiration, verbally and sincerely. Today it is different. Lets see how.

I am working for a client, who happens to be contractor who manages third party contractor. I am with one of the third party suppliers. There was an issue, which would affect the whole design framework. I wouldn't spell out the issue in the current post, thats not the point anyway. The proposal for that solved the problem without causing any major design changes. So our client and the actual authority were really impressed. This caused a cascade of mails. When you prepare a recipe, or shoot a nice picture, you would like knowledgable people to acknowledge it. People without the intimate understanding of nuances just follow the crowd. When you see someone buying a camera or tv, they go with the brand. These would seldom try new things, no matter how good they are and this has nothing to do with being acquainted with the product.

The cascade caused the senior management of our company, just jumped the bandwagon. Now, I know some really good tasks carried out by some of our team, I personally did some stuff which overshawdows the current task. The chance of not being able to give a solution was alway lurking around. The difference was, in the exposure I recieved this time. Thinking of all those old times, I just wonder at the ways persistance pays, when you least expect it. This political embargo I am carrying with me probably will get some mileage during my review meetings, but the baggage of my team members staring at me like they used to do when you top your class or play that crucial shot in a field game, is unwarranted.

I just get a feeling that things are overdone in real world, and have to remind myself that even olympians are forgotten

Friday, September 12, 2008

Lost world

Typical applications of ANTLR would be in parsing domain. My first interaction with ANTLR was for a data generation application. We had this system which consume huge xml streams. The schema types were defined via xsi and testing the code for all conditions was inhumane! Even coming up with data for functional flows was painful. So the solution was to comeup with a template of the xml (using schema) and another template for possible datatypes. Parse the template, create a inmemory tree and walk the tree several times (using custom java code). We picked up a random domain value for substitution for each walk and ended up having a comprehensive data sets. There were certain correlation problems though and it was a different story.

I am writing this as I became a bit nostalgic seeing http://blog.centuryminds.com/2008/09/antlr-tutorial-dependency-injection-language/. Err when was the last time I learned something new!?

Working with non-semantic elements

Most often, when a web page is putforth for review, the reviewers look for typical 'classitis', 'divitis' problems. Use of pseudo selectors needs more in depth inspection. Use of non-semantic entities are most often frowned upon. Infact the foremost guiding principle for a good html page, is to leverage the page content for styles (and not styles for content). Atleast that was what I thought of till date.

Recently when coding for a tricky piece of java script behaviour. I happened to come up with a simple solution that violated the guiding principles. The exact problem is irrelavent, but just to satisfy the curiosity, it has something to do with footer behaviour which varies with the page content. The crux of the solution was to rely on certain invariants on screen (images in this case) and position/scale/stretch my footer. What appealed the most was the idea of introducing non-obtrusive style invaraints at a template level and use them as guides to setup the behaviour rest of the page.

How about having an 'gif' border around the content or a absolute/fixed positioned images? Most of the time there may be some, if they don't why not introduce an element of transparent gif (not for spacing purpose). The intention is to simplify the javascript part, especially computing offsets and widths becomes a lot more easier. Just to clarify, this idea/pattern suits only code relevant to behavioural aspects. (The presentational aspects should be in CSS alone).

The next time, someone asks me to align textboxes or labels (from a behavioural point), I will definitely consider this approach.

Saturday, September 6, 2008

Google Chrome and abberations

Chromes on the face of it looks great! Today while trying out the POC for a problem we ran into, I encountered this wierd fact. Chrome is still in beta phase, and there is a long learning line anyway.

My guess: I can only say that, !important rules are ignored on stylesheets linked using js.(no speculations!)

Without much fuss, some code snippet. Sorry for not being able to host this on a site

The html block

<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : longdiv
Created on : 06-Sep-2008, 09:59:00
Author : kanthi swaroop

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>TODO supply a title</title>
<link type="text/css" rel="stylesheet" href="../css/demo.css"/>
<script src="../js/adjustLayout.js">
</script>
</head>
<body>
<div id="header">
Some space
</div>
<div class="outer">
<div class="left">
<span id="long">
longtext____longtext____longtext____longtext____longtext____longtext____longtext____longtext____longtext____longtext____longtext____
</span>
<span id="short">
The plain stuff
</span>
</div>

<div class="right">
DON'T__BLOCH__ME____DON'T__BLOCH__ME____DON'T__BLOCH__ME____DON'T__BLOCH__ME
</div>
</div>
</body>
</html>





There are two files, demo.css and override.css, using js we attempt try to include the override.css when necessary. override.css applies only to standard compliant browsers.

demo.css



/*
Document : demo
Created on : 06-Sep-2008, 10:06:20
Author : kanthi swaroop
Description:
This stylesheet is supposed to be overridden in special cases via java script.
*/

* {
margin : 0;
padding : 0;
color : #000000;
}

/*

#long{
display:none;
}

#short{
display:block;
}

/*
*/
#long{
display:block;
}

#short{
display:none;
}

root, div {
display: block;
border : 1px solid #000000;
}

body {
font-size: 62.5%;
font-family: Arial,Helvetica,sans-serif;
height: 100%;
background-color: #9999ff;
}

div, span {
font-size: 110%;
}

span {
background-color:orange;
display: inline;
}

body, .outer{
margin: 0 auto;
width: 1024px;
}

.outer {
position: absolute;
height:100%;
overflow:auto;
background-color: #999999;
}

.left {
float: left;
}

.right {
float: right;
}

.left, .right {
/*height: 10em;
*/
height: auto;
width: 49%;
}



override.css



/*
Document : override
Created on : 06-Sep-2008, 11:12:35
Author : kanthi swaroop
Description:
The following are to be overriden only for standard compliant browsers.
I know, I am using !important.
*/


.left, .right {
width:100% !important;
clear: both !important;

_width:49%;
_clear: none;

}




Java script


Some java script.


/*
The script part
Author: kanthi swaroop
*/
window.onload = function adjust(aEvent){
aEvent = aEvent || window.event;
var newLink = document.createElement("link");
newLink.href = "../css/override.css";
newLink.rel = "stylesheet";
newLink.type = "text/css";

var hasChildren = document.body.hasChildNodes();
if(hasChildren) {
document.body.insertBefore(newLink, document.body.firstChild);
}
else {
document.body.appendChild(newLink);
}
alert("Bye");
};


Sunday, August 17, 2008

Questionning questions - Rashmon

Most often we hear people asking for concise and compact answers. This is only acceptable when the two parties share a common understanding of the context. Due to the inherent ambiguity of the natural languages is the cause of the problem. More so, if one of the parties tries to play with words (showoff!) and other ignoramus obiliges.

An example of this is the popular illustration: "Panda eats, shoots and leaves" vs. "Panda eats, shoots, and leaves". The difference is that, of a panda doing what pandas do, or a clinteastwood western classic.

More dangerous are the glitches that show up when some one with a uncanny knack for finding loopholes (lawyers!) comesup with a ridiculous conclusion that wasn't even half expected. This makes, usage of simple language and active voice, of paramount importance. I have recently read a joke to illustrate this:

David and John were walking by a church. David suddenly had one of those electrifying moments and popped a question to John.
David: "John, is it ok to smoke and pray at the same time".
John: "Why don't we ask the preacher."
David: "Ok" (goes into the church)
David: "Father, Is it ok to smoke while praying to God?"
Priest: "Son, such things are unacceptable while praying"
(David comesout and tells John)
John: "Are you sure about that? I will go and ask once again" (John goes in)
John: "Father, Is it ok to pray when we do other things in life"
Priest: "Son, It is the most ideal thing to do"

(Moral: Ask the right questions to get the right answers)

In the movie "Rashmon" the director Akira Kurosawa, showcases the human eccentricity in narration and interpretation of the events. Life would be a better place, if every interviewer/questioner deals with fact finding than interpretation.

Friday, August 8, 2008

Pleasant surprises

Every one who has worked with UI designers (people who swear by Fireworks and Photoshop) know how insolent they can be. We laymen, find it difficult to appreciate how much effort has gone into a button or some other image, until we put things side by side. Programmers don't care for the gloss that shows up, designers and end users do. So do sales folks. Never ignore the fact that it is the cream that sells the cake and not the crust.

When you see a button, you should feel like clicking it. Not like the button images that the current template uses. A button bulges up, takes a large font and has a finish that pops out. Like Disney’s animal pictures, with huge eyes and soft texture. These are achieved by tinkering around opacities, gradients, crops and colour combinations. Sounds simple, next time try going for a round of shopping with a bunch of girls. You can appreciate the nuances (rather forced to).

After all, we are not Borg, we do have individual tastes. That said, the next time you go shopping dont' forget to check the cakes' crust as well!

Popular Posts

Labels

About Me

Well for a start, I dont' want to!. Yes I am reclusive, no I am not secretive; Candid? Yes; Aspergers? No :). My friends call me an enthusiast, my boss calls me purist, I call myself an explorer, to summarise; just an inquisitive child who didnt'learn to take things for granted. For the sake of living, I work as a S/W engineer. If you dont' know what it means, turn back right now.