Recent

Author Topic: A question on Modula2 vs Free Pascal  (Read 15192 times)

DoDep

  • New Member
  • *
  • Posts: 26
A question on Modula2 vs Free Pascal
« on: March 15, 2024, 02:46:27 pm »
Hello to all,

I have yet another question, which might have been answered in the (long ? ) past, but -sometimes-, in technology, thing might change rapidly.

So the question is rather simple: Is there any difference between (GNU) Modula - 2 and Free Pascal?  Especially:
a) what are (if any) the unique technical features (like, e.g., manual memory management) of each -not to be found in the other
b) what are the merits of each, again, not to be found in the other

I would appreciate any detailed explanation, for two reasons:
a) I am a hobbyist, so I have no severe constraints regarding which language I "must" learn
b) since, it is a site of Free Pascal, a detailed and clean explanation would diminish any suspicion for bias

Thank you in advance for your time.
« Last Edit: March 15, 2024, 07:34:36 pm by odysseus »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11951
  • FPC developer.
Re: A general question
« Reply #1 on: March 15, 2024, 04:15:46 pm »
Hello to all,

I have yet another question, which might have been answered in the (long ? ) past, but -sometimes-, in technology, thing might change rapidly.

So the question is rather simple: Is there any difference between (GNU) Modula - 2 and Free Pascal?  Especially:
a) what are (if any) the unique technical features (like, e.g., manual memory management) of each -not to be found in the other
b) what are the merits of each, again, not to be found in the other

I would appreciate any detailed explanation, for two reasons:
a) I am a hobbyist, so I have no severe constraints regarding which language I "must" learn
b) since, it is a site of Free Pascal, a detailed and clean explanation would diminish any suspicion for bias

Thank you in advance for your time.

(I was a  (Topspeed) Modula2 programmer before I started with Free Pascal)

Basically Free Pascal, like Delphi, supports both procedural and object oriented programming. The object oriented bit is also quite fleshed out and production quality.

Modula2 is just procedural, that's it. Maybe Gm2 has some rudimentary (M3?) OO nowadays, but probably not up to the Delphi level.

If we look at procedural only, Modula2 is better designed, but mostly those are details. Specially the block structure and import mechanisms are nicer. Some other changes are regressions though (IMHO), like the case sensitivity and the end "procedurename". The quite manual string support is also inferior to FPC's ansistring. (actually that was my biggest relief going back to Pascal after half a decade modula2, having a native string type again)

But the real killer is that choosing a development platform, is about more than language; FPC/Lazarus are together a complete project, including everything and the kitchen sink. From both (TUI and GUI) IDE to database classes to headers for things like opengl etc etc. Native CHM and PDF writers, Excel loaders and savers etce etc. Wanna connect to Google webservices? included? Connect to Cocoa on OS X? Done. All in a single (Lazarus) installer.

If I put "GNU Modula-2 windows download" into google, I don't even get a downloadable release for the compiler+ base libs in the first 3 options, let alone all the rest of the goodies. Likewise, where is the forum? There is a reason why you are asking here  :) Where would you go for questions, sample code or just plain old advocacy  ?

I can't give a definitive answer, since I never tried GM2 (and it doesn't make it easy to). But I wouldn't consider a standard M2 compiler over FPC for anything but the most embedded firmwares anyway. Even though I know the language.

Worse, in reality I'm using (cough) C for my firmwares, because using the vendor toolchain for micros is usually more important than the exact syntax of the language.
« Last Edit: March 15, 2024, 04:31:52 pm by marcov »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8046
Re: A general question
« Reply #2 on: March 15, 2024, 04:25:52 pm »
I echo what Marco said, from the position of also using (and selling) other variants. Taking his points about case-sensitivity and improved modularisation as read,

a) The syntax is different: Pascal used if-then-else while M2 uses IF-THEN-ELSE-END and so on. However UCSD, Borland and others extending Pascal rapidly realised there was a problem, hence try-finally-end etc.

b) M2 has no reference-counted types (dynamic arrays, variable length strings and so on). Strings are simple arrays of characters zero-terminated, without a leading length.

c) M2 has no polymorphic functions, no default parameters, and does not treat Write() etc. specially.

d) M2's typing is much stricter.

