Top Computer Programming Languages - Syntax questions


1. For Each and Iterate loops - Programming syntax

The For Each and Iterate loops look similar - this section shows which should be used when writing programs. The For Each loop is used with functions that return lists or arrays. The next example uses For Each to loop through the elements of an array:

  // TestForEach.cls
  Ubercode 1 Class TestForEach

  type TNameArray[*:*] : array[*:*] of string[20]

  function TNameArray(out aNames:TNameArray[*:*])
    aNames <- {"North", "South", "East", "West"}
  end function

  public function main()
    name : string[*]
    for each name in TNameArray()
      call Msgbox("Name", name)
    end for
  end function

  end class

In the program above, the type TNameArray declares an array type for storing strings, and function TNameArray returns an array initialized with some strings. The function is also known as a constructor function, since it constructs (and returns) a value of TNameArray type. Finally in function main, the For Each loop reads through each element in the array and prints it out using a message box.

The Iterate loop is used with tables. The next example declares a table type and uses Iterate to loop through all the elements:

  // TestIterate.cls
  Ubercode 1 Class TestIterate

  type Tname : record
    name : string[20]
    address : string[100]
  end record

  type TNameTable[*] : table[*] of Tname
    index 1 (name)
  end table
  public function main()
    tabNames : TNameTable[*]
    person : Tname
    call Tabadd({"Mr Smith", "1 Smith St"}, tabNames)
    call Tabadd({"Mr Jones", "1 Jones St"}, tabNames)
    iterate person through tabNames
      call Msgbox("Person", Str(person))
    end iterate
  end function

  end class

In the program above, the type Tname is a record with two fields (name and address), and is used as the components of the table. The type TNameTable is the actual table type. In function main, the table variable tabNames is declared, two records are added to the table, then the Iterate loop reads through each element in the table and prints it out using a message box.

The Iterate loop is useful when working with large amounts of data. The records in a table are kept in sorted order as defined by the indexes, and Iterate is allowed extra elements such as Where and Order By to control the iteration through a large table.

2. How often does Ubercode language syntax change?

Some languages change their syntax every year or two, whenever a new version is released. But it is bad when languages change with every release. It makes software rapidly become obsolete, it stops code being reused, it makes it hard for developers to keep up to date, and it encourages a culture where software is considered "bad" if it does not have the latest gizmo, and it puts appearance above reliability.

The only people benefitting from rapid updates are large companies that sell lots of software, and business that run training courses.

The Ubercode philosophy is that language syntax should be changed as infrequently as possible, consistent with keeping in step with mainstream technology. Therefore most operating system improvements are represented by new functions added to the run time library, and the syntax does not change.

Whenever a new major version of Ubercode is released (v1 to v2 etc) it will include tools to update earlier versions of programs. This is the reason for the version number at the top of Ubercode programs, to help automatic updates. In general Ubercode syntax will change as infrequently as possible, but no less infrequently!

3. What is the difference between "its" and "it's"?

"It's" is short for "it is" as in "It's a groovy language". "Its" means "belonging to it" as in "the program read its input".