Recent

Poll

Should the missing C-style operators be implemented in FPC?

Definitely YES
5 (10.2%)
Maybe YES, but I mostly dont care
7 (14.3%)
Definitely NO (please explain why youre against it)
22 (44.9%)
I dont care / I’ll leave it to the core devs
15 (30.6%)

Total Members Voted: 49

Author Topic: Feature Request: C operators (xor, or, and)  (Read 4907 times)

gues1

  • Jr. Member
  • **
  • Posts: 84
Re: Feature Request: C operators (xor, or, and)
« Reply #90 on: July 02, 2025, 10:58:17 am »
@gues1. It's difficult to disagree, but objections will likely arise.  :)
Fortunately, we are free to think and express our opinions  :D
Objections are always welcome because they show another point of view.

creaothceann

  • Full Member
  • ***
  • Posts: 142
Re: Feature Request: C operators (xor, or, and)
« Reply #91 on: July 02, 2025, 01:00:22 pm »
Here we are in PASCAL, a non-specialized language: everything that requires extreme (and professional) specialization is done with other tools (for example C, but mostly with advanced C compilers like the Intel compiler).

Why do you want to specialize a language like PASCAL? [...] If you like how C works, why not use C?
Because I dislike C syntax and the way its programs are generally written. Anders Hejlsberg and Borland had absolutely no problem with offering fast and/or low-level features: absolute variables, CPU ports, inline assembler, entire assembler subroutines, interrupt service subroutines. They were always interested in performance; in fact one of the top-selling features of Turbo Pascal was its insanely fast writing-compiling-running cycle.

I do not care if to achieve the goal, behind the scenes a tank or a tricycle moves, I care that the goal is achieved in a 100% SAFE AND CERTAIN way.
Sometimes the goal is not wasting the user's time.

But who sincerely uses -O3 or -O4 optimization in production? [...] I mean, I compile a software with a "BEWARE" in front of my eyes? Are you kidding?
As far as I know -O3 does not produce any "unsafe" code.

32 bits, 64 bits, 128 bits ..... 1 billion bits?

The compiler takes care of it.
The fastest memory in a computer 40 or 50 years ago was roughly 32 KiB in size, if you had the money for it.
The fastest memory in a computer today is also roughly 32 KiB in size. And if you don't care what your program is actually doing, you might end up with a program that runs for hours when it could be done in minutes. Or at 8 fps when it could run at 80 fps.
« Last Edit: July 02, 2025, 03:22:14 pm by creaothceann »

gues1

  • Jr. Member
  • **
  • Posts: 84
Re: Feature Request: C operators (xor, or, and)
« Reply #92 on: July 02, 2025, 05:52:45 pm »
Because I dislike C syntax and the way its programs are generally written. Anders Hejlsberg and Borland had absolutely no problem with offering fast and/or low-level features: absolute variables, CPU ports, inline assembler, entire assembler subroutines, interrupt service subroutines. They were always interested in performance; in fact one of the top-selling features of Turbo Pascal was its insanely fast writing-compiling-running cycle.
I wrote that improvements are always good news. But certainly not the implementation of a C syntax or equivalent functionality.
And I also wrote that in RTL and RTTI they do not have to follow these rules, obviously these must be optimized and targeted.
What you write has nothing to do with what I criticize.

Sometimes the goal is not wasting the user's time.
The video is a bit too long to watch. But from the comments I understood something.
My thought is that behind what I do (write Pascal code) if there is a compiler that uses one byte more or less to manage my calculations, I don't care. I do 10k calculations, 10KB more are not a problem. If the compiler does this, it means it is necessary.

As far as I know -O3 does not produce any "unsafe" code.
I read in the past about some problems about that, but even if we assume that it has been fixed, the presence of the -O4 on display does not seem very sensible to me. If you want, you can leave it "hidden" and if you think you are shooting yourself in the foot, you can set it manually.