e) M2 has no concept of object inheritance, and at roughly the time Wirth was promoting M2 he was arguing that OO-programming was irrelevant.

f) From (c) and (e), it goes without saying that M2 has no concept of late binding etc. That sort of thing could obviously be coded explicitly, but there's a lot of syntactic sugar in Object Pascal which makes programs neater.

I think those are the important things. There's obviously an enormous number of implementation differences, but there's at least as much variation between the pragmata expected by various M2s as there is between (e.g. TopSpeed) M2 and Pascal.

I've not tried for ages, but suspect that these days one is supposed to get it as part of the overall GCC (i.e. GNU Compiler Collection) set; for example on Debian it's the gm2 package. Before that it was part of the "GNU Savannah" bundle, i.e. "it's ours but not quite". Discussion at https://freepages.modula2.org/ suggests that the original developer, Gaius Mulley, is still active.

As a subjective opinion: M2 is the superior language, but lacks extensibility. Pascal similarly lacks user-accessible extensibility, but generations of compiler developers have piled on features many of which are overlapping. I am no longer comfortable using it, but particularly with the development environment provided by Lazarus I'm not convinced that there's anything better.

MarkMLl

p.s. I'd make the point strongly that "A general question" is spectacularly unhelpful if you want the right people to see your postings. The only reason I read it was in case it was a newly-joined user posting spam.
« Last Edit: March 15, 2024, 05:52:10 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11951
  • FPC developer.
Re: A general question
« Reply #3 on: March 15, 2024, 04:33:39 pm »
p.s. I'd make the point strongly that "A general question" is spectacularly unhelpful if you want the right people to see your postings. The only reason I read it was in case it was a newly-joined user posting spam.

Yup,  Odysseus can adjust the title by editing the (first) post.

DoDep

  • New Member
  • *
  • Posts: 26
Re: A general question
« Reply #4 on: March 15, 2024, 07:34:54 pm »
p.s. I'd make the point strongly that "A general question" is spectacularly unhelpful if you want the right people to see your postings. The only reason I read it was in case it was a newly-joined user posting spam.

Yup,  Odysseus can adjust the title by editing the (first) post.
Done ;-)

DoDep

  • New Member
  • *
  • Posts: 26
Re: A question on Modula2 vs Free Pascal
« Reply #5 on: March 15, 2024, 07:41:11 pm »
I would like to thank you both... but a follow up question arose:

@ Markov:
Why C? Can't you have Pascal in embedded? (Unless I am mistaken by considering firmware as embedded).

On the other side, I would say that I appreciate the fact that M2 is "pure" (i.e., without OO). Essentially I do not want to delve into OO -I rather prefer either procedural/imperative or functional (tried Lisp in the past). In fact, I have been using old books in Pascal (without the OO part), suggested to me, here, by others. Also, in my platform I can not have Lazarus (Void linux, with very outdated packages, and my attempts to build from source failed). Besides, Lazarus without OO is (as many mentioned elsewhere) useless.

So, my conclusion is that perhaps I should be inclined towards M2 (I think there is a Raylib wrapper as well!). On the other hand, I do understand your points. Also, I have hard time to install GM2 (GCC toolchain) in my system.

PS. There is a "downside" (just my quirk)... to be honest I would like something completely independent to C (I know...Raylib mentioned earlier)...
« Last Edit: March 15, 2024, 07:46:50 pm by odysseus »

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: A question on Modula2 vs Free Pascal
« Reply #6 on: March 15, 2024, 08:12:12 pm »
You don't need Lazarus, you can just install/build FPC.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8046
Re: A question on Modula2 vs Free Pascal
« Reply #7 on: March 15, 2024, 08:17:24 pm »
I would like to thank you both... but a follow up question arose:
Why C? Can't you have Pascal in embedded? (Unless I am mistaken by considering firmware as embedded).

What is "firmware"? When I were a lad it was in ROMs, PROMs, or- at a pinch- EPROMs. More recently it's been consigned to (non-filesystem) blocks of Flash, sometimes with a protected boot loader (i.e. like an Arduino etc.). But the Great Unwashed now seems to think that firmware is something that's loaded into memory from a filesystem...

