Recent

Author Topic: Why are types sometimes interchangeable  (Read 17059 times)

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Why are types sometimes interchangeable
« Reply #15 on: January 06, 2023, 04:17:15 am »
This is a prime example of the hostility to pascal I encounter from people who don’t use pascal. There is nothing wrong with pascal in this regard. I have been using it a long long time and it keeps getting better. Some people will just go to great lengths make up excuses not to use it as illustrated here.

Nothing wrong with pascal here?
No. It is not being consistent.
There are are many things wrong with pascal, and this is one of them.

But as I said, I can work around this flaw and am willing to do so because of all the other positive things about the language.

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Why are types sometimes interchangeable
« Reply #16 on: January 06, 2023, 04:19:47 am »
Meters and seconds mean nothing to a computer and it’s the responsibility of the programmer not to add meters to seconds or any other inappropriate things of same data type for that matter.

No, it is the responsibility of the type system if I as the programmer clearly indicated the meters and seconds were different types.
Just like the type system does not yet you assign a boolean to a real.

It would be ridiculous to make a new data type for every simple Numerical variable that shouldn’t be added together.

No, they were explicitly defined as different types.


440bx

  • Hero Member
  • *****
  • Posts: 4023
Re: Why are types sometimes interchangeable
« Reply #17 on: January 06, 2023, 05:40:29 am »
Meters and seconds mean nothing to a computer and it’s the responsibility of the programmer not to add meters to seconds or any other inappropriate things of same data type for that matter.

No, it is the responsibility of the type system if I as the programmer clearly indicated the meters and seconds were different types.
Just like the type system does not yet you assign a boolean to a real.

It would be ridiculous to make a new data type for every simple Numerical variable that shouldn’t be added together.

No, they were explicitly defined as different types.
The current implementations of Pascal do have some faults but, a compiler can only go so far in putting barriers between types.  For instance, as @Joanna pointed out, it must be valid to _divide_ meters by seconds (physicists do like to calculate speed) while it is usually (maybe always) invalid to add meters to seconds but, it would be difficult and cumbersome to have to tell the compiler what operations are and are not allowed between user-defined types.  (no compiler comes to mind that offers that feature.)

Allowing and disallowing operations among units of measure is NOT part of a compiler's type system.  As far as the compiler is concerned, seconds and meters are both numbers, therefore mathematically compatible.

In addition to that, even if it were possible to force the compiler to consider "meters" and "seconds" to be truly different types, doing so would lead to ambiguities and contradictions, e.g, meters = 10.5; seconds = 10.5;  if both meters and seconds accept the same 10.5 constant then they must both be the same type as the 10.5 constant which means they are themselves of the same type (transitivity) which would contradict the declaration that they are of different types.

« Last Edit: January 06, 2023, 05:43:24 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.

arahael

  • Newbie
  • Posts: 1
Re: Why are types sometimes interchangeable
« Reply #18 on: January 06, 2023, 06:34:09 am »
Hello!

If you check the documentation at https://wiki.freepascal.org/Type

It seems that the assignment-compatibleness is a point of difference between FPC and Delphi, though I'm not sure to what degree it's incompatible.

I suppose that if you really wanted it to be alignment incompatible, you would need to wrap the type in its own record, even if it's the only member in that. (I think other languages do this for you in this case).

I haven't tested this, however.

For more background, do give this thread a read: https://fpc-devel.freepascal.narkive.com/ftvTumKs/bug-in-fpc-and-declaring-distinct-types

MarkMLl

  • Hero Member
  • *****
  • Posts: 6685
Re: Why are types sometimes interchangeable
« Reply #19 on: January 06, 2023, 09:08:35 am »
No, it is the responsibility of the type system if I as the programmer clearly indicated the meters and seconds were different types.
Just like the type system does not yet you assign a boolean to a real.

And Wirth tightened this up- corrected it- in his later languages.

No matter how much Object Pascal and its congeners have fudged things, there are numerous problems in the foundation language as defined in the early 1970s.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: Why are types sometimes interchangeable
« Reply #20 on: January 06, 2023, 11:13:02 am »
And how it works in another languages to compare with fpc? For example in c or c++?
In C/C++ the type system is much worse than Pascal's and relies on casting (Basically a no type system except for primives).
OTOH reflective languages like Java and C# have a very strong type system, compared to Pascal.
But why not RTTI to help the system?
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Joanna

  • Hero Member
  • *****
  • Posts: 759
Re: Why are types sometimes interchangeable
« Reply #21 on: January 06, 2023, 05:05:19 pm »
Quote
No, it is the responsibility of the type system if I as the programmer clearly indicated the meters and seconds were different types.

You can’t declare something thing of real type to be different than something else of real type on a whim and this is a good thing. It would probably cause all sorts of problems to enforce things of same type being different types. I’m no expert on the inner workings of compilers but I’m sure the types as they are exist for a reason.

Meters and seconds are in fact the same type. Using aliases does not change this fact. It’s rather naive to think that you can control what a computer does by assigning names of what you expect to things.

Compilers have gotten easier and better but it’s still necessary to pay attention to what you are doing and not be tricked by names that mean nothing to the computer.