The fastest memory in a computer 40 or 50 years ago was roughly 32 KiB in size, if you had the money for it.
The fastest memory in a computer today is also roughly 32 KiB in size. And if you don't care what your program is actually doing, you might end up with a program that runs for hours when it could be done in minutes. Or at 8 fps when it could run at 80 fps.
I wasn't talking about processing power (other than the fact that with 32K what do you do? Turn on a socket for the coffee machine?).
I was talking about the different distribution of data and the use of these: 32-bit or 64-bit systems have different criteria ... programming currently with Pascal compilers this doesn't interest me, even if a minimum knowledge of the differences is necessary.
Since compiling in 64-bit or 32-bit my source code is exactly the same (apart from a few small adjustments to my routines in assembler). You don't have to worry about this anymore (the compiler, RTLs and RTTIs obviously make a fundamental contribution to this).

Thaddy

  • Hero Member
  • *****
  • Posts: 17451
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Feature Request: C operators (xor, or, and)
« Reply #93 on: July 02, 2025, 05:55:25 pm »
@gues1

You seem to have a very limited knowledge about the big picture a.k.a tunnel view or horse view, even if it is explained to you by many. And some of those are computer scientists, not amateurs.
It is time for you to self-reflect.
« Last Edit: July 02, 2025, 05:57:58 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

gues1

  • Jr. Member
  • **
  • Posts: 84
Re: Feature Request: C operators (xor, or, and)
« Reply #94 on: July 02, 2025, 06:20:00 pm »
@gues1
You seem to have a very limited knowledge about the big picture a.k.a tunnel view or horse view, even if it is explained to you by many. And some of those are computer scientists, not amateurs.
It is time for you to self-reflect.
My apologies, I didn't realize I was talking to scientists.
And as you say, I obviously don't have the full picture, I thought I was dealing with a forum on Pascal, but evidently the project is much more extensive than I can understand.
I await the events patiently and end the interventions here.

Thaddy

  • Hero Member
  • *****
  • Posts: 17451
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Feature Request: C operators (xor, or, and)
« Reply #95 on: July 02, 2025, 06:37:35 pm »
I don't discourage you from taking part in future discussions. Some of your arguments were/are valid.
Just remember that the Pascal language lovers on this forum have a percentage wise overly large representation of CS as compared to, let's say a C forum.. And that makes them a bit more language agnostic.
Old ones, mostly, but still.... :P

