Question - One characteristic of programming languages that varies widely from language to language is how parameters are passed. Among ALGOL, Pascal, Ada, C, C++, Java, and C#, no two languages pass parameters in exactly the same way. Among these languages, choose the one that you believe has adopted the best approach to parameter passing. Defend your decision by outlining the advantages of the approach of the language that you chose and the disadvantages of the approaches taken by other languages.

In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments

First we will brief about each of the languages namely ALGOL, Pascal, Ada, C, C++, Java and C#

ALGOL

ALGOL (short for Algorithmic Language) is a family of imperative computer programming languages, which greatly influenced many other languages and was the standard method for algorithm description used by the ACM in textbooks and academic sources for more than thirty years.

ALGOL allowed for two evaluation strategies for parameter passing: the common call by value, and call by name. Call-by-name has certain effects in contrast to call-by-reference. For example, without specifying the parameters as value or reference, it is impossible to develop a procedure that will swap the values of two parameters if the actual parameters that are passed in are an integer variable and an array that is indexed by that same integer variable. Think of passing a pointer to swap(i, A[i]) in to a function. Now that every time swap is referenced, it is reevaluated. Say i:= 1 and A[i]:= 2, so every time swap is referenced it'll return the other combination of the values ([1,2], [2,1], [1,2] and so on). A similar situation occurs with a random function passed as actual argument.

Pascal

Pascal is an imperative and proceduralprogramming language, as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.

In pascal parameters are passed by mainly call by reference and call by value. But there are a lot of limitations of pascal as the array sizes and string lengths were part of the type, so it was not possible to write a function that would accept variable length arrays or even strings as parameters.

Another difficulty was that, like ALGOL, the language did not allow procedures or functions passed as parameters to predefine the expected type of their parameters.

Ada

Ada is a structured, statically typed, imperative, wide-spectrum, and object orientedhigh levelcomputerprogramming, extended from Pascal and other languages. Unlike in the C class of programming languages, Ada subprogram calls cannot have empty parameters parentheses ( ) when there are no parameters.

The generic unit declares generic formal parameters, which can be:

•objects (of mode in or in out but never out)

•types

•subprograms

•instances of another, designated, generic unit.

When instantiating the generic, the programmer passes one actual parameter for each formal. Formal values and subprograms can have defaults, so passing an actual for them is optional.

C Language

C is a general purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instruction, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems.

In C Programming we have different ways of parameter passing schemes such as Call by Value and Call by Reference.

1.Function is good programming style in which we can write reusable code that can be called whenever require.

2.Whenever we call a function then sequence of executable statements gets executed. We can pass some of the information to the function for processing called argument.

3. While Passing Parameters using call by value , xerox copy of original parameter is created and passed to the called function.

C++

C++ is a general-purpose programming language. It has imperative, object oriented and generic programming features, while also providing facilities for low-levelmemory manipulation.As in C, C++ supports four types of memory management : static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.

In C++ programming, you can provide default values for function parameters.

The idea behind default argument is simple. If a function is called by passing argument/s, those arguments are used by the function.

But if the argument/s are not passed while invoking a function then, the default values are used.

Default value/s are passed to argument/s in the function prototype.

No matter how you use default arguments, a function should always be written so that it serves only one purpose.

If your function does more than one thing or the logic seems too complicated, you can useFunction overloading to separate the logic better.

Java

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.

You can use any data type for a parameter of a method or a constructor. This includes primitive data types, such as doubles, floats, and integers, and reference data types, such as objects and arrays.

When you declare a parameter to a method or a constructor, you provide a name for that parameter. This name is used within the method body to refer to the passed-in argument.

The name of a parameter must be unique in its scope. It cannot be the same as the name of another parameter for the same method or constructor, and it cannot be the name of a local variable within the method or constructor.

A parameter can have the same name as one of the class's fields. If this is the case, the parameter is said to shadow the field. Shadowing fields can make your code difficult to read and is conventionally used only within constructors and methods that set a particular field.

C# Language

C# is a hybrid of C and C++, it is a Microsoftprogramming language developed to compete with Sun’sJava language. C# is an object oriented programming language used with XML-based Web services on the .NET platform and designed for improving productivity in the development of Web applications.

C# boasts type-safety, garbage collection, simplified type declarations, versioning and scalability support, and other features that make developing solutions faster and easier, especially for COM+ and Web services. Microsoft critics have pointed to the similarities between C# and Java.

In C#, arguments can be passed to parameters either by value or by reference. Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling environment. To pass a parameter by reference, use the ref or out keyword.

As we looked how parameters are passed in different programming languages and keeping that in mind according to me Java seems to have adopted best approach because it is the most object oriented language and C# somewhat similar like Java.

Java uses a mixture of Call by Value and Call by Reference. Putting it in a nutshell, every parameter – be it a scalar value of an object – is passed by value. But if you pass an object, only it’s reference pointer is passed. As I already mentioned, this parameter is passed by value, so you can modify it safely without risking any side effect.

In languages like C/C++, Perl or Javascript, you can assign function pointers to variables. As far as I know, Javascript and Perl do this in a safe way: the only operation you can do with a function pointer is to store it and to execute it. In contrast, C and C++ exhibit the technical meaning of the pointer.