Quote
But as I said, I can work around this flaw and am willing to do so because of all the other positive things about the language.
Yes this is what real programmers do , they get things to work.

 I don’t know if ctk has ever created any substantial software at all He has never answered my question on what language he uses.
Although I usually disregard the opinions of people who don’t use pascal I was curious about the reasons behind how types work and it all seems perfectly reasonable. I’m sure a lot of effort has been put into making types work consistently and even having numerical types be somewhat interchangeable for easier use.

 It is really not that hard to properly put things You don’t ever want  mixing into separate record types instead of complaining.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 6685
Re: Why are types sometimes interchangeable
« Reply #22 on: January 06, 2023, 05:10:14 pm »
You can’t declare something thing of real type to be different than something else of real type on a whim and this is a good thing. It would probably cause all sorts of problems to enforce things of same type being different types. I’m no expert on the inner workings of compilers but I’m sure the types as they are exist for a reason.

Well, you can go argue that with Wirth since his post-Pascal compilers had much tighter type rules..

The rather sloppy Pascal rules are, as I've previously explained, because he was in a hurry, and didn't know any better.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Joanna

  • Hero Member
  • *****
  • Posts: 759
Re: Why are types sometimes interchangeable
« Reply #23 on: January 06, 2023, 05:26:35 pm »
I’ve heard that ADA has very strong typing rules but I’ve never used it. It seemed they weren’t teaching it anymore in colleges by the 1990s. It has a similar appearance to pascal. I don’t know if it would do what ctk wants though.
« Last Edit: January 06, 2023, 05:39:42 pm by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: Why are types sometimes interchangeable
« Reply #24 on: January 06, 2023, 06:59:27 pm »
ADA is still widely used in the space, aircraft and military industry and also for these industrie's new products just because  of its rock-solid type safety.
It is also very easy to learn for experienced programmers.

There are experiments with C++ and that still does not do very well regarding overal robustness and recovery.

I once had to train a couple (well, a company) to train from ADA to C++, and almost got shot when teaching them the loopholes to make the C++ right compared to ADA! And these were al scientists, contracted for ESA and NASA. Impossible job.
They are still using ADA for critical jobs and only use C++ for less critical things.
« Last Edit: January 06, 2023, 07:05:53 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6685
Re: Why are types sometimes interchangeable
« Reply #25 on: January 06, 2023, 07:05:22 pm »
Yes. But the reason that Ada- and it's a name, not an initialism- didn't take off was that it required a substantial set of additional utilities to be allowed to bear the name and the combination of all that lot was substantially more than late 80s PCs could handle.

However, Wirth was just one of numerous contributors to the language. If one wants to see his own contributions one has to look elsewhere (come on Joanna, you can use Google better than that can't you >:-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: Why are types sometimes interchangeable
« Reply #26 on: January 06, 2023, 07:09:08 pm »
Yes Mark, it is named after Ada (Lovelace, daughter of Byron)  ;D You knew I know that.. :D
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: Why are types sometimes interchangeable
« Reply #27 on: January 06, 2023, 07:14:01 pm »
Also note Ada can be a firey woman, to the point you want a divorce. <sigh>
She hates pressing the compile button before you have written your code correctly. <citation needed: I made that one up>

Not very surpising, if you are not given working hardware..in here lifetime: since the 21th century there's a working copy of Babbage's design.

Most Pascal programmers would have worn the comparable F9 button out multiple times a week.... :-X
Ada is not easy on that range of the keyboard, think her good friend Mary Shelley (whom, however a bit older, belonged to her inner circle)....could have written the manual... %)
« Last Edit: January 06, 2023, 07:39:44 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Why are types sometimes interchangeable
« Reply #28 on: January 06, 2023, 07:36:13 pm »
I don't think you want to do any form of RAD or Agile software development in ADA.

This programming language, as far as I have seen, requires strict top down design and is used in military and aerospace projects where each programmer writes a few lines of code per day that must then be approved by a control authority.

Major changes are not possible without starting from scratch.

One problem with the "type" concept in programming languages is that "type" denotes at least 2 independent things at the same time: The meaning and purpose of a data structure and its contents and size and compatibility.

For many practical problems this is too restrictive.

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: Why are types sometimes interchangeable
« Reply #29 on: January 06, 2023, 07:45:15 pm »
Mostly correct. (except for the major changes remark, major changes are always a rewrite for the sourcecode)
In my opinion both RAD and Agile are a curse in the wrong - well most - hands.
But what I actually wrote in my appreciation of early Victorian history was the appreciation of a language written many moons later and honors Ada Lovelace with her name, because it is very hard to make mistakes in Ada. But it is also very hard to write for sloppy programmers, not versed in logic, hence Agile nor RAD will ever work in truly fail-safe programming. E.g, from 45+ years experience:
RAD: "Hey, I have a nice user interface, let's make it work! I use components! No need to code classes or methods.!
Agile: Customer hasn't explained wishes good enough, more work, more cost.
Sane: write software based on initial whishes, write a functional document, write a technical document, write code and finish that. Some input from customer is welcome, but first let's finish what you required in the first place.
« Last Edit: January 06, 2023, 08:02:10 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018