Saturday 25 January 2014

Get It Write Coder

“BriNg It On
      I Am ReaDy to faCe It
        ImPossible is Nothing.”

In this second article of mine, we talk about coding techniques and how to get it right when writing code.
Coding is an art that requires a diligent, methodical mind and the need for focus, coding is a meticulous activity, a single slip causes a 10 step reversal that can cause 100 hours to fix. It was
getting cold, last I read it was 3 deg and getting colder, She walked over to the fireplace, “A methodology was in place and now I just have to code for the project.”
I smiled inwardly and keeping the same countenance, “You sure you can do it ?”I was thinking of the times that I had tried to convince her and always found her going the other way, she did detect a smirk and countered,”I can do whatever I want to today.”  She stood up and challenged me to an arm wrestling match immediately, I agreed not knowing what to expect and I was at loss for words, I am a big built man and normally beat people at this game easy.

Group Photograph Coder
This is so cool, that coding part, its like we get to our work place whenever we like and take a seat and start writing code.  So I have this project on building snowflakes on to a web page, it is pure HTML, JAVASCRIPT, I look at the specification sheets and start to write :

<script language="JavaScript1.2" type="text/javascript">
<!—Here we set the JavaScript version! -->
<!-- This script is provided free at Lissa Explains it All -->
<!-- http://www.lissaexplains.com -->

<!-- Begin
var no = 15; // snow number
var speed = 9; // smaller number moves the snow faster
var snowflake = "snow.gif";

var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i, doc_width = 800, doc_height = 600;

Note the difference in styles, now for the below code, some coders would write the two brackets “( )” and start filling up the code of the bracket next, “(ns4up) while for others it just a matter of writing the opening “(“ bracket, write the code and then close the bracket, “)”.

<!—checking for browser version and adjusting automatically -->
if (ns4up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
} else if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
Now in the same above code, see how the variables are named, there are conventions for setting this, you could write for example doc_width, or doc_Width or Doc_width as the variable name.
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();

Arrays are software code that can store numbers just like mathematical arrays.  Below is how we populate arrays by setting a FOR loop by incrementing “i “

sty = new Array();
for (i = 0; i < no; ++ i) { 
dx[i] = 0;                        // set coordinate variables
xp[i] = Math.random()*(doc_width-50);  // set position variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*20;         // set amplitude variables
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random();     // set step variables
if (ns4up) {                      // set layers
if (i == 0) {
Just as I was going to write more on the below document.write function, she popped into the  office,”Got time for a cuppa coffee.” I immediately agreed and walked with her to the vending machine, “Damn Machine always has me stumped, sometimes the tea gives out coffee and also the other way around,” she said,”You handle this and I will get us some cookies,”she walked over to the counter, while I fiddled around with the machine still trying to get the document.write function into my head.  It was DHTML and the document.write always wrote to the page what was presented to it at the position specified by the code.  I looked left and it said coffee, I pressed it at the exact centre and a stream of coffee flowed into the cup, there was this sign saying, I figured, “COFFEE,” that was smudged and that is why she sometimes got tea instead of coffee.  We sat down for a cup of coffee with the cookies, I had settled into a rhythm and sipped my coffee quickly waiting to get back to the work station.

<!—Writing the Layers -- >
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
} else {
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
   }
} else if (ie4up) {
if (i == 0) {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
} else {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
      }
   } }

Now we define the function for Netscape navigator as well as Internet Explorer,

If i leave here 2marOw
wOuld yOu Still RememBer Me ?
For i mUst be tRavellinG nOw
cAusE There's tOo maNy pLaCes
 
I've gOt tO seE
...

Browse browse (http://knowledgeisgreat.in/)said the bird on the wall and that’s what browsers are for, travelling, visiting places, each with their own nuances and settings that must be adhered to, sometimes a max resolution must be set in the code so that the travel is not hazy and blurred or even distorted.  Finer points of life I have learnt ever since I started coding for various versions.  Still getting a hang of the Opera Mini though, had me stumped for a bit because it would go through the corporate firewall to places I liked visiting.

function snowNS() {  // Netscape main animation function
for (i = 0; i < no; ++ i) {  // iterate for every dot
yp[i] += sty[i];
            if (yp[i] > doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
            stx[i] = 0.02 + Math.random()/10;
            sty[i] = 0.7 + Math.random();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
dx[i] += stx[i];
document.layers["dot"+i].top = yp[i];
document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowNS()", speed);
}
function snowIE() {  // IE main animation function
for (i = 0; i < no; ++ i) {  // iterate for every dot
            yp[i] += sty[i];
if (yp[i] > doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
            sty[i] = 0.7 + Math.random();
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx[i] += stx[i];
document.all["dot"+i].style.pixelTop = yp[i];
            document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowIE()", speed);
}
if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}
// End -->
</script>
In conclusion writing code requires a very typical mind set, some are born with it and are naturals, others develop it through learning and practicality.  If it were up to me, I would do this Software Engineering course at the City University, London,
Software development is a central activity in the IT industry and a degree in Software Engineering at City University London provides specialist focus on the programming and development of large and complex software and with an emphasis given to dependable systems.
Programmes Office (room A302)
School of Informatics
City University London
Northampton Square
London
EC1V 0HB
United Kingdom
T: +44 (0) 20 7040 8406


The Bsc. (Hons), Software Engineering is a specialized software course with modern software coding practices as part of its curriculum.  They also offer a Lord Mayor of London Scholarships for Academic Excellence, sounds like I could crack this one.

0 comments:

Post a Comment