Recent

Author Topic: Discussion - What if fpc syntax becomes C-like?  (Read 3652 times)

munair

  • Hero Member
  • *****
  • Posts: 696
  • keep it simple
    • SharpBASIC
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #60 on: April 07, 2020, 03:31:43 pm »
What is the harm in for example:]http://sharpbasic.com/images/bool-01.png]

The harm would be that simple typos would no longer be rejected as error.
Code: Pascal  [Select][+][-]
  1. var
  2.   CurrentValue: Integer;
  3.   CurrentValid: Boolean;
  4. ....
  5. TempBool := CurrentValue; // typo: should be CurrentValid

Personally I am glad for every hour of debugging from which the compiler saves me.
I perfectly understand. Personally I love compilers that allow that kind of assignment. Instead of an error it could optionally throw a hint or warning at compile time as a debugging switch, just as is being done with uninitialized data (which also often lead to bugs which can be even less obvious than typos).

ASBzone

  • Sr. Member
  • ****
  • Posts: 373
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #61 on: April 07, 2020, 04:36:48 pm »
Yet, it isn't forgiving in passing parameter types, like an integer argument to a word parameter. That is the kind of inconsistency that often prevents programmers from using such language.

Programmers who want that kind of "flexibility" would be well advised to stay away from a strongly typed language -- just as I try to stay away from many apps written by programmers who love to exploit said "flexibility".

That smacks of poor planning, and a correspondingly higher number of bugs.
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.11 r63516 / FPC v3.2.1-r45705 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 2004 (Build 19041.329)
Other Systems: Windows 10 Pro x64, Version 1909 or greater

PascalDragon

  • Hero Member
  • *****
  • Posts: 1768
  • Compiler Developer
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #62 on: April 08, 2020, 10:11:31 am »
Pascal is already very forgiving in that it allows assignments of integers to real and random integer types to other integer types.
Yet, it isn't forgiving in passing parameter types, like an integer argument to a word parameter. That is the kind of inconsistency that often prevents programmers from using such language.

Huh? As long as you don't have a var, out or constref parameter (and these do have reasons) the language is very forgiving there:

Code: Pascal  [Select][+][-]
  1. procedure Test1(arg: LongInt);
  2. begin
  3. end;
  4.  
  5. procedure Test2(arg: Word);
  6. begin
  7. end;
  8.  
  9. var
  10.   l: LongInt;
  11.   w: Word;
  12. begin
  13.   Test1(l);
  14.   Test1(w);
  15.   Test2(l);
  16.   Test2(w);
  17. end.

Compiles without error...

munair

  • Hero Member
  • *****
  • Posts: 696
  • keep it simple
    • SharpBASIC
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #63 on: April 08, 2020, 10:34:41 am »
Well, I stand corrected there. It's been a while since I programmed with FPC but I remember an issue where parameter passing with date variables raised a type mismatch. It was something with EncodeDate or something and types not compatible with words, if I remember correctly. It's been a while like I said, but I'll be sure to point it out when I come across this issue again.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1768
  • Compiler Developer
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #64 on: April 08, 2020, 10:51:22 am »
Probably DecodeDateTime and friends? In that case please take note that it's using out parameters which must be the same type, because it's essentially passing a pointer under the hood (which is why I excluded them in my list above).

munair

  • Hero Member
  • *****
  • Posts: 696
  • keep it simple
    • SharpBASIC
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #65 on: April 08, 2020, 10:59:18 am »
Probably DecodeDateTime and friends? In that case please take note that it's using out parameters which must be the same type, because it's essentially passing a pointer under the hood (which is why I excluded them in my list above).
That was probably the issue I ran into.

munair

  • Hero Member
  • *****
  • Posts: 696
  • keep it simple
    • SharpBASIC
Re: Discussion - What if fpc syntax becomes C-like?
« Reply #66 on: April 11, 2020, 04:16:34 pm »
While the subject of loosely vs strictly typed is sensitive, it is something that can be easily overcome by a special directive. For example, the language I'm working on (which is loosely typed by default) supports the "option strict" directive to enforce strict typing when put at the top:http://sharpbasic.com/images/option_strict.png. It is probably not conform Pascal standards though.

 

TinyPortal © 2005-2018