On Jan 25, 2015, at 2:56 PM, Benedict Holland <benedict.m.holl...@gmail.com> 
wrote:

> On Sun, Jan 25, 2015 at 4:38 PM, Francesco Menoncin 
> <francesco.menon...@unibs.it> wrote:
> Hello Benedict,
> thank you for your answer.
> I give you an example about how R is difficult for dealing with matrices: if 
> in Matlab (or Scilab or Octave or simila) I write:
> 
> x(2,2)=10
> 
> the following matrix is automatically created:
> 
> [0 0
> 0 2]
> 
> while in R
> 
> x[2,2]=10
> 
> gives an error because I first have to declare to R that x is a matrix and, 
> furthermore, give it the right dimension.
> If, afterward, I want to add an element to the matrix x, in Matlab I simply 
> write:
> 
> x(3,1)=5
> 
> and I obtain the matrix:
> 
> [0 0
> 0 10
> 5 0]
> 
> while in R I cannot do that, because x has already been defined as a 2 by 2 
> matrix.
> I find all this very inefficient for dealig with matrices.
> This is my point :-)
> 
> Francesco
> 
I'm not familiar with R but what you are saying about R in comparison with 
Matlab or Octave is that Matlab/Octave do not check array bounds. Thus, you 
might erroneously write into a matrix element that doesn't exist and 
Matlab/Octave does not report an error. Array bounds checking is the price to 
pay for having safer code. FWIW, Python and Mathematica are examples of 
languages that are only "half-safe" with respect to array indexing, meaning if 
you write past the beginning of an array (usually negative indexes) it assumes 
you want to index the array backwards, from the end. These are all conveniences 
but of course can also cause erroneous results or increased time spent 
debugging. I personally am happy to write in a safe language (Ada) and spend a 
little bit more time writing code (it's easy to declare a new array and copy 
the old one into it; you can write a subroutine if you want) and virtually zero 
time chasing bugs, but others prefer otherwise and that's fine.

Jerry 

Reply via email to