12 ms·
A guided intro to the Free Pascal language
- tristanbvk 4y agoPersonally I read the programmer manual for FP. You can do both Object Pascal OOP and Delphi OOP. Wild. Also nice units for doing mmap and all libc stuff. I really ought to finish learning Pascal and actually write something in it. Not a bad language.
- tanakian 4y agonot only libc. what is very cool is that most of the parts of very rich fpc library has no libc dependency. so necessary parts get linked statically to the resulting binaries, and those binaries do not require libc. most of the library goes with roots to kernel calls, bypassing libc. once you start using threads or link to other c libraries (like gtk) then libc becomes a dependency.
- tristanbvk 4y agoHonestly it is such a fun language playing with FPC especially. I have the urge tl write something in it. Maybe when I am done with my compiler (written in D), I'll write something fun and small like that in Pascal. Who knows! But I love FPC!
- tifadg1 4y agoPascal killed my interest in programming for a while as it was force fed in both high school and earlier collage years. Reflecting back, it was the pessimistic approach to teaching of just pushing math problems via programming.
- sysrpl 4y agoFree Pascal was originally derived from Object Pascal and later Delphi, both of which added more object oriented programming features to Pascal. Additionally, it supports some of the more advanced features introduced to Pascal with later releases of Delphi including managed types, interface types, operator overloading, generics, implicit and explicit conversions, extension properties and methods, as well and user defined initializers and finalizers for your custom types, and more. I could write an article about each of these features, but in summary they each are powerful and help users write more useful programming code when leveraged correctly.
- alexvoda 4y agoI also experienced mandatory Pascal classes in high school and similarly hated it, especially because I already knew other programming languages. Much later however, I started really appreciating Pascal, both as a teaching language and as a multiplatform language. PeaZip, CudaText, Transmission Remote GUI, UltraStar Deluxe and plenty others are written in FreePascal.
- markus_zhang 4y agoPascal aside, back when I was 10 my father also tried to force math programming to me when I showed interest in games. Apparently it didn't work.
- pankajdoharey 4y agoPascal is a great language for programming games as is evidenced from Delphi Quake and Delphi Quake 2 projects https://sourceforge.net/projects/delphiquake/ https://sourceforge.net/projects/delphiquake/ I believe the right approach to programming is graphics for kids.
- codewritinfool 4y agoAge of Wonders is a great Delphi-produced game too, if I remember correctly.
- tanakian 4y agothey just didn't know how to teach back then. they could approach the same math from the other side, by starting to write games. and gradually come to game math. that would be more interesting, and then it would become obvious why one may need some math while programming.
- aebtebeten 4y agoHeh, now you've made me consider an "abstract algebra for kids" tutorial, with data representations for simple games as the overarching conceit. Unfortunately, as a cishumanist, my finite lifetime expectation means I'll leave this project for some other interested party?
- prosaic-hacker 4y agoHexFlexagons https://en.wikipedia.org/wiki/Flexagon https://en.wikipedia.org/wiki/Flexagon Angle trisection tools. https://www.instructables.com/The-Tomahawk-an-Angle-Trisection-Tool/ https://www.instructables.com/The-Tomahawk-an-Angle-Trisecti... First AA proof I learned: Cannot trisect an angle with ruler and compass.
- 082349872349872 4y agoFlex Mex: https://www.youtube.com/watch?v=GTwrVAbV56o https://www.youtube.com/watch?v=GTwrVAbV56o > However it is imperfect: for it is not yet delicious.
- prosaic-hacker 4y agoBack Then. When was that? At University (1978) we used Pascal as the first language to learn (if you exclude CDC Cyber 6600 assembly). Yes we did the Discrete math problems common in CS (https://mathworld.wolfram.com/Floyd-WarshallAlgorithm.html https://mathworld.wolfram.com/Floyd-WarshallAlgorithm.html). We did other things as well. The professors were a mix of hippies, math geeks, and the Doctors from Doctor Who. Most knew both the academic and fun side of programming. I guess it depends on the school and people there to create a fun but educational culture.
- JanisErdmanis 4y agoI also had mandatory pascal during my high school years. Although I knew a little of C, C++ and python at that time and felt a bit obscured about learning pascal, today, I deeply admire my teacher's choice of pascal. Pascal has a nice beginner terminal IDE with a debugger and breakpoints; it has types, stack allocation and memory planning before the program is being run; recursion is possible, and it does not have many obscure features like pointers and OOP obscurities. Today, perhaps I would suggest Julia as the first language to teach, but pascal is still at the top.
- coliveira 4y agoPascal is great as a teaching language because of its simple syntax. It is also a pre-OO language, so you don't need to spend time explaining what classes and objects are. For an introductory programming course it is a very good language.
- thriftwy 4y agoBASIC is a great teaching language. Pascal is way too verbose and boilerplate-ly compared to that.
- FpUser 4y agoLuckily for me I've never received any formal training in programming back in school. My introduction to programming happened in University and research labs in a very simple way - I needed to process and interpret some experimental data live and the only way I could do it was a computer. So I got me a user guide for particular one and bunch of books. In a few days I was already coding away. In exactly the same way I was introduced to electronics. Had to make some equipment for my research as you could not by one. Started with machine codes but over the time I've used many languages including Pascal from Borland. Programming was far from my main job but at some point I switched from science to creating commercial products as I was good at it. Some products I own and some I develop for clients. Most of products are ether pure software or contain some good chunk of it so I am still happily coding away even though I am 60 already.
- projektfu 4y agoCa. 1994 we had Pascal as the language for AP computer science. Later, they started adding other languages. In my school the options were Basic (TrueBasic) which was offered as a stepping stone to APCS and pascal. I also had the opportunity to study Scheme through CTY's excellent summer class. At the time, I remember pascal feeling like "real programming". The programs were compiled and they operated at various levels of abstraction, from pointers up through advanced data structures and interfaces/ADTs. I didn't see Scheme as more than a toy, which was partly because the MIT Scheme implementation was just an interpreter. And I hated Basic and still do. Pascal was great because it was pretty easy to learn and somewhat consistent. Its most annoying feature, semicolon-as-separator, was easily handled by the terrific Think pascal editor. In its time, Pascal was a great choice. There were real-world things that you could do immediately using Think Pascal and Turbo Pascal. Making the switch to C and Unix wasn't simple but probably easier than starting with Basic. However, I was left with a bias towards wordy languages like Pascal, Ada and Modula-3 that took a while to get over :)
- analog31 4y agoThis was all people knew. Most people saw programming as a branch of math. When a high school offered a programming class, it was often taught by a math teacher. The smaller colleges in my state, that were beginning to add computer science, did so by combining it with the math department. My mom taught programming in the early 80s. She took a course at the nearby community college, and a year later, was teaching the course. Her background was... high school math teacher. She said: "Programming is just math, a program is like a proof." Fortunately I loved math and proofs, so that way of thinking wasn't an obstacle for me. Clearly we know differently now.
- shimonabi 4y agoIs there a way to use the Lazarus libraries, but write code in C++, like with C++ Builder?
- tanakian 4y agoyes, i believe delphi rad studio has c++ compiler and the libraries are written in pascal, it is a lineage from c++ builder.
- tanakian 4y agohttps://cppcast.com/cpp-builder/ https://cppcast.com/cpp-builder/ - this is the podcast where embarcadero devs tell about how they maintain number of patches to llvm's compiler to make it compatible with necessary non-standard features like closures. this also tells us that c++ became so big and complicated that one company (embarcadero size company) is not able anymore to support own compiler, they need to maintain own patches.
- coliveira 4y agoIf you look at C++ standard support in major compilers, you'll find that no compiler on earth supports the whole C++20 standard. Gcc is the one that gets closest, but still has several "partially supported" features. https://en.cppreference.com/w/cpp/20 https://en.cppreference.com/w/cpp/20
- signaru 4y agoQt and wxWidgets are also worth considering assuming you would just be "writing" the code and not taking advantage of the visual designers. These do have visual designers, but Lazarus if far easier to use, IMHO, following the footsteps of Delphi and VB classic.
- badsectoracula 4y agoYou can have your C/C++ code exposed to Free Pascal via a C API loadable as a shared library / DLL, but beyond that there isn't much you can do (Free Pascal comes with a `h2pas` tool to help convert C headers to Free Pascal units for such use). This is of course far from having something like C++ Builder. To have something like C++ Builder it'd need a lot of things to work together: 1. A C++ compiler will need to be extended so it can use Free Pascal classes (in terms of memory layout) and add any necessary language functionality for "published" sections (RTTI data that allows FPC objects to describe themselves and be streamed/serialized), metaclasses (classes in FPC are objects and can have their own virtual methods, including virtual constructors), delegates (basically "fat" pointers) as well as data types like sets, strings, etc that FPC has. LCL (Lazarus' framework) relies heavily on pretty much all of FPC features. 2. FPC will need to somehow be able to import classes defined on the C++ side too so that components written in C++ will be usable in Lazarus. Also almost goes without saying but it should be possible to statically link programs using both FPC and C++ in the same executable. 3. The C and C++ runtime libraries will need to use FPC runtime library functionality for things like memory management (FPC's memory manager is pluggable) so that "crossing" memory management will work fine - even across dynamic library boundaries (e.g. calling `malloc` on the C++ side and then "FreeMem" on the Free Pascal side, even when the latter is in a dynamic library that shares a memory manager with the host program, should Just Work). 4. Lazarus' "codetools" will need to be expanded to support parsing C++ in addition to Free Pascal so that all of the IDE's automatic code writing and refactoring functionality will work for C++ too - things as simple as double clicking on a button and having the methods be written automatically in the editor with the cursor placed in the method body rely on this working. These are from the top of my head, there might be other issues to handle, but even from the above it should be clear that it requires not only a lot of work but also a lot of different projects to work together (unless FPC and/or Lazarus devs decide to implement their own C++ compiler and runtime). In the short term it might be easier to use Qt Creator which has some RAD-ish features. It is certainly clunkier, the API feels to be made with a code-first (as opposed to LCL's WYSIWYG-designer-first) approach and the IDE isn't as featureful (also at least for me it never works out of the box on Linux) but it is the closest open source project you can find for C++.
- MikusR 4y agoThere is also this https://castle-engine.io/modern_pascal https://castle-engine.io/modern_pascal
- lelanthran 4y agoThis comment really should be the first one seen in this discussion.
- themodelplumber 4y agoSome 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 too was a victim of the great AP Pascal force-feed in my HS comp. sci. class...but fortunately at the same time there were demoscene programmers around the world blowing my mind with Pascal programs and it seemed like there were new projects to appreciate online (BBS) every day after school. To whit: Someday I would like to write a Pascal raytracer that tells me how old I am, with emoji output, since my other ride is a text editor. (And if you don't like my driving, get off the sidewalk!)
- bigpeopleareold 4y agoHeh - I didn't do great in AP with Pascal either. I remember though trying to make it worth buying CodeWarrior for Mac OS (oh how the Internet changed everything ... :D ), which had a Pascal compiler, but I got overwhelmed looking at the Mac Toolbox docs and couldn't make much sense of it. (I know there was also MPW, but I didn't know how to get my hands on it.) The school computers ran Turbo Pascal on MS-DOS. I vaguely remember having to write programs on paper without a lot of access to those computers. But, I tried FP last year. I wrote a program to mimic a small tool in the company I worked for. It was fun actually. At the time, I sort of wanted a lot to write stuff in Emacs. There is an LSP server for FP but it's not really complete.
- xet7 4y agoFor C64 and other retro platforms with Pascal, there is TRSE: https://lemonspawn.com/turbo-rascal-syntax-error-expected-but-begin/ 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 https://github.com/xet7/darkesthour
- markwong 4y agoIt is a beautiful language.
- chasil 4y agoThis is not a universal opinion. https://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pascal.html https://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pas...
- renewedrebecca 4y agoThat is an opinion that is completely irrelevant to modern pascal. Let’s just judge C11 on what K&R looked like while we’re at it.
- SomeHacker44 4y agoBack when I learned computing, I had an old Apple ][+ with a Z80 card. There were only a few choices to program it. Apple and Z80 BASIC, Apple Logo, 6502 assembly (I did not have access to a Z80 assembler) and UCSD Pascal. Pascal was awesome. So much better than the others. It really launched my interest in coding once it clicked. I remember discovering that the early Apple game Wizardry was written in it one day when I was hacking around with it.
- ThinkBeat 4y agoPascal gets an underserved bad reputation. I am showing my age but Turbo Pascal was (is) great. Extensions from Turbo and Delphi Object Pascal is great as well. I hate the insane pricing Embarcado has imposed on Delphi. They have had cross platform GUIs in Delphi for a long time. Something for some reason other tools struggle and mostly fail to do. I have not been able to "sell" it to clients mostly due to price.
- ak39 4y agoEmbarcadero insane pricing of Delphi is the reason I haven't continued beyond my old version Xe2. I guess they are making hay while the sun shines with the locked-in customers.
- galangalalgol 4y agoDo they have the yellow-on-blue syntax highlighting trademarked or something? I've looked for vim and vscode color schemes to match the original turbo c++ but to no avail. I remember borland builder had a setting to switch back to it.
- ragingrobot 4y agoProbably no one else saw interest to do it? I do remember seeing something similar for emacs.
- zem 4y agoI've definitely used turbo c vim themes in the past. a quick Google search brings up https://github.com/caglartoklu/borlandp.vim https://github.com/caglartoklu/borlandp.vim and some others
- zozbot234 4y agoThat's a nice color scheme, but what really made those text-mode IDE's intuitive was the TUI widgets and support for multiple views. Probably easier to do in neovim than plain old vi/vim of course. With modern devtooling support as found in neovim you could also have inline help, which was also very useful in those older environments.
- grumblepeet 4y agoCoincidentally i tried to install Lazarus yesterday and hit issue after issue, two being some missing dependencies, which were items that I found in the documentation to be downloads as well. It then complained about lack of gdb, which I do understand (on an older Macos here) but it did occur to me, if you know it is needed, why not include it in the download? Cut a long story short, Ive installed Dr Racket today and working through the tutorials.
- spapas82 4y agoI still remember that the thesis of a fellow student back in the university 20 years ago was to create an educational version of Pascal called... "Paschool". I laugh out loud when I remember it, definitely the programming language with the most funny/catchy name ever!
- speed_spread 4y agoI 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).
- revanx_ 4y agonothing magic about Result keyword, it's just an implicit pointer, you can avoid it completely by using explicit pointers.
- speed_spread 4y agoIt'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.
- cardanome 4y agoNim 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/ https://nim-by-example.github.io/variables/result/
- ZoomZoomZoom 4y ago
- Peter5 4y agoThis website, is a collection of cool samples and sources. Check https://www.getlazarus.org/learn/tutorials/examples/ https://www.getlazarus.org/learn/tutorials/examples/ for many cool projects and the author has many nice projects including https://github.com/sysrpl/Tiny.Sim https://github.com/sysrpl/Tiny.Sim
- boobybrown25 4y agoLazarus has, imo, the best wysiwyg GUI editor you can get. Enjoy it a lot more than fighting with qt.
- kqr 4y agoWhen I looked into learning Free Pascal (not that many years ago) it seemed to me like Ada was the more well-developed, actively used language of that sort of heritage. Have any of you used both languages? What made you stick with Free Pascal instead? (To be clear, I'm interested in a comparison that goes beyond the price point of the commercial compilers, which is a tired subject at this point.)
- pjmlp 4y agoI guess if you are into GUI applications, that isn't something that Ada is that great about, as most vendors target headless deployments.
- Peter5 4y agoNote 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: https://dadroit.com/ https://dadroit.com/ https://peazip.github.io/ https://peazip.github.io/ https://cudatext.github.io/ https://cudatext.github.io/ https://lazpaint.github.io/ https://lazpaint.github.io/ As far as I know, there is no toolkit out there that lets you make fine looking applications for multiple platforms with proper speed. The old Pascal you may know is not the new Pascal. The development of Pascal is mostly focused on ease of development while maintaining low-level programming and backward compatibility. It looks old on its face, but it is young at heart. I recommend starting with Lazarus, https://www.lazarus-ide.org https://www.lazarus-ide.org, a much lighter IDE compared to so-called light projects like VSCode, with many more features and components to play with. Friendly word: don't let the comments with outdated information make you miss a great and fun tool.
- andai 4y agoYou 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!)
- chinabot 4y agoPascal is type safe and generally catches most errors at compile time, you can still create run-time errors such as indexes outside arrays but these will cause errors not bad return data. eg I use C a lot and find myself referencing array index [0] a lot, in pascal arrays starts at [1] if not specifically defined so I know this from experience, frustratingly I have a different problem in C which will either return random data or crash if writing.
- gramie 4y agoI'm pretty sure that FreePascal and Delphi can do run-time bounds checking (it's a compile-time option). Pascal also avoids buffer overrun errors on strings, because strings are dynamically resized as necessary. You can also avoid having to free objects if you declare them as implementing a certain Interface (I forget the exact one). They will automatically be freed when the number of references drops to 0.
- Mikeb85 4y agoSince this is a pretty general thread about Pascal, shout out to Castle Game Engine: https://castle-engine.io/ https://castle-engine.io/
- terminalcommand 4y agoI 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 https://github.com/Fr0sT-Brutal/awesome-pascal I feel like pascal is a hidden gem.
- squarefoot 4y agoA peculiar aspect of Lazarus (Free Pascal's Delphi-like IDE) is that it either cross-compiles for other architectures or can run itself on them, therefore generating native GUI software that runs immediately on the target platform. That is, you can develop ARM executables on a Raspberry PI using Lazarus running on the Pi itself. I would also suggest to take a look at FPCUpDeluxe, an installer that does all the tedious job of dealing with dependencies for installing FPC, Lazarus and a great number of modules and components. https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi https://wiki.lazarus.freepascal.org/fpcupdeluxe https://wiki.lazarus.freepascal.org/fpcupdeluxe A personal dream: having something like Lazarus that works with other languages too; that would likely become a game changer for desktop apps development.
- Akira1364 4y agoDon't download the bundled Free Pascal and Lazarus distributions from this site, they're very outdated. Just get the normal releases from the actual Free Pascal and Lazarus sites which are linked at the top of the page. Lazarus comes with Free Pascal bundled by default anyways, so you don't need to grab the compiler separately if using Lazarus.
- user3939382 4y agoI downloaded Lazarus from its release page on Github and after installing it didn’t work, saying it needed extra binaries that it couldn’t find. Now I have to see what it’s talking about, what to install, etc. Kind of a hassle.
- Zuider 4y agofpcupdeluxe will automate the process of installing a working Lazarus/FPC environment. You can just click through, as the defaults are fine. https://wiki.lazarus.freepascal.org/fpcupdeluxe https://wiki.lazarus.freepascal.org/fpcupdeluxe
- pkphilip 4y agoYou will need to install Free Pascal (fpc) separately
- Akira1364 4y agoWhich Github page do you mean? I wasn't aware they'd started putting properly packaged binary releases on Github.
- mikewarot 4y agoThere are some things that Lazarus/Free Pascal does right: - It has the most sane strings you'll ever see, you don't have to allocate them, and they can hold gigabytes of text. - You'll never confuse equality tests = with assignment := - It's case insensitive - It doesn't do macros - It is one of the fastest compilers available - It is one of the best GUI builders available Things it doesn't do right - Begin/End seems verbose to some people - Other "standard" pascal systems gave it a bad name - Historically, Borland et al, priced people out of their products and killed off a loyal use base.
- xchip 4y agoWith all my loving(it was the first language I learnt), I don't think we need yet another language. We need to fix the ones we have.