Live data from Hacker News

A guided intro to the Free Pascal language

getlazarus.org

11–20 of 102 posts

Re: A guided intro to the Free Pascal language

#11

Personally 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.

not 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.

Re: A guided intro to the Free Pascal language

#12
post #3

Pascal 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.

they 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.

Re: A guided intro to the Free Pascal language

#14
Some 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!)

Re: A guided intro to the Free Pascal language

#15
post #3

Pascal 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.

I 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.

Re: A guided intro to the Free Pascal language

#16

Is there a way to use the Lazarus libraries, but write code in C++, like with C++ Builder?

Qt 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.

Re: A guided intro to the Free Pascal language

#18
post #3

Pascal 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.

they 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.

Heh, 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?

Re: A guided intro to the Free Pascal language

#19

Is there a way to use the Lazarus libraries, but write code in C++, like with C++ Builder?

You 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++.

Re: A guided intro to the Free Pascal language

#20
Back 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.

Post reply on HN