Skip to main content

Silly Mistakes (Technically?)

There could be too many, I am listing few of them.
Of course, they are not as obvious as shown below, especially when they go multiple levels of method/function calls.

Split: (Java)

I should have read the docs properly.
Code:

String[] data = { "Phil;45678910;", "Alex;45678910;45678911"};
for(int i=0; i< datasplit =" data[i].split(" i="0;" datasplit =" data[i].split(">



Parse Int: (JavaScript)

Strange? The date component doesn't work properly for August and September. (
I used parseInt(monthField).
Code:

alert(parseInt("07")); // 7
alert(parseInt("08")); // 0
alert(parseInt("0xA")); //10

Thank God, I know number systems!

Key Words: (JavaScript)

The following script throws an error. Absolutely correct?
Code:

var ZDBExport = function()
{
this.export = function(arg1, arg2)
{
// do export
}
}

And realised "export" is a keyword in javascript. It allows the signed script to export its properties to other signed/unsigned script.

Variable Scope: (JavaScript)

I was astonished (because I have not seen this idea anywhere else) javascript variable doesn't have block level scope.

String Array: (JavaScript)
Code:

var myArray = "Dream";
alert(myArray[0]); // IE -> undefined, FF -> D

Simple: substring helps!

Long (Java)

It worked when I had constant values. I forgot to check when I changed that to dynamically created values.

Code:

public static void main(String args[])
{
Long v1 = new Long(20);
Long v2 = new Long(20);

System.out.println(isEqual(20L,20L)); // true
System.out.println(isEqual(v1, v2)); // false
}

public static boolean isEqual(Long val1, Long val2)
{
if(val1 == val2) { return true;}
else { return false; }
}

I understand, symbol tables studied in the college helps!

Looping without Loop

Not a mistake! I think it is beautiful (
Code:

public boolean isType(long typeID, String value)
{
/// return boolean_value
}

public long getType(String value)
{
if(isType(1L,value))
{
return 1;
}
else if (isType(2L, value))
{
return 2;
}
else if ...
}


Switch - Ternary

Not a mistake. I love it.
Code:

switch(value ? no1 : no2)
{
case ....
}


PS: None of the above are actual and I have taken them to show the idea.




Kovil Pillai P.

Comments

Popular posts from this blog

My Book Shelf - Year 2017

I find it difficult to get this reading order. And I guess it would be still harder to read them without changing the order. I may allow one or two new books to be included in this list, if required. Share book reviews and ratings with Kovil Pillai, and even join a book club on Goodreads.

The Power Game

 Even if you count from the Homo sapiens time, it has been half a million years and from the caveman life to the one who attempts to control the universe, the progress is tremendous. A number of struggles that we have overcome are unimaginable. I am still not convinced whether all these are part of the Divine plan or the Nature adjusts (if at all something is required) itself to any change that takes place in it. As long as we believe in science, we can truly appreciate our power and the things we have achieved. The oldest of the power struggles can be the one between men and women. It is perhaps so subtle that we can’t even call it a power struggle. While we manage to fight against external things, this is something happening in our own race, and we haven’t had an answer yet. A coffee selling 10 times costlier than the price of it in a decade ago may mean the coffee price has been raised. But when you compare it with the price of everything, it is relatively the same. If you look ...