Question

In: Computer Science

Q From a programming language perspective, describe what orthogonality is, briefly explain any benefits or detriments...

Q From a programming language perspective, describe what orthogonality is, briefly explain any benefits or detriments of having a higher or a lesser degree of orthogonality.

Q  In computer memory, variables are bound to specific memory addresses and have a lifetime. Based on their lifetimes, what are the four categories of these storage bindings? Briefly describe each of the four variable storage bindings.

Solutions

Expert Solution

Orthogonility is a concept often used to describe modular and maintainable software, but it's more easily understood by way of a case study. In this article, Jens Dietrich demystifies orthogonality and some related design principles by demonstrating their use in the popular Log4j utility library. He also discusses how Log4j violates orthogonality in a couple of instances and discusses possible workarounds to the issues raised.

The concept of orthogonality is based on the Greek word orthogōnios, meaning "right-angled." It is often used to express the independence between different dimensions. When an object moves along the x-axis in a three-dimensional space, its y and z coordinates don't change. Change in one dimension does not cause change in another dimension, which means that one dimension cannot cause side-effects for others.

This explains why the concept of orthogonality is often used to describe modular and maintainable software design: thinking about systems as points in a multi-dimensional space (spawned by independent, orthogonal dimensions) helps software developers to ensure that our changes to one aspect of system will not have side-effects for another.

It happens that Log4j, a popular open source logging package for Java, is a good example of a modular design based on orthogonality.

The dimensions of Log4j

Logging is just a fancier version of the System.out.println() statement, and Log4j is a utility package that abstracts the mechanics of logging on the Java platform. Among other things, Log4j features allow developers to do the following:

  • Log to different appenders (not only the console but also to files, network locations, relational databases, operating system log utilities, and more)
  • Log at several levels (such as ERROR, WARN, INFO, and DEBUG)
  • Centrally control how much information is logged at a given logging level
  • Use different layouts to define how a logging event is rendered into a string

While Log4j does have other features, I will focus on these three dimensions of its functionality in order to explore the concept and benefits of orthogonality. Note that my discussion is based on Log4j version 1.2.17.

Considering Log4j types as aspects

Appenders, level, and layout are three aspects of Log4j that can be seen as independent dimensions. I use the term aspect here as a synonym for concern, meaning a piece of interest or focus in a program. In this case, it is easy to define these three concerns based on the questions that each addresses:

  • Appender: Where should the log event data be sent for display or storage?
  • Layout: How should a log event be presented?
  • Level: Which log events should be processed?

Storage Binding of a variable is the binding of a variable name to a memory address. The type of storage binding determines the lifetime of a variable; the lifetime of a variable is the time during which it is bound to a particular memory cell. Storage binding begins with memory allocation - getting a cell from some pool of available cells. Storage binding ends with deallocation - putting a cell back into the pool.

Categories of Variables by Storage Binding

1. Static- Bound to memory before execution begins and remains bound to the same memory cell throughout execution, e.g., all FORTRAN 77 variables, C static and extern variables and C++ static members in a C++ class.

Advantages: efficiency (direct addressing), history-sensitive subprogram support Disadvantage: lack of flexibility (no recursion)

2. Stack-Dynamic - Storage bindings are created for variables when their declaration statements are executed at runtime. If scalar, all attributes except address are statically bound Ex: local variables in C functions and C++/Java methods return values, arguments pass by value.

Advantage: allows recursion; conserves storage

Disadvantages: Overhead of allocation and deallocation; Subprograms cannot be history sensitive; Inefficient references (indirect addressing)

3. Explicit Heap-Dynamic - Allocated and deallocated explicitly by the programmer, occurs during execution. Referenced only through pointers or references, e.g. dynamic objects in C++ (via new and delete), all objects in Java

Advantage: provides for dynamic storage management Disadvantage: inefficient and unreliable

4. Implicit Heap-Dynamic - Allocation and deallocation caused by assignment statements. All variables in APL; all strings and arrays in Perl and JavaScript; all objects in Java; Advantage: flexibility Disadvantages -- Inefficient, because all attributes are dynamic and loss of error detection;


Related Solutions

Q What were the main design goals of the ALGOL programming language? o To describe algorithms...
Q What were the main design goals of the ALGOL programming language? o To describe algorithms in publications o To be machine independent o To teach non-science students o To mimic standard mathematical notation o To standardise software development tools Q The types of variables used in a programming language can be statically declared as part of the source code of a computer program. Define and give an example of explicit variable declaration and implicit variable declaration [2 marks]:
What are some benefits and detriments of televised trials?
What are some benefits and detriments of televised trials?
Pick one of the four loan repayment options and briefly discuss the benefits and detriments of...
Pick one of the four loan repayment options and briefly discuss the benefits and detriments of that option. Please vary your answers so that all four options are discussed. 1. Bullet loan 2. Balloon loan 3. Equal principle payment 4. Equal payment
In Philippines, what are the benefits and the detriments that the 60/40 rule to the Philippines?...
In Philippines, what are the benefits and the detriments that the 60/40 rule to the Philippines? (60/40 rule = where Filipinos must own 60% of the venture leaving only 40% to foreign investors)
Q: List the benefits of CPM scheduling in the construction project from the project engineer’s perspective.
Q: List the benefits of CPM scheduling in the construction project from the project engineer’s perspective.
Q Name and briefly describe three programming paradigms. Include in your description an example of at...
Q Name and briefly describe three programming paradigms. Include in your description an example of at least one programming language that uses that particular paradigm. Q  Name and briefly describe any three of the six attributes that a variable can be characterised by.
What are the benefits and detriments of using debt as a source of funds when compared...
What are the benefits and detriments of using debt as a source of funds when compared to issuing common stock?
What are some of the possible benefits and detriments involved in the pharmacological treatment of psychological...
What are some of the possible benefits and detriments involved in the pharmacological treatment of psychological disorders? Have we (society) become too reliant on medication treatments? What might be some of the long-term ramifications of overprescribing these medications?
11. What are the benefits and costs of advertising from an economist’s perspective?
11. What are the benefits and costs of advertising from an economist’s perspective?
Write a program, using any language you want, that uses a Randomized-Select algorithm. Briefly explain what...
Write a program, using any language you want, that uses a Randomized-Select algorithm. Briefly explain what it does, how it does. Include code and show output.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT