Hacker News new | ask | show | jobs
by badsectoracula 1487 days ago
Yeah, this is basically what Free Pascal does too. The default language mode is actually kinda obsolete (it is more of a Turbo Pascal 7+), but you can change dialects with the $mode directive (with most common being "objfpc", an extension to the default "fpc" mode that adds more advanced features and "delphi" which is used for Delphi compatibility to allow sharing code). In addition to that many new features are enabled with additional directives, like $modeswitch (e.g. "$modeswitch advancedrecords" enables using methods and management operators in records and "$modeswitch prefixedattributes" enables attaching custom attributes to classes, properties, etc to be accessed via the RTTI later) and $scopedenums (so that when you have an enum like TFoo = (Bar, Baz) it wont create Bar and Baz globals like in classic Pascal, but TFoo.Bar and TFoo.Baz - the fact that it isn't a modeswitch is most likely for Delphi compatibility as AFAIK Delphi doesn't have a modeswitch directive - or mode directive for that matter).

It does require having a litany of switches at the top of each source code but it beats having old code break (though i do think that in some cases the FPC devs go a bit too overboard - e.g. attributes would be a syntax error anyway).