(Dead giveaway: you can't seriously discuss compilers if you did not attend compiler classes, or a serious attempt at self-education)

Also it is very expensive to send birthday cards to half the core team for their 55'th birthday so I refrain from that. The median is lower, however. Unix time starts at 1970/1/1, but that is coincidence?
« Last Edit: July 02, 2025, 07:10:39 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

HotShoe

  • Jr. Member
  • **
  • Posts: 56
Re: Feature Request: C operators (xor, or, and)
« Reply #96 on: July 02, 2025, 08:04:35 pm »
The only time I even remember that FPC supports C style operators is when I port C over to FPC. In that case it is a nice feature that saves me a few minutes. Otherwise I simply forget they are there.

--- Jem

Fibonacci

  • Hero Member
  • *****
  • Posts: 788
  • Internal Error Hunter
Re: Feature Request: C operators (xor, or, and)
« Reply #97 on: July 02, 2025, 10:32:00 pm »
in RTL and RTTI they do not have to follow these rules, obviously these must be optimized and targeted

Right, so "RTL and RTTI" get the performance pass. But user code? Thats apparently supposed to stay slow, bloated, and "readable" - whatever thats supposed to mean, as long as its "clean" and "Pascal-ish".

everything that requires professional specialization is done with other tools

So if youre aiming for performance or modern features, youre clearly supposed to go with C, C++, or pretty much anything else. Pascal? Thats just for building nostalgic, slow, safe little toys to remind us of the good old days. Great thinking.



This isnt about blindly copying C. Its just about finishing an existing feature thats already halfway there in FPC. The "C operators" are partially implemented, some are even already in the codebase. Looks like someone started, then never bothered to wrap it up. Why? Who knows.

And its not just about C-style features either. There are plenty of other useful ideas out there, @Warfley listed a bunch of them nicely, and honestly, many of them would be a solid fit for FPC too.

We are talking about features that are useful, practical, and battle-tested across modern languages. Things that make programming easier, cleaner, or just less painful.

Time for FPC to look forward, not just backward. Let go of strict Delphi compatibility and make room for modern syntax and practical language improvements.

FPC being open source means we can shape its direction. Unlike Delphi, here we have the freedom to experiment, propose real improvements, and implement them. If a feature is useful, realistic, and makes Pascal better, its worth discussing and then adding to the language.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11476
  • Debugger - SynEdit - and more
    • wiki
Re: Feature Request: C operators (xor, or, and)
« Reply #98 on: July 02, 2025, 11:08:16 pm »
So if youre aiming for performance or modern features, youre clearly supposed to go with C, C++, or pretty much anything else. Pascal? Thats just for building nostalgic, slow, safe little toys to remind us of the good old days. Great thinking.

The  += operators have nothing to do with speed. Unless you blindly couple them with entirely unrelated features (like inplace overloading).

The += is a syntax. It does the exact same thing as the := ... + . And the compiler should generate identical asm for both. And if it doesn't, then the code generator should be fixed, rather than introducing an additional syntax. (that is for &= etc).

And the inplace overloading... That has nothing to do with the syntax. Sure you can (and some have) arbitrarily chose the syntax to trigger it. But that is just randomly sticking unrelated stuff together. inplace overloading needs its own trigger. Different thing, different trigger. And then it could happen for the normal + operator too.
Oh, wait, that needs an extra param passed? But once inplace *and* inlined, the code generator should optimize that away anyway. Much better to get the optimizer do its job...

Fibonacci

  • Hero Member
  • *****
  • Posts: 788
  • Internal Error Hunter
Re: Feature Request: C operators (xor, or, and)
« Reply #99 on: July 02, 2025, 11:20:06 pm »
So if youre aiming for performance or modern features, youre clearly supposed to go with C, C++, or pretty much anything else. Pascal? Thats just for building nostalgic, slow, safe little toys to remind us of the good old days. Great thinking.

The  += operators have nothing to do with speed. Unless you blindly couple them with entirely unrelated features (like inplace overloading).

That part you quoted wasnt really about the += operator or performance specifically. It was more of a sarcastic callback to what @gues1 said earlier, about "serious" work being done in other languages and Pascal being left for legacy toy apps. Just pointing out the mindset issue.

Warfley

  • Hero Member
  • *****
  • Posts: 1930
Re: Feature Request: C operators (xor, or, and)
« Reply #100 on: July 03, 2025, 12:52:34 am »
The example given by GMP: the DLL is developed in C, not in PASCAL, not in JAVA, not in VB .... only the wrappers are present in the various languages.

You have either not read or understood my post. I compared the C++ Wrapper of the gmp with the pascal wrapper. I did not compare the Pascal wrapper with the C base implementation.

Also C as well as Pascal as well as C++ are general purpose languages. I fact pretty much all of C89 is a direct subset of the capabilities of Pascal and all of the capabilities of Pascal is a subset of C++.
Except for superficial syntax differences there is nothing you can do in C you can't directly tra slate into pascal, similarly there is nothing you can do in pascal you can't directly translate into C++ (not the other way around though).

So neither of those languages is a specialized language. They just have slightly different focuses on what they assist with and what not.

So for example Pascal has language level lazy copy strings, while C++ allows you to define a datatype that behaves exactly the same. So they can both do the exact same thing, in pascal its just implemented on language level and in C++ you'd need to build it yourself
« Last Edit: July 03, 2025, 12:55:24 am by Warfley »

PascalDragon

  • Hero Member
  • *****
  • Posts: 6049
  • Compiler Developer
Re: Feature Request: C operators (xor, or, and)
« Reply #101 on: July 03, 2025, 11:10:49 pm »
Quote
x++;
Useless!!!

You cant do

Code: Pascal  [Select][+][-]
  1. while Inc(x) < 10 do ...

But you could do it C-style

Code: Pascal  [Select][+][-]
  1. while x++ < 10 do ...
  2. while ++x < 10 do ...
  3. while x-- > 0 do ...
  4. while --x > 0 do ...

Maybe Inc() should return the incremented value? In C, x++ returns the value of x and then increments it, while ++x first increments the value and then returns the incremented value. What variant should Inc() follow? I know: none! ::)

