Recent

Author Topic: Can this be done in FPC ?  (Read 7736 times)

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Can this be done in FPC ?
« Reply #15 on: November 25, 2018, 09:27:38 pm »
Ditto for several other declarations: strings (not shortstrings, of course), dynamic arrays, interfaces...
  Indeed.  The list is long.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Can this be done in FPC ?
« Reply #16 on: November 26, 2018, 05:40:46 pm »
Thanks for the comments.

I have to confess that I am a sugar addict.

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: Can this be done in FPC ?
« Reply #17 on: November 27, 2018, 05:19:14 am »
Pascal itself is syntactic sugar for machine code.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Can this be done in FPC ?
« Reply #18 on: November 27, 2018, 06:05:45 am »
Pascal itself is syntactic sugar for machine code.
Not really.

It' s more accurate to think of Pascal and other high level languages as macro languages with richer descriptive abilities than plain machine code.    The additional information contained in the richer descriptions is useful to ensure code integrity (and often efficiency).

Syntactic sugar changes the presentation but rarely adds anything useful, on the contrary, many times the syntactic sugar creates problems, which almost inevitably lead to poor solutions to the problems, thereby creating more problems.  it's a vicious circle.


« Last Edit: November 27, 2018, 09:45:52 am by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Can this be done in FPC ?
« Reply #19 on: November 27, 2018, 09:48:49 am »
it's a vicious circle.
It just demonstrates the lack of expression in the English language: circulus vitiosus does not mean the circle is a threat or in any way mean... Anyway, Latin is a (n almost)  dead language and assembler ( for any processor) is simply a notation. One could argue that it...... (oh, well)
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Can this be done in FPC ?
« Reply #20 on: November 27, 2018, 10:09:42 am »
circulus vitiosus does not mean the circle is a threat or in any way mean...
That's quite a departure from the interpretation that has prevailed for centuries.  Good thing you're here to "modernize" it.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Can this be done in FPC ?
« Reply #21 on: December 22, 2018, 02:12:57 am »
In C++, being fast is everything. You never copy a value, if you can pass a reference to it. Because copying takes time. Or, adding a count to an array (like, a string) is bad, because keeping it up to date costs a lot of overhead.

That's also why there are many ways to do the same thing in C++, of which most are considered "harmful". It's up to the programmer to know which ones and when, and not to use them.

Really, every time someone talks about the "do's and dont's" of programming, they're either discussing C++ or JavaScript. Because those two are a minefield. Almost all the things your really shouldn't do, are a non-issue in almost every other programming language. They won't allow it.


In Pascal, correctness is everything. It goes through great lengths to prevent you shooting yourself in your foot. Everything should be logical and consistent. It should be obvious to the programmer what is going to happen. Just casting any data type to and from a generic pointer is not something you want to encourage.

Most of the time, you don't want a reference to a variable, you want a copy. Simply to prevent many bugs. And if you really want a reference, specify it ("var").

In C++, there are three obvious ways to pass a parameter (copy, pointer, reference). Most of the time, it is not obvious which one to choose, and your program probably compiles anyway. While you have to use the exact same one as the function expects. Which is probably why the most common data type is "void *". Or: no defined type, the compiler will allow anything.


In my experience, most Pascal bugs are caught by the compiler. Most C++ bugs happen at a different location than where the runtime exception happens. And it's far easier to create them.

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: Can this be done in FPC ?
« Reply #22 on: December 22, 2018, 09:39:42 am »
In C++, being fast is everything. You never copy a value, if you can pass a reference to it. Because copying takes time.
Except when copying is faster because it's done only once, while pointer dereferences add a small overhead. Or because pointers are larger than the data being copied, or because arrays of pointer values (used e.g. by jump tables) waste precious cache space.

Though that's probably very rare.

Or, adding a count to an array (like, a string) is bad, because keeping it up to date costs a lot of overhead.
My impression was that many custom string solutions were created specifically to include a length field.
« Last Edit: December 22, 2018, 10:52:48 am by creaothceann »

fasdfasdfasdfasdfasdf

  • New Member
  • *
  • Posts: 45
Re: Can this be done in FPC ?
« Reply #23 on: December 22, 2018, 11:33:51 am »
In my experience, most Pascal bugs are caught by the compiler. Most C++ bugs happen at a different location than where the runtime exception happens. And it's far easier to create them.

That's why you use things like ClangTidy etc. If you find a bug in pascal.. expect to wait a long time for someone to fix it.
Same for Delphi.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Can this be done in FPC ?
« Reply #24 on: December 22, 2018, 11:50:28 am »
That's why you use things like ClangTidy etc. If you find a bug in pascal.. expect to wait a long time for someone to fix it.
If it is a real bug and not a feature request it gets usually fixed very quick in FreePascal.
Quote
Same for Delphi.
That's another matter. They sell bug fixes as features.
Specialize a type, not a var.

 

TinyPortal © 2005-2018