On 07/03/18 05:33, Wolf wrote:

The major shortcoming of this thread, the way I see it, is that the answer provided explains what the compiler does, but not why the key authors of Free Pascal have made these choices. What their choices achieve is a substantial watering-down of what is supposedly Pascal's most significant paradigm: strong typing. As Jim Lee points out, strong typing does limit utility - but if utility is first concern, a weakly typed language such as C would be more appropriate.

When looking at the (partial) disassembly of my little program, we see to what degree the compiler writers have sacrificed strong typing:

/*a:=1;*
  movb   $0x1,0x22de87(%rip)        # move 1 as single byte into 8 bit wide variable A
*b:=a*(-1);*
  movzbl 0x22de80(%rip),%eax        # move A into register %EAX and convert to 32 bit
  neg    %rax                       # negate what is in %EAX
  mov    %al,0x22de87(%rip)         # extract the low 8 bit from %EAX and store it in variable B
*writeln(b);    // result: 255*/
. . .

This was compiled without any optimizations. As you can see, the brackets are ignored, as is the fact that variables A and B were supposed to be multiplied. In other words, the compiler has optimized the code, where it was not supposed to do so. It has also replaced byte typed values with longint typed values. It has taken my code and translated it as if I had written
/  var
    a: byte;
    b: longint;//
//begin
    a:=1;
    b:=-longint(a);          // convert A to a longint and negate it, then save result in B     writeln( (Lower(b) );    // 'Lower' is a fictional typecast to denote that I only use the %AL portion of the %EAX register for the result
  end./
Which is quite a bit different from what I did program. Sorry if I am picky here, but this is the type of bug you can expect in software if you test using examples, and not through rigorous reasoning. And this is the reason why the original Borland Pascal had range checking built-in. If you activate it, the compiler does complain, both on my little program and on Jim's. But by now, range checking is optional, and Lazarus at least does not even activate it by default. But range checking is not the same as type checking, so I regard it as a crutch, a work-around that needs to be taken because the compiler does not adhere to (the spirit of) strong typing. And in this sense, what I submit here represents the same issue as what is given in the subject string if the whole thread:

Strong typing, and also readability, has been sacrificed on the altar of utility, by using implicit type conversions.

Maybe we do get some views from the key authors of Free Pascal.


Wolf


I didn't fully understand the intent of your first post, but now I get what you're saying.

I tend to agree.  Strict typing is the main thing that separates Pascal from C, conceptually.  I'd rather not see them converge.

-Jim


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to