ThelopWiki

Wards Wiki Pages / Virtual Structure

A VirtualStructure? is a structure that doesn't formally exist within the framework of the programming language. It exists only as a structure in the framework of the LopLanguage?. -- HelmutLeitner

The following example is trivial and not meant to teach something new. It is necessary to explain the term VirtualStructure? as it is used in LanguageOrientedProgramming. It is an example of VirtualOrder?.


(1) Let's start with some variables: String id; String name; Date dlv; Integer days; At this point it is not clear, what their relationship is and whether they belong together or not.

(2) If we try to rename them to make their meaning more visible, we might find the following names appropriate (imagine a hotel guest): String CustomerId; String CustomerName; Date CustomerVisitLastDate; Integer CustomerVisitLastDays; which makes clear, that these data belong together. They now form a VirtualStructure?. Nothing has changed for the compiler or interpreter of this code. A lot has changed for a human reader.

(3) Often the next step is building a true structure or class, so that one will be able to access its elements by any of the following expressions

Customer.Id Customer.Name Customer.VisitLastDate Customer.VisitLastDays Customer.VisitLast.Date Customer.VisitLast.Days

or accessor function calls like (only some possible examples)

Customer.Id() Customer.VisitLast().Date() Customer.setVisitLastDate(date) Customer.retVisitLastDate() Customer.getVisitLastDate(rDate) Customer.retId() Customer.setId(id) Customer.retVisitLast().retDate() Customer.retVisitLast().setDate(date)

Note how the hierarchical names of (2) prepare for step (3). The names are built to minimize the work needed to form real structures or classes. Although accessor words like Set, Get or Ret may be inserted, the other words don't change their positions within the names.

Note also that the following names String IdC?ustomer; String CustomerName; Date LastC?ustomerVisitDate; Integer LastVisitDaysC?ustomer; won't serve this purpose as well, although the same words are used.


LanguageOrientedProgramming commands that any possibility to increase readability, to display meaning, to increase symmetry and order and to prepare for change and maintenance must be used.


HungarianNotation? places the data type at the beginning of a name, so it is not compatible to the idea of VirtualStructure?.


I have two issues with this approach.

Firstly, this kind of code violates encapsulation of the Customer class an breaks the LawOfDemeter?. It makes it harder to later change the way the Customer class represents the date of the last visit. Also, it makes it harder to keep other state of the Customer class in sync with the last-visit date (in this example).

Customer.retVisitLast().retDate() Customer.retVisitLast().setDate()

Better would be code of form:

Customer.setVisitLastDate( a_date );

Secondly, the code does not read like natural language. At least, it does not read like english (it may read naturally in German, I do not know enough of that language to tell).

In English, adjectives come before nouns, so it would be better as:

Customer.getLastVisitDate(); Customer.setLastVisitDate( a_date );

Again, that feels unnatural, so even better IMHO would be:

Customer.getDateOfLastVisit(); Customer.setDateOfLastVisit( a_date );

--NatPryce?

First, I just gave few examples (common OO usage) without any intention to advocate a certain practise. In fact some of them (e.g. Customer.Id(), a method name that contains no action word) are not even legal THELOP names. But I added your suggestion (and a few others) to the list.

Second, It may be natural to expect common English grammar, but English is not designed for software engineering, so THELOP is sometimes different. Some words have different meaning, word order differs, some words even belong to different words classes. The reason for this is not the influence of other languages (like e.g. German) but the goals of LanguageOrientedProgramming. One goal is to increase order (even if it is only VirtualOrder?), hierarchial names are part of this.


See also: LanguageOrientedProgramming, ThelopLanguage?, VirtualOrder?, ThelopLanguageFaq?
CategoryThelop?
 
© ThelopWiki Community zuletzt geändert am September 22, 2003