Translating Pascal into java
Pascal is one of the respected computer grandfathers, but died long ago.
C is a kind of “dirty-Pascal”,
C++ is the oo version of C,
and java is a dialect of C++
Concluding: java = dialect of a oo-“dirty.Pascal”
I know, this statement might already trigger a 2000 pagina thread, but lets by practical!
In pascal this makes since, or is the double declaration of "c" a twenty year old mistake (found in my twenty year old pascal program...the crime is "over-yeard" anyway)?
Code:
procedure calc(var a, b, c:integer);
begin
c:= a + b;
end;
procedure docalc();
var c: integer;
begin
c:=4;
clac(2,3,c);
{what would be the value of c here? I believe 5}
end;
The equivalent in java would be (looks silly, I know)
public void calc (int a, int b, int c) {
c=a+b;
}
public void docalc () {
int c=4;
calc(2,3,c);
System.out.println("the value of c is: " + c);
}
The call docalc prints 4 and not 5
What deeper issues are involved compairing the two versions?
found a pascal translator
see: Micro-Processor Services, Inc.
they will know about control loop and system issues, the stuff that Norm and I will be worried about.
Norm: Code:
class PassTheCode{
int[] testValue = new int[1];
testValue[0] = 27;
static String method(int[] intArray)
{
intArray[0]=34;
String returnValue = new String(Integer.toString(intArray[0]));
return returnValue;
}
publc static void main(String[] args)
{
int[] mainArray = new int[1];
intArray[0] = Integer.parseInt(args[0]);
System.out.println(method(mainArray));
Opie's gonna waste time on this, primitives pass a register load and store, [] (arrarys) in Java are a first class object, thus are passed by indirect addressing. Dis-entangling copy of reference from actual data location is obviously not beyond the skills of original poster. Also, looks like we picked up a pascal coder. For an overview of how pascal works from a computer scientists perspective I suggest ( for Norm ) a reading of Compiler Construction - Principles and Practice - Kenneth C. Louden PWS Publishing. The sample code these two workers are talking in is almost straight out of that work and the cited work is mostly computer science that you are already familiar with.