FPC's certainly OK for something like a Raspberry Pi Pico, as well as- obviously- "firmware" running on something of the scale of a "classic" RPi. But TBH I'd be uncomfortable trying to get support from the broader community for something I'd written in a language that they weren't routinely using., and I'd be very /very/ uncomfortable trying to explain that I was using an "advanced" API- object-oriented, or with some strange way of representing bitfields etc.- in place of one that they'd written and sanctioned.

OTOH, at the other extreme I remember somebody refusing to use M2 at an application level on a unix system because "unix is written in C and that's the only language it supports".

The bottom line is that (a) there are things that make C++ and other "advanced" languages (including FPC) problematic in embedded systems, and they almost always revolve around the risk that eventually the heap will get fragmented and (b) when choosing an implementation language you have to consider both inherent language properties (e.g. whether or not it relies heavily on the heap) and the extent to which the broader community will approve of it (e.g. will the people who really understand the nitty-gritty tell you to get stuffed).

Having said which, there's nothing inherently wrong with OO techniques, or with using dynamic arrays and strings: they can all make life much easier when used with a degree of caution appropriate to the environment.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 4761
Re: A question on Modula2 vs Free Pascal
« Reply #8 on: March 15, 2024, 08:37:25 pm »
I rather prefer either procedural/imperative or functional (tried Lisp in the past).
That's my preferred programming methodology too.  I have no idea how many lines of code I have accumulated over the years (about 40 years) but, there isn't a single line of OOP in my code except for programs I wrote when TP 5.5 came out (which introduced OOP) and I studied the methodology in full detail but, never used in development.

Besides, Lazarus without OO is (as many mentioned elsewhere) useless.
Now, that statement is a _big_, really BIG mistake.  Without all the OOP stuff, which is the way I use it, Lazarus provides a reasonably decent editor, a very capable source code navigator (courtesy of codetools) and, most importantly, a very capable debugger, FpDebug, that is getting better everyday (well... make that roughly every week... thanks Martin and all those involved in its development).

Personally, I believe a good debugger is every bit as important as the programming language because no matter how good the language may be, programming errors will occur and without a good debugger, it can be a real pain to locate them.  The Visual Studio debugger and Windbg are the main reasons I still use C (but, in spite of that, I avoid it as much as possible... if SoftICE was still available, I doubt I'd write more than 100 lines of C per year, consisting only of small additions to existing code exclusively for testing O/S behavior.)  The other reason I still use C is because there are libraries that either, are only available in C or, actively supported in C.

You need a good language but, without a good environment, a good language is for intellectual masochists.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11951
  • FPC developer.
Re: A question on Modula2 vs Free Pascal
« Reply #9 on: March 15, 2024, 09:09:07 pm »
I would like to thank you both... but a follow up question arose:

@ Markov:
Why C? Can't you have Pascal in embedded? (Unless I am mistaken by considering firmware as embedded).

FPC has no dspic backend. There is some third party dspic pascal, but for relative straight code and commercial timelines, it is simply not worth the effort to veer from the vendor's choice unless you have really good reasons. It has nothing to do with the properties of C itself, other than being supported by the vendor.

Quote
On the other side, I would say that I appreciate the fact that M2 is "pure" (i.e., without OO). Essentially I do not want to delve into OO -I rather prefer either procedural/imperative or functional (tried Lisp in the past).

Yeah, well, then we are done talking. In all of my 35 years of programming including almost a decade of M2 (not all of it exclusively), I never "got" the concept of purism over practical considerations ;-)

For me, "what can I do with it" always topped stylistic concerns.

The only thing I can recommend is keeping a good eye open for anything except for language, i.e. the wider project!

