Function vs Method

The main difference between a function and a method is that a function can live independently of the any instance of a class, where as a method sits within a class.

That is about it, e.g. a function is

int func(int value);
...
 
int main()
{
  cout << funct(3) << endl;
}

whereas a method has to live within a class

class myclass
{
    int myMethod(int it);
};
 
....
 
int main()
{
   myclass theclass;
   cout << theclass.myMethod(4) << endl;
}

Strings

Just a small thing encase anyone else finds this interesting as such.. but you cannot add a set of ” ” strings together in c++ without declaring one being a string.. for example

cout << "hi" + "bye" << endl;

the error would be

error: invalid operands of types 

Why -> and not *name.type

When you are coding with pointers in c++ and you want to access the function/variable from that pointer deferenced, how come you cannot use something like below.

struct typeT{
   int value1;
};
 
typeT* tt = new typeT;
*tt.value1;

it is because the access element of the variable tt is higher in the compiler and thus it tries to equate

tt.value1

first, which is not a good thing because the tt has not been de-referenced and thus it is just a memory address pointer to the actual object. so you need to do

(*tt).value1

because like in maths the () will be equated first and then the access element part “.” and thus to make it easier

tt->value1

will change to

(*tt).value1

within the compiler.

Moonlight

Within kubuntu (or ubuntu derived setups) you can have a moonlight development .. aka the silverlight open source version that will run on linux.

if you install the

monodevelop-moonlight

and also the

monodoc-moonlight-manual

packages, the last one is the manual if you need some help, but the first one will allow the monodevelop development environment have the moonlight plugin which creates a project to develop silverlight applications in.

Curly brackets

It all depends on your type of coding, but I for style I do prefer to put array data within a separate part of the echo statement, for example.

$arr = array("first" => 1, "second" =>2);
 
echo "this is the first value " . $arr["first"];

but of course you can put the arr object within the echo statement as long as you { .. } it out, which is kinder similar to using the ” . as such,

echo "this is the second value {$arr["second"]}";

both work, but because of the array object uses the “..” for the hash key, then you will need to use the { .. }

Delete object from array within javascript

Someone asked me whilst doing a job how to delete parts of a array within javascript, so just like other object oriented languages, you can have a array of data objects and each one can be accessible and removable. To achieve this with javascript you use the delete method as below.

var myArray = new Array();
myArray[0] = "first value";
myArray[1] = "second value";
 
// and to delete the second value
delete myArray[1];

Adding floats together with commas and decimal places

Someone contacted me about adding some numbers together with comma’s and dots within there values, here is the email via the contact me page.

“Please I need a javascript code that can enable me add two or more numbers containing dot(.) and/or comma (,) together. For example, 122.34 + 233.56. Or/And 233,239.34 + 323,322.44. Thanks in advance.”

Here is the code that will accomplish the request.

<html>
<script type="text/javascript" >
       function load()
       {
               var value1="233,122.34";
               var value2="233.56";
               alert(parseFloat(value1.replace(",",""))+parseFloat(value2.replace(",","")));
       }
 
</script>
<body onload="load()">
</body>
</html>

The main part is the parseFloat and replacing the “,” with nothing “” to remove the none float characters via the object replace method.