8 ms·
Modern Object Pascal Introduction for Programmers
- sysrpl 6y agoIn my experience Free Pascal, that is what the article refers to as "modern pascal", is a great language and compiler. It compiles to native code, to JVM bytecode, and there is even a tool to transpile to Javascript. Unfortunately it suffers from a stigma inherited from it's origins as an old "teaching you how to code" language rather than a real language. Never mind the fact that Delphi (the precursor to "modern pascal") was the brain child of Anders Hejlsberg before he was snatched from Borland by Microsoft, when Anders had remade Turbo Pascal (already great) into a fantastic product. Bill Gates said "The only thing wrong with Delphi is that it's not made by Microsoft". In short, Free Pascal a fantastic multi platform language and compiler, but suffers from a lack of popularity due to being considered something old and not very modern, even though it has all the modern features one might need.
- unnouinceput 6y ago"..remade Turbo Pascal..." - translation: C#. Yup, that's right, C# is a clone of Delphi and then some. Anyone knowing Pascal will have no problem jumping to C# because it will swim in familiar waters, only difference is that being a Microsoft product has C style syntax.
- sysrpl 6y agoWell you have said what I always think. For those familiar C# feels like the next iteration of Delphi, but with curly braces. Both Delphi and Free Pascal haven't stopped though. They've added generics, extension methods, attributes, and many of the other features that have also been added onto C#. Free Pascal has gone further to add management operators, vector math intrinsics, and improved array features.
- Koshkin 6y ago> with curly braces ...and .NET in tow.
- yjftsjthsd-h 6y agoYeah, FPC can target an absurd collection of systems; can C# handle that level of portability?
- madhadron 6y agoOnly in the same way as Java can (run the .NET VM) and the GUI story is far less clear.
- int_19h 6y agoEarly .NET also copied liberally from VCL. The entire System.Windows.Forms namespace, with base classes like Component and Control, feels very familiar to anybody who made GUI apps in Delphi before.
- unnouinceput 6y agoDelphi has those too, and with latest iteration (read May 2020) they added inline variable declaration (which on Free Pascal will raise a syntax error)
- badsectoracula 6y agoNote that inline variable declaration had been discussed at the past by the Free Pascal developers and was rejected by most of them - this is a (rare) case where they decided that they wont follow Delphi. Reasons, IIRC, are mainly due to how weird the syntax is and it feels too un-Pascal-ish to have mixed declarations and code (in Pascal pretty much everything is declared in its own section) and with Pascal supporting nested functions/procedures and the IDE being able to autocomplete variable declarations for you, it is more of a code smell than something necessary.
- 6y ago
- boznz 6y agoAnyone knowing pascal will have made the jump to C# in 2006, everyone left are quite happy with Pascal, nobodies going to make the jump in 2020 IMHO
- rishav_sharan 6y agoIs this some inside joke that I am not getting? C# is nothing like Pascal. Java is the language closest to C#.
- SideburnsOfDoom 6y agoOne person, Anders Hejlsberg, was a leading architect on Delphi and then on C# His work on C# is widely thought to be a continuation of his work on Delphi. https://en.wikipedia.org/wiki/Anders_Hejlsberg https://en.wikipedia.org/wiki/Anders_Hejlsberg
- mhd 6y agoThere's also plenty of other cross-pollination, e.g. the influence that Cedar or even Modula-3 had on Java. Still, I can understand the issues. Let's not forget that despite his work in the field, Hejlsberg isn't Mr. Pascal, that would be Niklaus Wirth. Who always had a way more minimalistic design perspective than others, starting with Algol-W and ending with Oberon-7. Comparing that to the kitchen sink approach of C# (and arguably even Object Pascal) shows two philosophies that can hardly be more different.
- SideburnsOfDoom 6y agoI think that Delphi took a bit of a "kitchen sink" approach when compared to classic Pascal, for practical reasons of being most useful to a working programmer, rather than being academic. Specifically the infamous yet influential essay "Why Pascal is Not My Favorite Programming Language" has a laundry list of reasons why academic Pascal is hard to use "for serious programming", and many of them have been corrected in Delphi.
- pjmlp 6y agoMany of them were already corrected in ISO Extended Pascal, UCSD Pascal and Apple's Object Pascal, before Borland happened.
- badsectoracula 6y ago
- pjmlp 6y agoFirst he did J++, though.
- brnt 6y agoAs an IDE, Freepascal does seem dated, not including many details that we've gotten used to in recent decades. The language itself feels also frozen in the early 00's, have a look at string handling for instance. Very verbose methods, and a problem that's true for the Freepascal dialect in general: small incompatibilities with Delphi Pascal, the dialect any old veteran will be used to and as such also much documentation/discussion online. Add to that a near invisibily in places like Github, and it does not make for a very attractive platform, compared to some others. Freepascal/Lazarus has a nice forum, and if you happen to be working in the same niches as other guests, that may be enough, but otherwise... I also couldn't help but notice that the practices passing around zipped code bases/fragments is alive and well on there, mirroring the culture of small but closed source tools the Delphi ecosystem was famous for around 2000. While friendly, very dated and 'source hidden' in its ways.
- badsectoracula 6y agoThe textmode IDE is largely a fallback for platforms that Lazarus doesn't support yet, pretty much everyone nowadays uses Lazarus which is very featureful (and very fast, IMO it puts pretty much other IDE to shame considering the functionality it has and its responsiveness and resource requirements). Verbose methods are a convention that you'll find in other languages too (e.g. Java and C# and also some C++ projects). What is the issue with string handling? Free Pascal has several language modes, one of them being Delphi which should be compatible enough to share and port code between the the two compilers (though the default mode in Lazarus is ObjFPC which is different and IMO the better mode). In practice the differences are small enough that unless they refer to very internal stuff (e.g. memory layout of RTTI data), anything you find online about Delphi also applies to Free Pascal (assuming of course that FPC has implemented the functionality, but since you refer to old veterans, i think everything those veterans and old discussions will be there). I'm not sure what you mean with passing around zipped codebases, there are a ton of projects on GitHub. And how can a codebase be 'source hidden' when it is available as a zip?
- brnt 6y agoI did mean Lazarus. Just the text editor component feels alien. Things like block selection by default. It just doesn't work the same as any other text edit component I've ever used. The issue with string handling is (or was) that there seem to be different string types but that 'string' is used to describe all of them. Some of those methods require or produce ASCII, and it may be difficult to know what your problem is when you have one The language modes suffer from incomplete support. The differences aren't large,but that does mean they re easy to fix. My previous employer, a Delphi shop for more than 2 decades, was unable to be compatible with Freepascal over some of these issues. With limited source I mean that things like history will not be there, or its just a single file of part of a single file bundled up, so you're missing out on context. All makes it hard for a newbie, even for someone with some experience.
- pjmlp 6y agoActually he decided to go to Microsoft after being disillusioned how things were going at Borland. Also what people keep forgetting, J++ was actually what he first did after joining Microsoft.
- pjmlp 6y agoSince I cannot edit it any longer, here is one of the podcasts where he mentions it (first episode). https://www.microsoft.com/en-us/behind-the-tech https://www.microsoft.com/en-us/behind-the-tech
- badsectoracula 6y agoOne thing i find interesting about J++ (i have Visual J++ that came with VS6, though i never used it myself - and i do not think it even works in modern Windows) is that it also had its own relatively big framework that pretty much died with the language. It is like this language was made, existed for one or two versions and then the entire effort was thrown out of the window.
- pjmlp 6y agoThey couldn't have done otherwise given Sun's lawsuit. If you read Ext-VOS paper and the history of F#, that was how the upcoming COM Runtime was rebooted to use a managed language runtime. Hence why when one knows all these puzzle pieces, UWP seems so close to what they were trying out back then.
- int_19h 6y agoIIRC parts of that framework were the basis for .NET libraries, e.g. WFC -> System.Drawing / WinForms. Just compare the class names: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa286472(v=vs.60) https://docs.microsoft.com/en-us/previous-versions/visualstu... https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms https://docs.microsoft.com/en-us/dotnet/api/system.windows.f... https://docs.microsoft.com/en-us/dotnet/api/system.drawing https://docs.microsoft.com/en-us/dotnet/api/system.drawing
- unnouinceput 6y agoAs a 20+ years Pascal/Delphi lover, this read is too much for beginners. I had no problem going through it in one go, but it did felt a lot of energy was spent even by me. Maybe it's better to be split in chapters, giving a potential inquiry mind time to breath. And yes, I do realize it has a left ToC. So maybe instead of one big document with a lot of inline anchors, should be made separate files. Or perhaps both, giving readers the opportunity to choose whichever they like.
- oefrha 6y ago> Or perhaps both, giving readers the opportunity to choose whichever they like. Yeah, good old texinfo-style entirely-on-one-page and one-page-per-node model (as seen on the documentation page of any GNU project, e.g. https://www.gnu.org/software/texinfo/manual/texinfo/ https://www.gnu.org/software/texinfo/manual/texinfo/) is heavily underrated and underutilized in “modern” documentation systems. Want to quickly search for something in the entire manual? Use the one page version. Want to read cover to cover or link to a specific topic? Use the split up version. Btw, this book is apparently written in AsciiDoc and generated by Asciidoctor. There seems to be a multi-page plugin available, although I haven’t tried it myself. https://github.com/owenh000/asciidoctor-multipage https://github.com/owenh000/asciidoctor-multipage https://github.com/asciidoctor/asciidoctor/issues/626 https://github.com/asciidoctor/asciidoctor/issues/626
- romaniitedomum 6y agoSeems Pascal is having a field day today. Makes this old Pascal fan happy! The other piece is about Castle Game engine, written by the same author, Michalis Kamburelis. About the only issue I'd take with this piece, and it's minor, is that it's slightly modified from the original and pushes the use of Delphi mode over the default ObjFPC mode in the Free Pascal compiler. To see the original: https://castle-engine.io/modern_pascal_introduction.html https://castle-engine.io/modern_pascal_introduction.html While there's nothing wrong with preferring Delphi mode or ObjFPC mode, since the differences between them aren't that great [1], a piece that aims to describe the language should at least offer some rationale for a preference that is urged so strongly on readers. But otherwise this is an excellent piece for anyone wondering what Pascal looks like in 2020. [1] https://www.freepascal.org/docs-html/prog/progap4.html#progse62.html https://www.freepascal.org/docs-html/prog/progap4.html#progs...
- rubyn00bie 6y agoAlright, sooo... Pascal kind of seems like the holy land of "get shit done" that isn't C or C/C++. At least as far as cross platform UI development goes that isn't _electron_. How is it maintaining a Object Pascal project in 2020? What are it's weak points? Anyone have some examples of "modern" apps written in Object Pascal or problem spaces it's still vastly better than the competition? Are there any like magical libraries, frameworks, or patterns?
- badsectoracula 6y agoThe main magical part is largely Lazarus and LCL for desktop application development. The slightly less magical part is that the language has many features that you often find in languages targeting a VM but instead it generates native executables (pure Free Pascal executables can be less than 50KB) with no mandatory external dependencies outside what comes with the OS. It also target a ton of platforms. But TBH outside of GUI development there isn't anything particularly special about Free Pascal that you wont find in any other language, especially if you do not care about requiring a VM (in which case something like C# will probably be the closest equivalent). One thing that it has though and personally i find it very important when it comes to maintenance is that the developers care a lot about backwards compatibility - existing code you wrote even 20 years ago will keep working either as-is or with very minor changes. Personally two issues i remember having were in one case when character encoding aware strings were introduced, i was treating a string as a byte buffer (prior to that change they were basically byte buffers) so i had to change a declaration from using "String" to use "RawByteString" (which behaves as a byte buffer) - that was a single line change. The other change was when at some point some years ago (i think it was when Delphi-compatible generics were introduced) the ClassName of a specialized generic class changed format. One issue Free Pascal and Lazarus have is that sometimes they feel a bit "messy" and unorganized or unpolished. But they are projects that are 100% community driven by many people, going back decades (especially FPC) so i guess that is to be expected, especially when they do not want to break people's code in pursuit of some ideal purity.
- brnt 6y agoMain thing holding me back is very small online community, most is using Delphi Pascal, not Freepascal, on very corporate and closed source projects, usually old codebases thus no new nice features, and those nice new features are often different between Freepascal and Delphi. So if you manage to get to see someone's code, it may be using features not implemented in or coded in modern Freepascal. And old Delphi Pascal suffers from similar things as 90ies C or C++: it skips modern features and uses a style that is contrary to what people now learn, expect or even enforce. Also, there are a few incompatibilities/differences in stdlib between Delphi and Freepascal, and it was very easy for me to run into them.
- zenlot 6y agoThe first time I've played around with Borland Delphi was I think 99-00 and it was good experience. Then moved on and kind of forgot it. Last weekend I thought to look if Delphi still alive, found out that it's now owned by Embarcadero, downloaded their latest architect edition trial (they have community edition now too) and was surprised how easy it is to write cross platform apps. Stuff which I've remembered from ~1999 - still works the same way, and you can have Android, Windows, iOS, Linux GUI apps on the same codebase in one go. It's just pleasure to work with. If only Embarcadero modified their licencing terms, e.g not charging ~5k for Architect edition and did some marketing they could win over some space in software development world. Something like Microsoft did with Linux and Open Source world when they changed their view on it. Even if you don't plan to use it, it's worth a try, just to see how joyful and easy it can be to write cross platform apps. It also somehow reminds me Smalltalk/Pharo experience in some ways.
- srean 6y agoI am not very familiar with Free Pascal. Does it have coroutines ? Modula2 does but there aren't that many free and maintained implementations around. There is of course GNU's Modula, but it wasn't very easy to install.
- nurettin 6y agofpc has no coroutines. Delphi has them. In fpc, You can declare a procedure or function within another, but that's about it. Authors are skeptical of its utility. https://forum.lazarus.freepascal.org/index.php?topic=45818.45 https://forum.lazarus.freepascal.org/index.php?topic=45818.4...
- FpUser 6y agoYou are confusing coroutines with anonymous functions / lambdas.
- nurettin 6y agoWow, silly me I misread that thanks for the correction sorry gp. Yes, it has coroutines in the sense that you can queue functions to be run as soon as the event queue is drained, so that it looks like your UI is responsive, but they probably won't be able to run concurrently unless said event loop runs on a separate thread which I don't think it does correct me if I'm wrong.
- FpUser 6y agoCoroutines do not really run concurrently unless you yield explicitly or call functions that do async io (those yield automatically). The main reason it is directly available in languages like Go is that they are meant for building servers that do lots of network/file interactions and very little actual calculations. In this pattern coroutine looks rather natural and your code is not riddled with endless explicit yields. As soon as you step out of that pattern coroutines became headache where once must constantly watch and make sure that the interval between yields is not too big and they do not block each other. In my opinion coroutines are an artificial construct that is very specific to the OS (Windows has fibers for example) and one can argue that it belongs to some standard library rather than first order language construct. Well Delphi is guilty in this department as well. It has direct language support for automation services on Windows for example.
- mckinney 6y agoNice. While I suppose Pascal did suffer a bit from its "learning language" beginnings, it was wildly popular as Delphi. If only Anders/Borland had designed Delphi as a VM, similar to the JVM. Of course he did that for MS with J++ (and then C#), but had Borland done it first with Delphi, would MS still have squashed them? Probably. As for the Introduction posted here, Nice! Well written and densely informative. Refreshing to see some focus on Pascal. One feature I'd like to see borrowed in other languages: Class references. In my experience this feature would be extremely useful for code generators, say in Java. For instance, you get virtual static methods and constructors. Man, that would be nice.
- FpUser 6y ago>*"If only Anders/Borland had designed Delphi as a VM." That would've been enough reason for me not to use it. Targeting whatever VM as yet another platform to compile to would be fine I think. It was actually done for Java and .NET but hardly used. I guess it has no benefits compared to native.
- acqq 6y ago"By default FPC programs and libraries do not use the C library on most platforms" (1) is what makes Free Pascal potentially interesting on Linuxes: sometimes the dependencies that exist when producing the binary using C or C++ simply disappear if one could write a Free Pascal program. I haven't been able to use it in the environment I worked recently, but I had to waste so much time on the C and C++ library dependencies, different on different systems. Free Pascal seems to be a possible solution to that. -------------- 1) https://wiki.freepascal.org/libc_library https://wiki.freepascal.org/libc_library
- badsectoracula 6y agoUsing libc on Linux shouldn't introduce any incompatibilities (also you can use libc with Free Pascal, e.g. when using threads you link against the pthreads library which in turn needs libc and you can use libc's memory management functions instead of Free Pascal's own functions which can be faster), at least as far as glibc is concerned, since they are supposed to be backwards compatible. For example I have binaries compiled on 1998 Red Hat and linked against libc and libX11 working on two decades later distros just fine. It is usually the libraries you use on top of libc and libX11 that tend to break and introduce incompatibilities. C++ is another topic though, but i think there is an effort nowadays to avoid breaking that too.
- acqq 6y ago> I have binaries compiled on 1998 Red Hat and linked against libc and libX11 working on two decades later distros just fine. The goal was avoiding to use "1998 Red Hat" to compile today something that should work on a few years old system. That is the direction that is typically broken with C and C++, to the point that only safe approach is, indeed, to use 1998 Red Hat. But using 1998 Red Hat forces you to use the very old compilers and old anything else on that same Red Hat, which is what could be very inconvenient in 2020, when one has to use other tools with newer features in the process. If I understand, I can use 2020 OS and using Free Pascal trivially produce binaries that would work on the older systems on which the C and C++ binaries produced on the 2020 OS just wouldn't. Edit, answer to the post below: > i'm not sure if you link against libc if it'll generate versioned symbols If I understand correctly, one can produce Linux binaries with Free Pascal while depending only on Free Pascal's libraries which don't have libc dependencies at all. And that is what I see as a huge potential to produce the binaries that don't break on older Linux version, the way libc-linked typically do not because Linux kernel is incompatible, since it isn't, but just because GNU libc infrastructure allowing only "build on older Os for newer" but not at all the opposite scenario.
- musicale 6y agoThere is very little that can be done with C-style syntax that can't be done with Pascal-style (or Oberon-style) syntax. I find the Pascal-style syntax to be easier to read. I also like that Pascal has always had enumerated types and ranges. I'm neutral on nested scope, but I think it could be occasionally useful. After using C-like languages for so many years it is a little jarring to see function calls without parentheses, but I think I like those as well.
- himanshu810e 6y ago100+ points for this waste of time and piece of crap and dont even get me started on their game engine
- FpUser 6y agoI would agree that state of game engines/libraries in Delphi/FreePascal is far from ideal. Pasvulkan on github might be possible exception as it is done very professionally but is also very opinionated. As for the subject itself you seem to be overreacting. Delphi and FreePascal/Lazarus are very decent tools.
- himanshu810e 6y agoI literally went over the entire thing and tried to find anything which is adding value and did not find any. As of now I see this project as novelty or a hobby project. You are free to think that I am overreacting but a piece of crap will be called a piece of crap specially if it's getting hyped for no good reason.
- lordgroff 6y agoPascal was the first language I played around with after Amiga era BASIC. I still don't really understand why it faded into relative obscurity. To this day, I feel like it's close to a perfect language. It's fast, it's productive. It's not a "safe" language, but its design from very beginning steered you away from danger. With Lazarus, it is probably the most pain free way to write GUI apps. But more than anything else, it is so, so readable. This is often expressed as criticism: it's verbose. But that verbosity is absolutely a small price to pay for code that is often shockingly easy to understand.
- theamk 6y ago> 5.1. Remember to free the class instances > The class instances have to be manually freed, otherwise you get memory leaks. This was the most annoying part back in the Turbo Pascal days, I am surprised it is still there. I'd think with all the changes (generics, etc..) they could have added a smart pointer class?
- vram22 6y agoRelated HN thread of interest (IMO): Delphi – why won't it die? (2013) https://news.ycombinator.com/item?id=7613543 https://news.ycombinator.com/item?id=7613543 It is about: http://stevepeacocke.blogspot.com/2013/05/delphi-why-wont-it-just-die.html http://stevepeacocke.blogspot.com/2013/05/delphi-why-wont-it...
- atombender 6y agoI "grew up on" Object Pascal as a developer — first Turbo Pascal, then Borland Pascal (for DOS and Windows), then Delphi, up until the early 2000s. Back then, I wrote GUI apps and commercial games, but I also did a lot of non-GUI development in Delphi, using technologies like COM, MAPI, etc. While Delphi itself wasn't "meant" for non-GUI development, it was still a very nice experience. The interactive debugger was fantastic, as it always was in Borland's tools. Nowadays, I don't see room for Object Pascal. While later versions of Delphi have improved on the syntax (e.g. generics), it's still a fairly old-fashioned language. It doesn't really have anything special to offer someone who already knows C#, Go, Rust, Java, Nim, etc. There's a strong Object Pascal influence on both Go and Nim, and those languages improve on it in every way, including the size of the communities, the available libraries, and so on. Delphi's killer app used to be GUI development on Windows, but these days you need to target multiple platforms, and I'm not a believer in cross-platform GUI toolkits; you end up with something that doesn't look great on any platform. I look at Object Pascal with a lot of fondness, but it's mostly nostalgia.