
Guide to modern Object Pascal for programmers - open-source-ux
http://michalis.ii.uni.wroc.pl/%7Emichalis/modern_pascal_introduction/modern_pascal_introduction.html
======
samuell
I was tasked with building a small utility for copying out a few GB of files
from a super-complicated folder structure, and convert it into a different
structure, with the requirement that it should have an interactive GUI (to do
various selections interactively), and run natively on Windows and Mac.

Couldn't have found an easier route than to build this in FPC with Lazarus.

Even though I had hardly coded a line in the language before, it was built
from scratch to "happy end-user" in 80 hours, including learning the language.

I built it on Xubuntu, then imported it on my Windows VM and compiled, WITHOUT
A SINGLE CHANGE! On Mac, I needed to add a missing import statement or so.

Simply an outstandingly productive tool for open source, cross-platform GUI
development.

(The tool: [https://github.com/NBISweden/mdc-file-
export](https://github.com/NBISweden/mdc-file-export) )

~~~
samuell
Btw, a shoutout to the awesome OmniPascal project, which allows you to write
Delphi and FreePascal in the Visual Studio Code editor (when you are not
building GUI apps, and and/or don't need a full blown visual IDE, or just for
navigating around in legacy code bases):
[http://www.omnipascal.com](http://www.omnipascal.com)

Unfortunately, code completion is so far only available on Windows [1], but
will hopefully come in due time (you can vote for the issue in [1]).

[1] [https://bitbucket.org/Wosi/omnipascalissues/issues/6/add-
ric...](https://bitbucket.org/Wosi/omnipascalissues/issues/6/add-rich-
language-support-for-mac-and)

~~~
girvo
It's amazing to see how fast VS: Code is picking up extensions with full
autocomplete, go-to definition, and other IDE-styled features. Atom's
equivalents are rarely as nice, unless you're using Nuclide because they wrote
their own damned framework inside the editor to achieve those features! I
think it's because VS: Code's APIs are built around exposing those sorts of
features nicely and simply.

\- OCaml [0]: IntelliSense, go-to-definition, interactive debugging. This
plugin is so well done that I feel VS Code is the best editor for my OCaml
work now!

\- Nim [1]: IntelliSense, go-to-definition, linting, Nimble building
integration

\- Purescript [2]: IntelliSense, compilation, linting, quick fixes for common
errors, and type inspection

Seriously, more and more are added every day, which is just awesome. I'm still
annoyed at small UI parts of VS: Code, but honestly the functionality and
speed make it second to none in my opinion. \---

[0]
[https://marketplace.visualstudio.com/items?itemName=hackwaly...](https://marketplace.visualstudio.com/items?itemName=hackwaly.ocaml)

[1]
[https://marketplace.visualstudio.com/items?itemName=kosz78.n...](https://marketplace.visualstudio.com/items?itemName=kosz78.nim)

[2]
[https://marketplace.visualstudio.com/items?itemName=nwolvers...](https://marketplace.visualstudio.com/items?itemName=nwolverson.ide-
purescript)

------
boznz
Nice little intro, everything there would compile fine with Free Pascal on
Linux, Windows or OSX

BTW Shoutout to the FreePascal/Lazarus team, the improvements over the past 12
months have been great and finally convinced me to make the move from Delphi.
I even created my first Real Linux desktop program two months ago to replace
an XP status display screen in a factory.. A real big step for me :-)

~~~
e12e
This is interesting - I knew work was ongoing on FPC/Lazarus - but not so much
that it might draw people away from Delphi. Could you say something more about
what you used to miss, that's now available - and how you use Delphi/Pascal?

~~~
mamcx
Delphi is the MOST mismanaged language ever produce on earth! and have survive
several changes of owner.

Currently, this is the storm, where a large team on charge of the IDE and
other stuff is fired:

[https://plus.google.com/105481197125997414290/posts/FnLvMteQ...](https://plus.google.com/105481197125997414290/posts/FnLvMteQ4dU)

The gossip now is that only 8 people are left on charge of it:

Paul said

>2016/06/24 at 21:14 >Yes and here some hot news.

>Delphi and C++Builder Team now is only 8 developers >IDERA contract free
lance developers without experience in >Delphi and pay per job

Is ironic, but in one of the oldest forums of Delphi (where I'm moderator)
some of us have left the language long ago (or more exactly, use it sparly),
yet still are there!

And this one was our discussion (spanish)

[http://clubdelphi.com/foros/showthread.php?t=90494](http://clubdelphi.com/foros/showthread.php?t=90494)

\---

So yes, Delphi love is strong, but this was the start of the trouble:

[https://www.quora.com/Why-did-Borland-
fail?share=1](https://www.quora.com/Why-did-Borland-fail?share=1)

\---

So the thing is Delphi improve a lot, yet is mismanaged, cost too much, the
only way to get bugs fixed is buy next version and each few months yet another
company buy it.

The thing is so crazy that some people are considering seriously do a buy from
the community (ie: Pay money to buy the product)...

~~~
wila
Every half year there is a new version and then you get new bugs.. for which
you have to buy the next version to get it fixed.

------
randcraw
Wonderful! I've long been a fan of end-of-life Turbo Pascal and Object Pascal
thereafter. I love the language's simplicity, type safety, and speed. To my
eye, Object Pascal is the goto language for minimalist OOP. In the spirit of
C, it's short, sweet, and sufficient.

------
hudell
I worked with different versions of Delphi for 7 years. I miss it sometimes.
The language was quite good, but people would always judge it because of the
IDE that made it "too easy"

~~~
r00fus
Delphi was years ahead of it's time. I remember coding a patient data entry
system (for the VA) and submitting machine learning college courses.

Always got pushback, but it was quite maintainable code and it ran fast.

~~~
voltagex_
I'm a programmer today because someone gave me a pirated copy of Delphi (6?).
Sorry Borland!

See also another interesting discussion on Delphi here:
[https://news.ycombinator.com/item?id=7613543](https://news.ycombinator.com/item?id=7613543)

~~~
bunnybender
I started programming "for real" with Turbo Pascal (5.5 probably) while in
high school. It was easy to copy it for personal use from there. Although
later I actually went and bought Borland Pascal 7.0, a big and fairly
expensive box with the disks and lots of books inside. I think I wanted it to
be able to create Windows applications, but ended up hating Windows, so really
only utilized a little of its potential..

~~~
tjl
I saved my money and bought a copy of Turbo C. Before that, I used both Basic
(first on the TI 99/4A then on QBasic) and Pascal (on computers in schools)
with some Logo, Icon, and later AutoLisp (for AutoCAD).

I really liked Pascal and I always thought it was somewhat unfortunate it
didn't survive outside of a small programming niche.

------
alayne
But why. I don't understand why you'd use Pascal today when you could use C++.
I jumped over 25 years ago and never missed Pascal the language, only the
Turbo Pascal development environment. Many languages later I still have never
wanted to go back and write in any Pascal variant. It's a verbose, weak, and
inexpressive language.

~~~
clouddrover
> _I don 't understand why you'd use Pascal today when you could use C++._

Here are some "whys":

1\.
[https://news.ycombinator.com/item?id=11005203](https://news.ycombinator.com/item?id=11005203)

2\. [http://ian.hixie.ch/programming/](http://ian.hixie.ch/programming/)

3\. [http://ziotom78.blogspot.com/2015/01/lfi-data-analysis-
with-...](http://ziotom78.blogspot.com/2015/01/lfi-data-analysis-with-
fpc.html)

4\. [http://freepascal.org/advantage.var](http://freepascal.org/advantage.var)

5\.
[https://www.embarcadero.com/products/delphi/features](https://www.embarcadero.com/products/delphi/features)

Object Pascal has changed a _lot_ in the last 25 years. You should check out
modern Object Pascal. It's pretty nice.

~~~
unscaled
Reading through the docs, it was nice seeing that Pascal wasn't sitting still
through all the these years. Generics, extension methods (class helpers) and
value types - though the last features actually existed way before class, and
I've extensively used it back in the day, old style objects are unsafe and
were abandoned for a while without being fixed.

Too bad that memory management is still tedious and categorically unsafe with
all sorts of crazy hacks like a TComponent hierarchy and reference counting
that exists only for interface.

It was a reasonable trade-off for me back in the days where the best thing C++
had was auto_ptr and a bunch of incompatible vendor specific classes.
Nowadays, it's a world I wouldn't want to come back to (or I would happily
programming C).

~~~
clouddrover
> _Too bad that memory management is still tedious_

I don't find it onerous. It also depends which compiler you're using. Delphi
uses Automatic Reference Counting for Android and iOS:

[http://blog.marcocantu.com/blog/delphi_arc_android.html](http://blog.marcocantu.com/blog/delphi_arc_android.html)

[http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic...](http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic_Reference_Counting_in_Delphi_Mobile_Compilers)

------
Animats
If only programming had gone that way. It almost did. The original Macintosh
was programmed mostly in Apple Pascal. Wirth's original Pascal had some
serious limitations, which led to far too many Pascal variations.
Unfortunately, none of them won out over C.

~~~
solidsnack9000
Do you think device drivers or servers like Nginx could ever have been written
in Pascal?

~~~
int_19h
Let me give you just one example adding to the other comments. In
Turbo/Borland Pascal, you could declare global variables (including arrays)
allocated at a specific memory address, e.g.:

var video: array[0..4000] of byte absolute $B800:0000;

It also had a special modifier for functions, that made them work as interrupt
handlers. And inline assembler with nice, readable syntax that allowed
addressing variables directly.

Consequently, it was actually easier to do most low-level DOS hackery in
Pascal rather than C.

So yes, I'd expect it do just fine for drivers, as well.

~~~
SyneRyder
"Consequently, it was actually easier to do most low-level DOS hackery in
Pascal rather than C."

I remember downloading source code in the mid 90s of various DOS graphics
effects from the demoscene, and being surprised how much of it was in Pascal.
And also frustrated, because I'd gone with Turbo C++ instead & had to try
porting the code across myself.

------
vanilla-almond
Does anyone use Pascal for web development (cgi, dynamically generated web
sites)?

I would love to use a fast, low-memory, natively-compiled, strongly typed
language with a clear, readable syntax. Pascal meets all these requirements.

Golang is the other language I'm considering. It has many web-related
libraries, excellent documentation and a lot of momentum. Free Pascal,
unfortunately suffers from fragmented documentation (the wiki is often out-of-
date and hard to navigate). Despite that, I still prefer Pascal syntax over Go
(yes, really).

So, if you are using Pascal for web development, what has been your
experience? Would you recommend it?

~~~
amelius
The feature you really want for web-development is closures. I can't imagine
writing event-handling code without them. As far as I know, Pascal does not
have closures.

Unfortunately, with closures you need good memory handling. And this means
either a complicated type-system such as Rust's, or a garbage collected
environment. The way C++ does closures is too dangerous for event-driven code,
imho.

~~~
Artlav
Why do you want closures for the web code? What do they add? What is hard to
do without them?

~~~
amelius
To handle event call-backs. Generally, inside an event-handler, you want
access to variables in a higher scope.

~~~
mhenr18
Two things:

1\. You don't need closures at a language level to do event callbacks. Just
the ability to refer to functions by reference and call those references.
Closures certainly make it syntactically nicer, but you can work without them.

2\. You don't need event callbacks in a webserver to make it performant. The
memory/CPU overheads needed to make closures work are essentially identical to
what's needed to make blocking threaded code work, as long as the threading is
done in userspace and you have support for expanding stacks. Even if you don't
have support for those niceties, modern kernels and hardware are perfectly
capable of handling thousands of OS-level threads.

------
crypt1d
This is like a blast from the past. My first interaction with programming was
with Borland Delphi 6 which had its own dialect of Object Pascal. Poor
internet connection and no stackoverflow had me figuring out programming on my
own, mainly by using Delphi's help books and looking at code examples. Which
is probably why I eventually lost interest - I couldn't figure out complex OP
concepts on my own at that age.

Fast forward to the present, I really envy the people learning programming
today for the first time. The amount of possibilities and resources now is
many orders of magnitude bigger, making learning so much more enjoyable.

Edit: grammar

~~~
agumonkey
I had a memory lane trip few months ago. Got to run turbopascal 7.0 in dosbox.
It's an amazing piece of software. The included help is great. And the
language was deceptively simple. I didn't understand the value of intervals,
set types, even ordinals (succ and prec)... Pretty neat.

Small sidenote: even QBasic was amazing for a free code environment in these
days. The language is bare, but QBasic had some form of modularization. I
thought nothing of it at the time, but it feels they tried to make people
think in terms of isolated "objects" not large source files full of global
variables.

~~~
nickpsecurity
QBasic was what I started on. Built my original hacking tools and 4GL
prototype in it. The semi-memory safety, simple syntax, and rapid compilation
let me iteratw stuff out quickly.

------
johnthuss
Manual memory management is the weak point of Pascal. It limits functions to
never returning newly constructed objects, which really limits the
expressiveness of APIs both in the standard library and in custom code.

The manual reference counting system in old objective-c provides a better
solution which while still cumbersome, doesn't prevent good powerful APIs.

The automatic reference counting capability of Delphi interfaces always seemed
like a good idea to me, but seems to be rarely used.

~~~
clouddrover
> _It limits functions to never returning newly constructed objects, which
> really limits the expressiveness of APIs both in the standard library and in
> custom code._

How? Set the return type of the function to be the object type you want, then
result := TYourObjectType.Create; and you'll return a newly constructed
object.

------
samuell
Interesting with the new FreePascal and Lazarus foundation, which was just
started a week ago, to support development of it as an alternative to Delphi
[1] (Source [2])

[1] [http://foundation.freepascal.org](http://foundation.freepascal.org)

[2]
[https://plus.google.com/105481197125997414290/posts/FnLvMteQ...](https://plus.google.com/105481197125997414290/posts/FnLvMteQ4dU)

------
regularfry
I wonder, if they'd added some sort of concurrency primitive to the language a
few years ago, whether it might have stolen Go's crown.

~~~
vanilla-almond
It's a nice thought, but Pascal's age and its verbose (but highly readable)
syntax means that many programmers will never give it more than a passing
glance (regardless of the modern features it has to offer).

~~~
chappi42
Age and verbosity has imho no influence. I'd rather say the following points
are important:

\- the project is not on github, issue tracker looks like from 2 centuries
ago, ditto website, several different forum (maillists) instead of e.g. one
discourse instance for the 'whole pascal project'

\- the granularity of the code libraries is difficult (compiler, rtl,
component sets (ui and non-ui), tools, lazarus, web, ...). You cannot just
clone one of these parts and work on it

\- no (fully supported) Cocoa support and thus the Mac platform is a bit
handicapped (32bit Carbon), too many obscure legacy platforms, too many
options, too complicated

\- no modern defacto standards, e.g. md/rst formatted docu, different
syntaxes/dialects (fpc, delphi, mse, oxygene, smartpascal, etc...)

\- iirc license situation is a bit 'chaotic' (some LGPL 2.1 (with exception),
some GPL 2 (3?), some MPL 1.1/2, more?) and in comparision to newer languages,
e.g. go/rust (MIT, APL) the licenses are more (copyleft) restrictive. I like
that more modern environments dropped ideological for pragmatic

\- afaik no big company/organization invests money into the pascal ecosystem
(if this were the case, probably most of the points above would be different)

This is just to say why I think it is not more popular, I very much appreciate
the project/work, it's great!

~~~
samuell
The forums (and I think wiki) etc are astonishingly up-to-date though in my
experience, and I have mostly got a useful answer in the forum within an hour
or so, so I would say, don't judge the book by the cover :)

~~~
chappi42
I agree. Nevertheless in the world of today the cover is important too :) I
think...

------
philippeback
FreePascal has indeed a lot of good stuff.

I wrote a ton of Pascal a long time ago and always liked OWL for Windows
development. Compared to MFC, well, that was much better to they eye.

The main issue to wider adoption is that there are lots of integrations to do
in modern applications and I am not sure that FreePascal can catch up.

Still, it is great for coding, as compilation is super fast and one can pretty
much understand what's going on.

~~~
leledumbo
I assure you, it can. Be it through API, custom socket protocol, bindings, no
problem. When one doesn't exist yet, creating yourself is not a big deal.

------
ivan_gammel
Last time I've been programming on Pascal was almost 20 years ago, just before
I've learned Java. The Delphi was a breakthrough in 90s, but today, when we
have MLoC-size apps, this language is just too outdated, fighting the wars of
the past and preserving some unnecessary legacy. Memory management? Dependency
management? Reflection and generative programming support? There are some
things, of course, that are still nice to have in languages like Java (I liked
the class helpers), but, thinking about development productivity and code
quality, I'm not sure this can be called anything else but a steampunk toy, as
modern as contemporary replica of some Art Nouveau thing.

~~~
vidarh
The vast majority of apps today are still small, and certainly nowhere near
MLoC-size.

It certainly lacks features many of us takes for granted. But people e.g.
still write C, that is far more primitive, so if people want to do Object
Pascal, why not.

Though it's a shame to see it effectively win over a language like Oberon (if
one first is to stay in the Pascal lineage).

~~~
ivan_gammel
Thanks to lots of available 3rd party frameworks, modern web portal can be
just 50-100KLoC, but add all the dependencies and you may become really close
to million lines. All these dependencies have to be resolved, loaded and
processed in order to compile your code, namespace and version conflicts must
be avoided, test dependencies separated from production ones etc, so you
cannot ignore it as some magic on the back stage. Of course, there's still
some room for low-level utilities or one-time scientific calculations, for
which Pascal can be used (hell, I remember that times, when we, the kids,
hacked our school network to get super user access by writing keyloggers and
simple viruses on TP6), but should it be a language of first choice for that
today?..

~~~
leledumbo
I agree with your first 2 sentences, which Modern Pascal is just as capable,
if not more, than Java. Lazarus is an example of such complex project, it has
near 5 MLoC (without external dependencies) according to openhub and is
managed just fine, thanks to the compiler's smart dependency management.

Modern Pascal is a very good language of choice when you have tight budget but
still want to compete with enterprise Java systems. The low resource
requirement is one prominent factor while the performance is similar if not
better in real world applications. We have one of our apps (web application
with embedded web server, proxified by nginx) running constant 100MB RAM only
at peak, single process, while serving tens of thousands of users, backed only
by a single SQLite database. Even the 100MB is mostly due to our template
engine automatic caching system.

Java will win in microbenchmarks, but that's the best HotSpot JVM can do.
Tight loops and complex calculations are actually seldom happened in
enterprise apps, while context switching happens a lot more often as (a lot
of) users move from one context to another frequently.

~~~
ivan_gammel
Thanks, that's really interesting. I'm not surprised that Pascal applications
are very fast - after all, it's native. My main concern is the maturity of
ecosystem - tools, libraries, frameworks, everything that defines the TCO
(development + distribution + maintenance) of modern application. It's good to
know that something exists in this field and there are examples of live apps
and it would be interesting to compare the stacks and their capabilities.

