Forum > Other

Comparing Pascal and Rust

(1/6) > >>

OwlOfTime:
Hi, I'm Pascal user not Rust user, but I take a look on that language last days.

What I've seen is:
- Rust uses only struct with associated methods (no classes), in FPC we call it advanced records.
- The memory is "moved" and can be only one owner at a time. Seems that the simple assign of a variable just moves it, in FPC we copy the variable, so we have copies. Also in Rust there is only a single pointer to a single data at the same time. This says to help to prevent having a variable for example in threads and in other places, and change them at the same time.
- There are references as well. Seems that in FPC this can be const modifier in functions and procedures?
- The types are a bit more strict than in FPC, for example there is no type conversion automatically, say you assign an Integer to a Double, that's not directly possible.
- The memory is erased when the scope ends, say a function. Same in FPC I think.

Well that's the far I get now with that language.

I see some things:
- Advanced records are available in FPC. No difference there.
- The memory is in FPC by default a copy of that record, not a move. Is possible to do a move and that the first instance is not valid anymore in FPC? Like moving a record to other record, inside the same function and / or to another functions.
- Passing a reference can be done with const or var parameters. In Rust it will be "&" for const and "mut &" for var. So no difference there.
- The memory is erased as well in FPC, when the functions ends, that is what I understand, so no difference.

So, they say Rust is more safe. On my experience is just that the compiler is very smart telling you where are the possible bugs you're making when coding. Other than that I see no point of using Rust.

Like typescript and javascript, the only difference is the compiler preventing you doing invalid stuff.

There's a mode or can be added to FPC that will help to prevent bugs? I alredy see some in Lazarus code editor, like unused variables, not initialized variables, missing return in a function. A lot of warinings about conversions.

Well that's it, I'm not saying one languages is better than the other. But just saying that FPC has already features that make it similar to Rust.

PierceNg:
Rust has an evangelism strike force. Pascal has not. :P

Someone will surely correct me if I am wrong: Pascal records are stack-based, classes are heap-based, objects default to stack but can be heap-based. Dunno about advanced records. Rust structs default to stack but can be heap-based. Are Rust structs directly equivalent to Pascal advanced records?

In terms of language features, most of the newer languages like Rust, Swift, Kotlin etc support nullable or optional types. Such types are supposed to help deal with the null reference, which inventor Tony Hoare has called his billion dollar mistake.

MarkMLl:
Put another way, people who say Rust is good are basically praising Pascal-like functionality which they perceive as superior to C-like functionality.


--- Quote from: lainz on April 24, 2021, 06:11:13 am ---- The memory is erased as well in FPC, when the functions ends, that is what I understand, so no difference.

--- End quote ---

Not quite. By and large FPC makes variables inaccessible when they go out of scope, but the memory- and this includes strings which have been used for passwords etc.- is not erased/blanked/wiped/zeroed/randomised.

MarkMLl


dbannon:

--- Quote from: MarkMLl on April 24, 2021, 09:40:19 am ---......
By and large FPC makes variables inaccessible when they go out of scope, but the memory- and this includes strings which have been used for passwords etc.- is not erased/blanked/wiped/zeroed/randomised.

--- End quote ---

And that would be because blanking out very large blocks of memory can be a time consuming thing. But few of us would store a (eg) password in a huge data array, should fpc null out smaller allocations and leaving the huge arrays alone ?

OK, thinking out loud, suppose an ANSIString can be told to blank out its memory before it goes out of scope ?  ANSIString.NullOnFree : boolean = false    ?

Davo

avk:

--- Quote from: MarkMLl on April 24, 2021, 09:40:19 am ---... but the memory- and this includes strings which have been used for passwords etc.- is not erased/blanked/wiped/zeroed/randomised...

--- End quote ---

Does Rust do that sort of thing?
And seems like Rust has managed to outperform C++ in syntax ugliness?

Navigation

[0] Message Index

[#] Next page

Go to full version