Guide to modern Object Pascal for programmers
michalis.ii.uni.wroc.pl
michalis.ii.uni.wroc.pl
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 )
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...
- 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...
[1] https://marketplace.visualstudio.com/items?itemName=kosz78.n...
[2] https://marketplace.visualstudio.com/items?itemName=nwolvers...
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 :-)
I can't easily migrate my biggest project (25 years in making 300k+ LOC), but I am going to use Lazarus for smaller utilities and new projects.
Currently it is best tool for making cross-platform desktop applications.
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...
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
---
So yes, Delphi love is strong, but this was the start of the trouble:
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)...
The main reason is that there are no more grey areas of my code, if something doesn't work, the documentation is missing or doesn't work the way I like, then right-click find the declaration and look at it or change it. This includes the IDE. For someone used to GPL it is no big thing but as a Delphi Programmer it is close to magic.
Portability is awesome. Being able to write your program in Lazarus Windows and then open it in Lazarus in Ubuntu and it just runs is amazing the first time you see it as a Delphi programmer.
The hardest part is migrating when you have third party components. Unless you can get the source code or a free pascal version you're stuck. I have an 85K line wine management system written in Delphi but it uses a lot of third party components so it is never going to just open and re-compile, however I have gone through changing a touchscreen module and it looks and feels the same except it also works in Linux!
Lastly I tend to agree, Delphi was badly mismanaged. For example I had to re-install XE2 on my new Windows 10 PC and I had to go through the most horrible install process getting it activated as it took 3 goes and required emails to support to prove I paid for it, the Official Delphi Forums are just about dead and there is still no free version which means nobody is ever going to learn it.
Note that I have not tried the most recent Delphi versions, but Lazarus 1.6 out of the box is much more stable than Delphi XE2.
There was massive pressure in the 2000's to convert to .NET and C# from corporate managers, auditors and customers, I never understood how this became such a force but In 2005 it was intense to the point of paranoia and a lot of my colleagues converted (Delphi 8 sealed the deal in most cases). Needless to say most are now very happy with C#. if I had stayed an employee and not gone independent at the time it would have happened to me.
As of now I am very happy with my decision to stay with Pascal, Delphi XE2 compiles my legacy code fine even with Windows 10 and All new developments are in Lazarus giving me the ability to support Linux/BSD and ARM processors which more customers are coming to appreciate.
Always got pushback, but it was quite maintainable code and it ran fast.
See also another interesting discussion on Delphi here: https://news.ycombinator.com/item?id=7613543
I really liked Pascal and I always thought it was somewhat unfortunate it didn't survive outside of a small programming niche.
Compared to any other OOPL, C++ is simply ghastly -- a grossly overcomplex mishmash of hacks in the key of C inspired to repent for the multitude of sins that historically bedeviled C, and have since led to a never ending cascade of ill-fated hacks to shoehorn a nearly 50 year old unsafe high level assembly language into the guise of a modern type safe OOPL. History has since shown this to have been a tragically quixotic quest which inevitably and catastrophically spun wildly out of control, mutating and metastasizing into a disgusting chimeric monster that now strikes fear and loathing into the soul of even the most stouthearted digital denizen, who only when lit by the faint glow of a failing CRT, oft have been heard to admit furtively and only under duress in the faintest of whispers:
"Yes. I admit it. I code in C++".
Ahem. Anyway, that's why I use Pascal.Here are some "whys":
1. https://news.ycombinator.com/item?id=11005203
2. http://ian.hixie.ch/programming/
3. http://ziotom78.blogspot.com/2015/01/lfi-data-analysis-with-...
4. http://freepascal.org/advantage.var
5. 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.
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).
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://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic...
I also wonder why C++ is claimed to have no instance function pointers even though std::bind was available since TR1 and boost::bind was available aeons ago. Did the author confuse C++ style function references with C function pointers? But this is like confusing the C++ std::string (which exist only as a library feature) with C-style char arrays.
But the Turbo Pascal 6.0 from 25 years ago certainly was more expressive, feature rich and safer than C of today.
The verbosity of Pascal is welcomed by those that had to maintain programs written by others.
I don't see why anyone would like to implement its own WriteLn.
You have the same issue with professional languages and I never saw anyone complaining about it.
Also C needs Assembly for its IO library and everyone is ok with it.
Don't actually feeling the need to go back though. It's not about language properties anymore, but the library ecosystem. I hated when anything useful in Delphi was a C dll port. You're never a first class citizen.
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.
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.
By the time of TurboPascal the things was great. The peak was around Dephi 3 and it was possible to circle around C/C++ all day long, barring, obviously that the market share and ecosystem was bigger for C/C++ so that answer why you "cant'" do some stuff. Because was not implementation or library for it, NOT BECAUSE THE LANGUAGE.
In CP/M, MS-DOS and a few other home systems, Pascal used to have more compiler variants available than C.
Pascal dialects like Turbo Pascal had all the features of C, plus modules, OOP, type safe enumerations and many other features.
If it wasn't for the rise of FOSS in the late 90's, widespreading the UNIX culture and thus C, Pascal derived languages might have been kept around.
In the late 80's I wrote a framework that allowed multi-user games (via dial-up) to be created. Included 256 color graphics, mouse input etc... had fun fighting IRQ conflicts etc. Good times :)
web servers are just network programming, it's even easier. FPC even ships a HTTP server library with examples in only a few lines of Pascal.
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
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.
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?
(it needs a face-lift, for sure)
Our product Elevate Web Builder allows you to write client web applications using Object Pascal and a RAD IDE:
http://www.elevatesoft.com/products?category=ewb&type=web
(examples are at bottom of the page)
The IDE/compiler/web server used in Elevate Web Builder were written using Delphi. We've also written two small database engines, as well as two ODBC drivers and a .NET data provider, using Object Pascal and Delphi. Object Pascal is a very versatile and useful language that allows you to write applications that do just about anything from front-end UIs to back-end server code. Being able to debug server-side code in the IDE is a life-saver and allows one to get to the root of any coding issues immediately.
FreePascal is also equally nice, albeit a little rougher around the edges in certain places. But, every year it gets better and more polished and has come a very long way since its humble origins.
I used Pascal to write some web apps, i.e. computer graphics explanations [0], visual philosophy [1], and simple games [2].
It's a nice ability to have - being able to share complex programming as you share written text.
However, i wrote my own compiler that among other things output C, which is then Emscripten-translated to asm.js you see.
This is the complete opposite of an easy, low friction path you'd want for web development.
[0] http://orbides.org/apps/superslow.html [1] http://orbides.org/apps/motion.html [2] http://orbides.org/apps/the_bits.html
docs: http://synopse.info/files/html/Synopse%20mORMot%20Framework%...
- with Lazarus/FreePascal, mORMot supports almost all Linux distros, check this forum post: http://synopse.info/forum/viewtopic.php?id=3319
- Check the commit logs of its github repository, see how active the development is.
- The FPC/Lazarus foundation (http://foundation.freepascal.org/) was launched several days ago, check the Projects menu - you can expect a lot of modern language features would be added.
- The newpascal.org site was launched recently to get you started easily for Linux web development with mORMot/Lazarus
It's applicable for both the preshipped fpWeb and Brook, which is my choice of web framework due to its simpler and shorter hand coding.
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.
Delphi has closures, FPC is on development, but in the end I won't use it much. I need performance and maintainability, closures are against those two.
They're called Anonymous Methods in Object Pascal:
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Anonymous...
Free Pascal doesn't support them yet.
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.
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.
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.
No it doesn't.
The automatic reference counting capability of Delphi interfaces always seemed like a good idea to me, but seems to be rarely used.
You mean rarely used by people who are amatures, developers have always been pushed towards programming against interfaces.
However one of the compiler's designers has an experimental branch which allows you to mark classes as being automatically managed and any instance and use of those classes becomes reference counted. So at some point it might become part of the main compiler (although it is probably far from now since AFAIK it isn't something people really ask for from FPC and there are other things to do).
[1] http://foundation.freepascal.org
[2] https://plus.google.com/105481197125997414290/posts/FnLvMteQ...
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.
- 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!
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).
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.
- fast compilation
- fast program execution
- compiled to small (or smallish) native executables (including GUI apps)
- cross-platform
- low-memory usage executables (does depend on code)
- strongly typed
Now ask yourself: how many modern or popular languages can match all the features above. Surprisingly, not that many.
So high time to give it another look. It's changed a lot in 20 years. Check it out:
1. Free Pascal: http://www.freepascal.org/
2. Delphi: https://www.embarcadero.com/products/delphi