That works in C or C++, because there statements also return a value. In Pascal they do not. So if C/C++ would not provide that, then those examples of yours would not work either.

One think that Pascal are less user 'cause missing some C / C++ features and the other think that Pascal should compile and support C++ syntax and operators 'cause it will works better ?
Programming languages are living languages, they develop new features incorporate features from other languages. This is how languages work and how they have always worked.

But that does not mean that a programming language needs to have every feature under the sun or - even more importantly - implemented as a direct copy-paste of some other language. Like attributes which Delphi simply copied from C#... 🙄 If it can't be implemented in a way that corresponds with how Pascal is designed (namely with readability and clarity being important) then it's better not implemented at all.

Take any feature from Pascal you like and most likely it was taken from another language.

I haven't seen that many (old) languages that have an integrated set type. ;)

  • In haskell I can write pass operators the same way as functions:
Code: Bash  [Select][+][-]
  1. sort (<) myList # call sort to use the < operator for the sorting

Operators are simply not first class functions in Pascal, thus something like this will simply not be done.

  • In java if I have a datatype and just want a basic constructor that initializes all of the values I can write:
Code: Java  [Select][+][-]
  1. @AllArgsConstructor
  2. class MyClass {
  3.   public int i;
  4.   public string s;
  5.   // Automatically generates a constructor that takes an integer to set i and a string to set s
  6. }

Something like this is mainly useful for records and there it would be better to implement Extended Pascal's support for true record constants (and thus the ability to use them inline).

  • In Go or Haskell I have compiletime interfaces for generic types, which enforce a generic type to have certain methods:
Code: Bash  [Select][+][-]
  1. myFunc :: Ord a => a -> a# the generic type a needs to be an ordinal

I indeed have plans for improving generic constraints.

  • Languages like Go and Erlang have language level concurrency:
Code: C  [Select][+][-]
  1. func foo() { msg <- "result" }
  2. ...
  3. go foo(); // Run foo asynchronously
  4. fmt.Println(<- msg); // Receive message from foo

The question is whether language level concurrency is really important to have. But in this case one could take inspiration from Concurrent Pascal though I personally would simply prefer to port the OmniThreadLibrary.

  • LUA allows functions to return multiple values as tuples and to easily unpack what you need:
Code: Pascal  [Select][+][-]
  1. first, _, third, remainder = myFunc();
  2. // first and third are elements from the tuple, second element is ignored and remainder is a tuple of all the rest

Implementing a tuple type including constructors and destructors is something I have somewhere on my ToDo list.

  • Python allows a while ... else statement:
Code: Pascal  [Select][+][-]
  1. while x>0:
  2.   // Loop
  3. else:
  4.   // x<=0 from the beginning

In Python this wouldn't be a problem, but in Pascal you would get into problems with existing code that combines ifthenelse together with a whiledo inside the then-branch.

  • Javascript or python allow to write enumerators using a generator syntax:
Code: Javascript  [Select][+][-]
  1. function *fibbonacci() {
  2.   let p1 = 0;
  3.   let p2 = 1;
  4.   while (true) {
  5.     let result = p1 + p2;
  6.     p1 = p2;
  7.     p2 = result;
  8.     yield result;
  9.   }
  10. }
  11.  
  12. for (let i of fibbonacci()) console.log(i); // 1, 2, 3, 5, 8, etc

