Friday, June 28, 2013

New Series - Arrays and Indexers

Today, I'm going to start a new series of posts called "Arrays and Indexers in [Programming Language]".  As with previous posts, my aim is to show programming language's basic features, in this case, Arrays and Indexers.

There will a little program. It will show the different declaration and initialization syntax for single-dimensional, multi-dimensional and jagged (arrays of arrays) arrays, how to access elements using numerical index, how to use them as method's input parameters and return type. For the last example, I will define a class that implements the Indexer with its respective get set properties/methods and use it.

Regarding the demonstrating code, I chose an easy array-based sorting algorithm "BubbleSort" (single-dimensional array), a Matrix Transpose (multi-dimensional array) and a Random Uppercase Array. There will also be some Print Array Content methods to display the elements of the array. For the indexer part, it will just encapsulate an array of characters to store alphabets and access specific letters on it.

Each post of the series will be implemented in the latest version, available at the time of writing (stable or unstable), of the following languages targeting the latest version of the supported stable Runtime (JDK7 & .NET4.5)

CLR: C#, VB.NET, C++/CLI, F#, Boo, Phalanger, IronPython, IronRuby, Oxygene, Zonnon, Nemerle, Cobra, JScript.NET.

JVM: Java, Groovy, Jython, JRuby, Fantom, Scala, Gosu, Ceylon, Xtend, Kotlin.

And will use its respective System.Array or java.util.Array.

The Program's Structure will be (more or less) as follows:
// imports 
// namespace 
    // Program Class
        // Main Mathod            
            // Single-dimensional Array(s)            
            // Declare & Initialize Character Array
            // Reverse Array Elements
            // Print Array 
            // Declare & Initialize Integer Array
            // Sort Integer Array Elements
            // Print Array 
            // Declare & Initialize String Array
            // Sort String Array Elements
            // Print Array 
            // Multi-dimensional Array (Matrix row,column)
            // Declare & Initialize Matrix Array
            // Transpose Matrix
            // Print Array
            // Jagged Array (array of array)
            // Upper Case Random Array 
            // Print Array
            // Graph Number of Elements
            // Common Array Exceptions
            // Print Exceptions
            // Indexers Usage
            // Declare & Initialize
            // Access Class Array Elements via Indexer
        // Method: ReverseChar          - Char[] 
        // Method: BubbleSortInt        - Integer[] 
        // Method: BubbleSortString     - String[] 
        // Method: TransposeMatrix      - Integer[,] 
        // Method: UpperCaseRandomArray - String[][] 
        // Method: PrintArrayChar       - Char[] 
        // Method: PrintArrayInt        - Integer[] 
        // Method: PrintArrayString     - String[] 
        // Method: PrintMatrix          - Integer[,]
        // Method: GraphJaggedArray     - String[][]
        // Method: PrintJaggedArray     - String[][]
        // Method: PrintCommonArrayExceptions - String[][]
        // Method: PrintTitle            
    // Indexer Class
        // Field: Char Array        
        // Indexer
            // Get
            // Set
        // Constructor: - Integer
        // Constructor: - String
        // Constructor: - Char Array
        // Method: toString
        // Method: Slice

Here below some definitions of the new concepts:

"An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched."
Taken from:

One-dimensional arrays
"A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index."
Taken from:

Multidimensional arrays
"A data structure consisting of a vector of vectors, in the case of a 2-dimensional array, or, in the case of an N-dimensional array, a vector of multidimensional arrays of degree N minus 1, thereby allowing the simulation of a N-dimensional grid of storage locations using an underlying memory architecture in which storage is addressed in a linear fashion."
Taken from:

Jagged Arrays
"In computer programming, an Iliffe vector (Jagged Arrays or Array of Arrays), also known as a display, is a data structure used to implement multi-dimensional arrays. An Iliffe vector for an n-dimensional array (where n > 2) consists of a vector (or 1-dimensional array) of pointers to an (n - 1)-dimensional array. They are often used to avoid the need for expensive multiplication operations when performing address calculation on an array element."
Taken from:

Bubble Sort Algorithm
"Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted."
Sorting Algorithm in Action:
Taken from:

"In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns.[1][2] The individual items in a matrix are called its elements or entries. An example of a matrix with 2 rows and 3 columns is: "

Taken from:

Matrix Transpose
"A matrix which is formed by turning all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written AT."
1 image says more than N words

Taken from:

"In object-oriented programming, an indexer allows instances of a particular class or struct to be indexed just like arrays"
"Indexers are implemented through the not get and set accessors for the operator[]. They are similar to properties, but differ by not being static, and the fact that indexers' accessors take parameters."
Taken from:

Array Slicing
"In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices (or dimensions) and different index ranges."
Taken from:

Tuesday, June 25, 2013

And, What Next?

It's been a while since my last post... worry not, this blog is neither dead nor forgotten, in fact, the Languages page is constantly being updated to reflect latest releases. Besides that, I often log in to see who has visited this blog and pretty much all the other stuff that the good Google Analytics has to tell me. For instance, here is the info of the last 30 days (May 25, 2013-Jun 24, 2013):

Visitors Location :

Numbers of Visits and Top 10 avg time:

Not bad! 1 - 2 minutes is not bad at all I think, even though there lots of visits with 0:00 lol. Anyway, let's see if I get more audience now that I plan to continue writing some posts. In fact I will start a new series about another very useful feature which almost every programming language supports: "Arrays". In this series I will write a couple of little programs demonstrating the syntax to declare, initialize and access elements through its index. I will also include an example of Indexers usage to make your own class accessible via numeric index, just like you do with arrays.

Other topics I was thinking about were Operator Overloading, Inheritance and Generics, but I think Arrays is far more basic than those.

Bon voilĂ , c'est tout. Au revoir!