[fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis michalis.kambi at gmail.com
Tue Jun 21 12:30:25 CEST 2016


>> I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-}
>> directives should be the *default* directives for every new FPC
>> programs/units. We're now using Free Pascal compiler on 2016. Why do we need
>> to explicitly declare Free Pascal mode in a Free Pascal program? In 21st
>> century, our string should not be limited to 255 chars anymore. And what the
>> hell is "writable constant"? It's contradictio in terminis. :)
>
> We have a strong focus on backwards compatibility, so the default mode stays
> "fpc" and changing a modes' default settings would also affect backwards
> compatibility.
>

Maintaining compatibility is usually a compromise. I feel that in this
case, maintaining such compatibility hurts more than it helps. It is
of course my opinion, biased by the kind of code I write, and by the
programmers I talk with (many of whom don't know Pascal, but know
Java, C# or other OOP languages).

Current FPC defaults:

- Help people who except the {$mode fpc} to be default (so they write
code without classes and a lot of other new features),
- Or people who expect that string is by default ShortString (limited
to 255 chars).

I think that the majority of people use now suitable command-line
options, or directives, to change FPC mode to something more modern
({$mode objfpc} or {$mode delphi}, and {$H+}). So changing the
defaults will not hurt them. Sure, I don't have any hard data to back
it up, I don't know how much is "majority". But this applies at least
to all Lazarus users that have these settings "by default".

Again, this is just my opinion, but I would say that breaking
compatibility in this case is warranted. Making objfpc the default
mode, and making $H+ the default in objfpc mode, before the fpc.cfg is
read (so it applies to everyone, and can be overridden by fpc.cfg or
command-line later) would be a nice thing.

(Making {$J-} would be a cool bonus, but I don't dream about it, as it
could admittedly break more recent code.)

In http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html
I decided to just write

  {$mode objfpc}{$H+}{$J-} // Just use this line in all modern sources

at the beginning of a first "hello world" example. And I never explain
the reason for this line, I just repeat it in all examples (that are
full programs/units). That's an ugly solution, but I just couldn't see
a better one. It doesn't sound nice to explain that:

- otherwise, they don't have classes ("why are classes disabled?"),
- otherwise their stings are limited to 255 ("are you sure this is a
modern language?"),
- and otherwise their constants are not necessarily constant ("what?") ...

It's not a good learning experience, if you have to learn about so
many historical things when you learn to write a first Pascal program.
And these things are already fixed -- just the defaults are old.

Regards,
Michalis



More information about the fpc-pascal mailing list