Hacker News new | ask | show | jobs
by speed_spread 1270 days ago
I used to be a hard Delphi/Pascal guy and still think it is much better than C for it's strong typing and overall "squareness". But I'd have a hard time going back to it nowadays. The 'var' section, magic "Result" variable and begin/end pairs are just from another age.

Programming languages have advanced _a lot_ since Pascal was created. It's core principles remain valid (safety by default, readability, flexibility). But the feedback loop between language design and actual usage is much tighter thanks to the Internet and open source.

Some things I still miss from my Delphi days are the language-level enumsets, near-instant compilation and RAD tooling (GUI builder).

3 comments

I pretty much started programming in Delphi (which was very popular in this part of the world, and still is to some extent).

After using VCL for a year or two, I started branching to other, much more popular programming environments, and was shocked about how bad they were for GUI development. Why would anyone put themselves through the pain of writing interfaces manually using programming languages not designed for it (like C) when you could design everything in a convenient GUI builder?

It's sad they decided to focus on the "enterprise" market and buried themselves in the long term. Writing GUI stuff in Delphi was (probably is) a pleasure: they compiled quickly, looked native, and ran fast on my shitty hardware.

"The 'var' section, magic "Result" variable and begin/end pairs are just from another age...Programming languages have advanced _a lot_ since Pascal was created."

I understand why some programmers dislike Pascal's syntax, but C and C++ are also old and still popular (including for new projects). Syntax and semantics are closely entwined but C and C++ syntax still influence "modern" languages.

Nim has a result variable, it's very handy.
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/

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.

Ha, I'm quite used to Rust's last-expression-is-the-value and I also get why some would think it's weird but I find it actually works quite well in practice. Each language has its gymnastics and special moves, I guess. Back to Pascal, I'm not opposed to Result usage per se and I understand the appeal since it's what I grew on. My concerns are more about code maintenance in long-ish functions - I don't have a particular example of mis-usage, but I'd be wary of late reassignments overriding a previously set value. Separating exit points from return value assignment could let code become hard to follow and create situations where it's easy to misread the actual outcome.