Quote
So, my conclusion is that perhaps I should be inclined towards M2 (

Good luck then! If you find proper download locations for gm2 and a forum, don't hesitate to post them here! Despite going the other way I'm still somewhat interested.
« Last Edit: March 15, 2024, 09:22:23 pm by marcov »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11951
  • FPC developer.
Re: A question on Modula2 vs Free Pascal
« Reply #10 on: March 15, 2024, 09:17:01 pm »
What is "firmware"? When I were a lad it was in ROMs, PROMs, or- at a pinch- EPROMs. More recently it's been consigned to (non-filesystem) blocks of Flash, sometimes with a protected boot loader (i.e. like an Arduino etc.). But the Great Unwashed now seems to think that firmware is something that's loaded into memory from a filesystem...

I don't know if I'm washed or not, but I'm talking about the dspic33epXXXM?8YY series. With XXX= the kb of flash, the YY = (number of pins div 10) and ? the availability of USB or not.   (U=USB, C=not. we prefer not since USB wastes 2 pins, but due to corona we have become less picky)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8046
Re: A question on Modula2 vs Free Pascal
« Reply #11 on: March 15, 2024, 09:44:35 pm »
I don't know if I'm washed or not, but I'm talking about the dspic33epXXXM?8YY series. With XXX= the kb of flash, the YY = (number of pins div 10) and ? the availability of USB or not.   (U=USB, C=not. we prefer not since USB wastes 2 pins, but due to corona we have become less picky)

IOW, "classic" firmware in some form of PROM or Flash without a filesystem. I've seen a suggestion that anything stored in a filesystem, whether or not it is intended to be rewritten on a regular basis, would be better called slushware: in any event the concept that something like Firefox is software on a PC but firmware on a 'phone or tablet sticks in my craw.

Good luck then! If you find proper download locations for gm2 and a forum, don't hesitate to post them here! Despite going the other way I'm still somewhat interested.

Regrettably, I agree. However I've got a list of Pascal problems which in most cases apply also to M2, and a personal project I'd like to pick up at some point to revisit some compiler technology which just about exists on paper but has been lost in implementation.

I might get somewhere with that, but want to also say that David Given's Cowgol appears worthy of study and possibly support: it borrows heavily from Ada with a tinge of Rust but can apparently self-compile on an 8080-based CP/M system.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

DoDep

  • New Member
  • *
  • Posts: 26
Re: A question on Modula2 vs Free Pascal
« Reply #12 on: March 15, 2024, 09:51:02 pm »
Now, that statement is a _big_, really BIG mistake.  Without all the OOP stuff, which is the way I use it, Lazarus provides a reasonably decent editor, a very capable source code navigator (courtesy of codetools) and, most importantly, a very capable debugger, FpDebug, that is getting better everyday (well... make that roughly every week... thanks Martin and all those involved in its development).

Personally, I believe a good debugger is every bit as important as the programming language because no matter how good the language may be, programming errors will occur and without a good debugger, it can be a real pain to locate them.  The Visual Studio debugger and Windbg are the main reasons I still use C (but, in spite of that, I avoid it as much as possible... if SoftICE was still available, I doubt I'd write more than 100 lines of C per year, consisting only of small additions to existing code exclusively for testing O/S behavior.)  The other reason I still use C is because there are libraries that either, are only available in C or, actively supported in C.

You need a good language but, without a good environment, a good language is for intellectual masochists.
Well, to be honest, what I wrote about Lazarus is that others here, mentioned that -and I took it for granted. Nevertheless I do agree that in any case could be used, even as a (very) sophisticated editor. But I just have failed to build it from sources....

DoDep

  • New Member
  • *
  • Posts: 26
Re: A question on Modula2 vs Free Pascal
« Reply #13 on: March 15, 2024, 09:55:50 pm »
Yeah, well, then we are done talking. In all of my 35 years of programming including almost a decade of M2 (not all of it exclusively), I never "got" the concept of purism over practical considerations ;-)

For me, "what can I do with it" always topped stylistic concerns.
I do understand, and I did not mentioned to offend anyone. Eventually, I do agree that what is important is for the job to be done. On the other hand, I am not a professional (just a hobbyist) so I have the "luxury" of being "short-sighted" -if you want. On top of that I never understood the fundamental ideas behind OO paradigm (perhaps I have not tried enough) and moreover I am more mathematically inclined person -hence the reference to the functional paradigm.

DoDep

  • New Member
  • *
  • Posts: 26
Re: A question on Modula2 vs Free Pascal
« Reply #14 on: March 15, 2024, 10:00:01 pm »
Good luck then! If you find proper download locations for gm2 and a forum, don't hesitate to post them here! Despite going the other way I'm still somewhat interested.
For the time being I am building gm2 (veeeery time consuming ;-) ). So regarding the first part, I am just using the "old way". Regarding the second one (i.e., the forum), I do not think so. Probably, there is nothing...

 

TinyPortal © 2005-2018