While conceptually I find the concept of generators intriguing I also find them rather confusing considering how they work.

  • C#, Javascript or Python have language level co-routines
Code: C  [Select][+][-]
  1. async void myFunc() {
  2.   var result = await otherFunc();
  3. }

That would be something one could think about as well. But on the other hand this can also be simply done by a library... Again, not everything that can be done as part of the language needs to be done as part of the language. It can just as well be done as part of some code.

That's one of the major design decisions of C++, to give the user as much control for optimizing their code as possible. C++ is inherently designed to give the programmer the ability to write code that allows the generation of the most efficient assembly and all features in the language are designed around performance.

And that is simply not a major design decision of Pascal. Simplicity, Readability, Maintainability are more important. If you can simply look at the code and understand what it's doing then that is more important than squeezing every last bit of performance out of it. And already some features like operator overloading are counter intuitive to that (or at least they can be if they're abused by the users).

Warfley

  • Hero Member
  • *****
  • Posts: 1930
Re: Feature Request: C operators (xor, or, and)
« Reply #102 on: July 04, 2025, 11:40:17 am »
I haven't seen that many (old) languages that have an integrated set type. ;)
Thats true and it's one of my favorite features. Together with the type associative nature of arrays:
Code: Pascal  [Select][+][-]
  1. array[enumtype] of ...
Pascal originally did a really good job to abstract from the underlying hardware implementations and instead used more mathematical concepts. Which is really great.

Also the variant records of pascal were the first example of an algebraic typesystem which by now basically any language has. If we look at for example Swifts algebraic enum type
Code: Pascal  [Select][+][-]
  1. enum MyEnum {
  2.   First(Int, Int),
  3.   Second(Double)
  4. }
It's not to different from a variant record:
Code: Pascal  [Select][+][-]
  1. MyRec = record
  2.   case (First, Second) of
  3.     First: (a, b: Integer);
  4.     Second: (d: Double);
  5. end;

Sadly the evolution of Pascal was kindof regressing on a lot of those things, e.g. that variant records have been degraded to basically C style unions with extra steps.

Also a notable mention should be to extended pascal which had a lot of really great ideas that never were put into practice. For example, it extends on the variant records to make the variant selector actually meaningful, disable overlaps and allow to use them for initializations with new.

The question is whether language level concurrency is really important to have. But in this case one could take inspiration from Concurrent Pascal though I personally would simply prefer to port the OmniThreadLibrary.
If concurrent programming is required, language level concurrency support can be extremely valuable. That said, it's probably not worth the effort as it requires a lot of design choices in the language (like concurrency safe datastructures, memory management, etc.) while also only serving some very niche applications.
I guess for most Pascal users this wouldn't bring any benefit.
In Python this wouldn't be a problem, but in Pascal you would get into problems with existing code that combines ifthenelse together with a whiledo inside the then-branch.
Well theres still "otherwise" (not so serious suggestion :P)

While conceptually I find the concept of generators intriguing I also find them rather confusing considering how they work.
Considering that enumerators in Pascal already work best as classes, a .Net like implementation where the generator is "just" compiled down to a state machine class where all local variables become class fields and theres a state variable that counts where to continue, would not be too off.

That would be something one could think about as well. But on the other hand this can also be simply done by a library... Again, not everything that can be done as part of the language needs to be done as part of the language. It can just as well be done as part of some code.
Well, language level can do some interesting stuff that libraries can't. Aside the fact that using a library for that is always clunky, you either need to write the co-routines as state machines, or do some weird platform dependent stack and exception handling. But even further, when it's implemented on a language level the code analysis can create dependency graphs between the co-routines to allow parallelization if the scheduler allows this.
Generally the scheduler could be exchangable, by either a single threaded scheduler, a threaded scheduler, or even a distributed scheduler. But especially the latter requires knowledge which global state is touched by which function.

 

TinyPortal © 2005-2018