-
Call-by-reference is more powerful than call-by-value:
This statement depends on the context of "powerful." Call-by-reference allows functions to modify the arguments directly, facilitating efficient data manipulation and avoiding the overhead of copying data, as seen in call-by-value. In languages that support call-by-reference semantics, this can lead to more flexible and efficient code for certain operations. However, call-by-value has the advantage of making functions pure (their output depends only on their input, without side effects), which can simplify reasoning about programs and improve safety by avoiding unintended modifications of data outside the function. Thus, while call-by-reference might be considered "more powerful" in terms of flexibility and efficiency for certain tasks, it doesn't unequivocally make it better in all programming contexts. The statement's validity is subjective and varies with the specific needs of the application and the preferences of the programmer.
-
It is possible to represent infinite lists by using list comprehensions in Erlang:
This statement is misleading. Erlang supports lazy evaluation in the form of generator functions, but the typical list comprehensions in Erlang are not inherently lazy and are expected to terminate. Erlang's list comprehensions are not directly suited to representing infinite lists in the same way as Haskell's lazy evaluation model, for example. However, Erlang can represent potentially infinite processes or streams using its actor model and message passing, but this is conceptually and practically different from infinite lists generated by list comprehensions. So in the context of Erlang's standard list comprehensions, the statement is not valid.
-
Closures can be used to provide encapsulation:
This statement is valid. Closures, which are functions that capture and retain variables from their containing scopes, can indeed be used to provide encapsulation. By capturing specific variables and providing a function that operates on or with those variables, closures can hide the state (the captured variables) from the outside world, only exposing a controlled interface (the function itself). This is a form of encapsulation because it restricts access to the internal state, allowing manipulation only through defined behaviors (functions). In many programming languages, closures are a powerful tool for creating private variables and methods, thus supporting encapsulation in object-oriented and functional programming paradigms alike.
-
In class-based OO languages, the parameters of overriding methods can be covariant with the corresponding parameters of the overridden methods:
This statement is generally incorrect. Covariance refers to a type system's ability to replace a type with a subtype (a more specific type). In most class-based object-oriented languages, the return type of an overriding method can be covariant, meaning an overriding method can return a type that is a subtype of the return type of the overridden method. However, the parameters of overriding methods are typically contravariant or invariant, not covariant. This means that the parameters of an overriding method can accept types that are the same as or more general than those of the overridden method, not types that are more specific. The principle behind this is Liskov's Substitution Principle, which ensures that a subclass can stand in for its superclass.
-
The cost for using virtual functions in C++ is minimal:
The statement that the cost is "minimal" can be somewhat misleading without proper context. The use of virtual functions in C++ introduces a level of indirection through a virtual function table (vtable), which can have performance implications relative to non-virtual functions. There is a runtime cost associated with dynamic dispatch (the process of determining which overridden function to call at runtime). However, in many cases, especially when the flexibility and polymorphic behavior provided by virtual functions are needed, this cost is considered acceptable or minimal relative to the benefits. Thus, while there is a non-zero cost to using virtual functions, whether it is deemed minimal is often context-dependent, depending on the performance requirements of the application and the alternatives available for achieving polymorphism.