Live data from Hacker News

A guided intro to the Free Pascal language

getlazarus.org

61–70 of 102 posts

Re: A guided intro to the Free Pascal language

#61
post #38

Earlier quoted context omitted.

nothing magic about Result keyword, it's just an implicit pointer, you can avoid it completely by using explicit pointers.

It's not magic in how it works, it's just magic in it's syntax. It's a variable you don't have to declare. It's ripe for abuse / mistakes and would be one of the things I'd have lints for and watch closely in PRs.

Nim has the same result variable[1] and I absolutely love it.

It helps avoid the classic "oh, I forgot to return it" bug. Also makes the code more succinct and saves you from having to type an extra line for explicit return.

I kind of get why you would be wary of it, as it is a special variable but compared to other messed up stuff like for example Rust treating a line without semicolon as implicit return, it is a relatively tame solution for this problem and can be easily figured out.

Did you ever had any actual bugs caused by the use of result?

[1] https://nim-by-example.github.io/variables/result/

Re: A guided intro to the Free Pascal language

#62
post #60

Earlier quoted context omitted.

Object Pascal has two magic types, dynamic arrays and AnsiStrings. These are automatically reference counted. Objects and classes have to be managed by hand, yes. In general, expect a lot more compiler magic out of Pascal, a lot of concepts were hacked into the Borland compilers over time.

So, it's closer to C++ wrt safety, not Go or Rust.

That is accurate, yes. Borland C++ and Delphi share the same component library and are interoperable.

Re: A guided intro to the Free Pascal language

#63

Some recent personal projects with laz and fp got me pretty interested in it. I have nothing impressive to show for my work except for a lot of retro-pride when I type in e.g. the snippet which triggers the Pascal program which tells me how old I am. With some bells and maybe a couple whistles. I was surprised to learn that there was Pascal for the C64, which I thought was more of a "BASIC or bare metal" system. I to…

For C64 and other retro platforms with Pascal, there is TRSE:

https://lemonspawn.com/turbo-rascal-syntax-error-expected-bu...

If coding with C, like text adventure games, then for example:

https://github.com/xet7/darkesthour

Re: A guided intro to the Free Pascal language

#64
post #52
post #51

Note for people who don't know much about FreePascal. It is a full-featured and very fast compiler. The resulting program is a rival for the best output of C/CPP compilers. It can be used in the style of simpler languages like Go and is almost as safe as Rust in a much faster manner. It has a great but old-looking IDE, Lazarus. It has been under active development for decades and is used for proper projects like: htt…

You mention that Pascal is almost as safe as Rust. This comes as a great surprise to me, because I was under the impression that Pascal and C are very similar. (Though I hear the strings, at least, know their own size!)

I have no experience with Free Pascal, but its predecessor Delphi was a lot safer (and easier) to use because of dynamic strings and arrays. You could use it almost without touching pointers ever (Win apis were the main reason for using pointers, as they were C based). In those days when stack overflows were the main security issue for majority of apps, Delphi apps were considered way safer than VC++ apps.

Re: A guided intro to the Free Pascal language

#65
post #52
post #51

Note for people who don't know much about FreePascal. It is a full-featured and very fast compiler. The resulting program is a rival for the best output of C/CPP compilers. It can be used in the style of simpler languages like Go and is almost as safe as Rust in a much faster manner. It has a great but old-looking IDE, Lazarus. It has been under active development for decades and is used for proper projects like: htt…

You mention that Pascal is almost as safe as Rust. This comes as a great surprise to me, because I was under the impression that Pascal and C are very similar. (Though I hear the strings, at least, know their own size!)

I learned programming at school in Pascal and didn't have troubles with memory safety. FreePascal/Delphi has good standard library to work with strings and dynamic arrays and objects, and as long as you follow very simple convention with TObject.Create() and TObject.Free; you won't have memory safety problems.

I didn't really have a need to work with pointers and do pointer math in Pascal, because language itself provided facilities to work with heap objects safely.

Also standard Pascal compiler added array bounds safety and many other checks, and you would easily find these errors during program execution (there wont be a silent exception).

Also because Pascal compiler is LL(1) single pass compiler, you could easily do a cycle of: edit code, compile (That compiler enabled developer experience of like modern Python/Javascript

Unlike C++ which spent enormous time evaluating macros, compiling, linking, etc

Re: A guided intro to the Free Pascal language

#66
post #56
post #51

Note for people who don't know much about FreePascal. It is a full-featured and very fast compiler. The resulting program is a rival for the best output of C/CPP compilers. It can be used in the style of simpler languages like Go and is almost as safe as Rust in a much faster manner. It has a great but old-looking IDE, Lazarus. It has been under active development for decades and is used for proper projects like: htt…

> It can be used in the style of simpler languages like Go and is almost as safe as Rust in a much faster manner. What does this mean, exactly? Usage in the style of Go requires garbage collection and being safe like Rust (without GC) requires a borrow-checker, and as far as I know Free Pascal doesn't have either.

A borrow-checker isn't the most practical or the only way to provide safety. For example, a string type can have an offset for creating O(1) string slices and point to a shared counter. That way when mutating the string, it creates a fresh copy iff the counter is bigger than 0.

I am working towards this in https://github.com/planetis-m/cowstrings

Re: A guided intro to the Free Pascal language

#67
post #42

Earlier quoted context omitted.

In these days, Lazarus and FPC are a valid choice instead of Delphi, except when you are doing some heavy component based codes, like organization oriented projects. Plus side is Lazarus can produce a project and UI for almost any OS.

I would jump back to fpc/lazarus after twenty years if devexpress supported it.

100%. My projects are DevExpress heavy.

Re: A guided intro to the Free Pascal language

#69
I think the popularity of pascal has something to with Modula-2 (the successor of Pascal invented by Wirth) having been recently included as an officially supported language in gcc alongside Rust. I tried lazarus again, I was amazed. It is as simple as using VB6 for creating quick GUIs that run everywhere. Turbopascal is blazingly fast, produces efficient and small binaries.

Pascal also has libraries for nearly everything, check awesome pascal for a list of actively maintained third party libraries: https://github.com/Fr0sT-Brutal/awesome-pascal

I feel like pascal is a hidden gem.

Re: A guided intro to the Free Pascal language

#70

Earlier quoted context omitted.

It's not magic in how it works, it's just magic in it's syntax. It's a variable you don't have to declare. It's ripe for abuse / mistakes and would be one of the things I'd have lints for and watch closely in PRs.

Nim has the same result variable[1] and I absolutely love it. It helps avoid the classic "oh, I forgot to return it" bug. Also makes the code more succinct and saves you from having to type an extra line for explicit return. I kind of get why you would be wary of it, as it is a special variable but compared to other messed up stuff like for example Rust treating a line without semicolon as implicit return, it is a re…

If you forgot to return a value, a function shouldn't have compiled. In Nim you can easily forget to return something or have a hole in your branching and get a defaulted value, instead of a compiler error.

In some cases an implicitly declared variable feels neat and convenient, but I'm not sure it's worth it.

Post reply on HN