Recent

Author Topic: Is Pascal the right language for me ?  (Read 5874 times)

Warfley

  • Sr. Member
  • ****
  • Posts: 309
Re: Is Pascal the right language for me ?
« Reply #45 on: June 30, 2020, 09:52:38 pm »
Quote
1. The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.

Yeah, but It's not really insightful, this is basically a rephrasing of "If you have a hammer, everything is a nail".
Thats why it's so important to have many different tools at hand. If you give a life long C programmer the task to parse an string, he will most probably start by writing a low level state based text parser, while if you give the same task to a python programmer, he will probably just write a regex for it. That's the reason why I believe everyone should try out at least a few different paradigms like functional programming, it really broadens your horizon and allows you to think differently about problems.

For example, many computer scientists profess to be followers of Whorf and to be searching for a notation which prevents common programming errors, while at the same time being prepared to countenance syntaxes which can't be parsed easily and semantics which require complex run-time support.
It fully depends on what your needs are. For example, garbage collection is pretty slow, but if you don't need that performance and you simply want to get something done without having to think a. about ownership or b. about memory management, it works great (see Java, the performance penalty is not stopping it from being one of the most prevalent languages).
But even if you are concerned about performance there are many compile time possibilities, like they are employed by rust (and partly C++). Or, my favorite example for this are Null pointers. Null pointer errors are extremely tedious, even in pretty "safe" languages like Java.
But there is no need for them to exist. In for example TypeScript, Swift or Kotlin, there are no Null pointers, there are only Nullable variables. This means, every variable that can become null, must be marked as such. If a variable is marked as null, everywhere where it is used, you need to check if it is assigned (provable at compile time). If you know a variable will never be null, you will not mark it, and then you (and the compiler) knows, what ever happens, in this variable will always be a valid pointer.
All of this happens during compile time, and with this little change, Nullpointer derefenrencing seg-faults are simply not possible anymore. One of the major bug sources simply gone by a better language design without any penalty

Languages are designed with specific goals in mind. For example, haskell applications become huge because haskells lazy evaluation strategy requires a lot of boilerplate code for the compiler to generate. It is also not the fastest, but in haskell you can handle infinitely large objects with ease, something that is not easily possible in other languages.

It's all a matter of requirements. I would never write an OS in Java, but I also wouldn't write a cross plattform gui program in C.
« Last Edit: June 30, 2020, 10:03:02 pm by Warfley »

gour

  • New Member
  • *
  • Posts: 17
Re: Is Pascal the right language for me ?
« Reply #46 on: August 11, 2020, 02:38:44 pm »
It depends very much on what you do. I think this is a bit overly black and white. And one of the problem is that currently the popular choices are changing so often they might not even be there any more if you quit your current job. 
...
If you are self employed or work in a situation where IT is part of a product or service, it is less important, and your long term maintainability becomes important. And nowadays Lazarus' continuity is actually a plus there.
If you are hobby, that long term view is even more important, since your development will go slower, and you want to be able to maintain for a while to reap the rewards of your effort.

Let me just share my story...Five years ago I was already interested in FPC/Lazarus wanting to work in my spare time on a hobby project -- open-source multi-platform desktop application, but due to several reasons had to postpone it until today...In the meantime I was considering/evaluating and/or played with several languages and eliminated them for the various reasons, like:
  • C is too low-level for me and do not want to fiddle too much with pointers
  • C++ evolved into huge beast since the time when I was doing my thesis on the university using Zortech compiler
  • Java was eliminated from the very start for being quite bloated

Then I did try/consider some like:
  • Haskell, but it fails, like many others (e.g. D, Go,...) with GUI-test, iow. not having decently supported GUI bindings
  • some like Rust have weird syntax
From the very beginning I also eliminated Electron and similar JS-powered stuff wanting to have native application.

To make the story short, I ended up with the following possibilities:
  • Racket which has nice built-in and support GUI DSL, but I abandoned it due to having experience with Lisp/Scheme languages
  • Nim is attractive language with too many GUI options, but none supported wel. I have also considered Nim for the back-end + Python for the front-end, but prefer to avoid 2-language solution
  • Julia also does not have GUI solution except with GTK which does not look great on Windows/Mac OS-es, while possibility to use Julia+PyQt (via PyCall) means, again, to handle 2-language solution
  • Pure Python via PyQt was last option, but the nature of my app would probably require speeding up slow python code by usign Cython or something
When I was already a bit in despair I've remembered FPC/Lazarus which I did explore in the past and which seems as the only solution for my use case to fulfill (almost) all of my requirements and I really wonder why it is not used more widely.  :o

Considering I plan to work on the project in my free time for a longer period of the time, I also consider that FPC/Lazarus' "Lazarus' continuity" is a great 'pro'.  :D

Moreover, FPC/Lazarus does offer opportunity, afaict, to even write 'lighter' version of my application for e.g. my Android phone. 8-)

I was writing code on my university using Turbo Pascal (compiler course) and like...after graduating my life went into another direction, but I'm happy to, somehow, close the circle, by returning back to Pascal hoping it won't take me too long to get into it, while, afaics, Lazarus does provide environment for RAD.

I've some question about recommended procedure to learn/master FPC/Lazarus, but that's not appropriate for this thread.  ;)

Any comment on my reasoning and/or whether I've arrived to the proper solution?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8779
  • FPC developer.
Re: Is Pascal the right language for me ?
« Reply #47 on: August 11, 2020, 02:57:06 pm »
Any comment on my reasoning and/or whether I've arrived to the proper solution?

It's basically my reasoning too. Even if I for some reason change the tooling for some main app, and in my line of work (Vision) that usually means C++, I think all the small programming stuff, the utils, the scripts etc remains in FPC/Lazarus.

BeniBela

  • Hero Member
  • *****
  • Posts: 760
    • homepage
Re: Is Pascal the right language for me ?
« Reply #48 on: August 12, 2020, 11:02:15 pm »
For example, garbage collection is pretty slow, but if you don't need that performance and you simply want to get something done without having to think a. about ownership or b. about memory management, it works great (see Java, the performance penalty is not stopping it from being one of the most prevalent languages).
In many cases garbage collection can be faster than heap allocatiojn.

Moving garbage collectors could also move data around to improve cache locality.

Or, my favorite example for this are Null pointers. Null pointer errors are extremely tedious, even in pretty "safe" languages like Java.
But there is no need for them to exist. In for example TypeScript, Swift or Kotlin, there are no Null pointers, there are only Nullable variables. This means, every variable that can become null, must be marked as such. If a variable is marked as null, everywhere where it is used, you need to check if it is assigned (provable at compile time). If you know a variable will never be null, you will not mark it, and then you (and the compiler) knows, what ever happens, in this variable will always be a valid pointer.

It is very silly that Pascal went from having only record and objects on the stack, which are never null, to classes where every class object can be null

winni

  • Hero Member
  • *****
  • Posts: 1894
Re: Is Pascal the right language for me ?
« Reply #49 on: August 12, 2020, 11:30:20 pm »

It is very silly that Pascal went from having only record and objects on the stack, which are never null, to classes where every class object can be null

Hi!

Yes - that is true.

But look at Borlands situation in the mid 90s:

Turbo Pascal for Windows was awful and a big flop.
But in the background Delphi was developed - with one great idea:
It was a milestone for Rapid Prototyping .
The second big change was not so brilliant:
The introduction of classes.

But Classes came then into fashion despite all the debates:
There were the critics of N. Wirth, there were the critics because of the inheritance.
And there were fans of the "old" Turbo Object Model which was introduced then not long ago.

But we allways have to be a "dedicated follower of fashion" (Ray Davis, The Kinks, 1966).
So the Classes were implemeted into Delphi 1.
And 25 years later they are still there.

Not mater if sense or nonsense.

Winni



MarkMLl

  • Hero Member
  • *****
  • Posts: 1319
Re: Is Pascal the right language for me ?
« Reply #50 on: August 13, 2020, 09:06:20 am »
It is very silly that Pascal went from having only record and objects on the stack, which are never null, to classes where every class object can be null

Would I be right in assuming that an object on the stack has its lifetime defined by the scope of the function in which it is declared? If that is correct then ISTM that it implies excessive reliance on global variables, or alternatively Pascal would have needed an equivalent to ALGOL's OWN which is generally considered to be a mess.

It's not instances of classes that are nullable, it's anything on the heap as a general statement. And ISTM that the bigger problem is not null (pointers to) instances, but invalid pointers in general (uncluding doubly-freed as a special case).

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

440bx

  • Hero Member
  • *****
  • Posts: 2007
Re: Is Pascal the right language for me ?
« Reply #51 on: August 13, 2020, 10:18:15 am »
Would I be right in assuming that an object on the stack has its lifetime defined by the scope of the function in which it is declared?
That's correct. Just like any other variable, an object (not a class) on the stack "vanishes" when the function/procedure goes out of scope.

If that is correct then ISTM that it implies excessive reliance on global variables,
Not really.  The program can use heap blocks for data it wants to be persistent, that said, heap blocks do share some of the global variable problems and, an additional one which is, one must remember to free them when no longer needed.  Classes give you the _worst_ of both worlds, there is almost always at least one class variable that is a global variable and its data is allocated on the heap.  Gotta love it. :)


FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1319
Re: Is Pascal the right language for me ?
« Reply #52 on: August 13, 2020, 10:26:21 am »
But at that point if you're using a heap block you've already got a (nullable) pointer to it. Delphi-style classes and instances only change things by hiding the indirection.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

440bx

  • Hero Member
  • *****
  • Posts: 2007
Re: Is Pascal the right language for me ?
« Reply #53 on: August 13, 2020, 10:42:03 am »
But at that point if you're using a heap block you've already got a (nullable) pointer to it.
True. 

Personally, I firmly believe that memory management should be tailored to the problem at hand.  That means, a one-size-fits-all "solution" such as class data always being in a heap block is inherently limiting (I'm abstaining from saying it's wrong, even though I firmly believe it's so highly deficient that it would be fair to consider it wrong at least most of the time.)

I think that's the real problem: trying to make a one-size-fits-all "solution" work well in _all_ cases.  I know it doesn't exist and, I seriously doubt it ever will.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8779
  • FPC developer.
Re: Is Pascal the right language for me ?
« Reply #54 on: August 13, 2020, 12:53:51 pm »
For example, garbage collection is pretty slow, but if you don't need that performance and you simply want to get something done without having to think a. about ownership or b. about memory management, it works great (see Java, the performance penalty is not stopping it from being one of the most prevalent languages).
In many cases garbage collection can be faster than heap allocatiojn.

It often also depends on your testing parameters. The problem is that you rarely can make a pure comparison:

  • language with generational gc often use the heap more, because shortlived heap usage is relatively cheap. The same access pattern for a non generational GC is unnecessarily expensive, and something you never do in practice
  • strings are sometimes immutable and treated differently from normal allocations, with global lists. Immutable strings are afaik not for speed, but to limit memory consumption
  • similarly at the non GC side, strings might be handed differently from normal allocations too, like FPC's refcounted copy on write strings

Truth be told, in my year doing .NET, and separate 1.5 years Java, I never saw the wonders of GC for non trivial programs. (In one source programs, global optimizers might simply optimize the GC usage away, or the allocation pattern might be very simple (e.g. always the same size)). At best the slowdown was not really bad, never better.

Quote
Moving garbage collectors could also move data around to improve cache locality.

Which of the main GC languages do this? Other than just after allocation when they are still in the same generation of course?

Or, my favorite example for this are Null pointers. Null pointer errors are extremely tedious, even in pretty "safe" languages like Java.
....
If a variable is marked as null, everywhere where it is used, you need to check if it is assigned (provable at compile time).

Well, actually sounds like replacing one tedious chore by the other.

I never got the obsession with nullability. Basically it only helps when you change a piece of source from non-nullable types to nullable types, and for that case a limited language extension seems to be overkill IMHO.

Most code is made with nullable types, and remains so.

Quote
It is very silly that Pascal went from having only record and objects on the stack, which are never null, to classes where every class object can be null

Yes. No tricks under the hood to make static types to look like dynamic ones. No autoboxing either (well, one could maybe consider type helpers a form of that)
« Last Edit: August 13, 2020, 01:00:09 pm by marcov »

MarkMLl

  • Hero Member
  • *****
  • Posts: 1319
Re: Is Pascal the right language for me ?
« Reply #55 on: August 13, 2020, 01:29:45 pm »
Quote
Moving garbage collectors could also move data around to improve cache locality.

Which of the main GC languages do this? Other than just after allocation when they are still in the same generation of course?

My recollection is that the Smalltalk "Green Book" documents a GC that does that: alternately consolidates data to one end of the heap or the other.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8779
  • FPC developer.
Re: Is Pascal the right language for me ?
« Reply #56 on: August 13, 2020, 01:56:51 pm »
My recollection is that the Smalltalk "Green Book" documents a GC that does that: alternately consolidates data to one end of the heap or the other.

I'm just trying to distinguish alleged possible features from features that are actually proven. Quite often these kinds of optimizations are demonstrated with crafted one piece source on some convention, but it is often hard to successfully integrate it in a production toolchain, because there is much more competition for a place in the cache then, and it requires an overall optimization.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1319
Re: Is Pascal the right language for me ?
« Reply #57 on: August 13, 2020, 03:00:26 pm »
My recollection is that the Smalltalk "Green Book" documents a GC that does that: alternately consolidates data to one end of the heap or the other.

I'm just trying to distinguish alleged possible features from features that are actually proven. Quite often these kinds of optimizations are demonstrated with crafted one piece source on some convention, but it is often hard to successfully integrate it in a production toolchain, because there is much more competition for a place in the cache then, and it requires an overall optimization.

In any event, Smalltalk was a special case since the entire system- including RAM and any swapspace on disk- was dedicated to a single environment.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Warfley

  • Sr. Member
  • ****
  • Posts: 309
Re: Is Pascal the right language for me ?
« Reply #58 on: August 14, 2020, 01:20:34 pm »
In many cases garbage collection can be faster than heap allocatiojn.

Moving garbage collectors could also move data around to improve cache locality.

The two big GCs (.Net and Java) are both generational garbage collection systems optimized for speed of small allocations. They consist basically of three stacks, gen 1-3, and when you allocate an object it is just pushed to the g1 stack. When the garbage collector starts running (after a certain time, or if g1 stack reaches a certain size), every object that is still in use in g1 gets pushed to g2 and g1 will be completely erased.
If g2 reaches a certain size (much bigger than g1) it will go through the same procedure and everything that survives now lives happiely in g3. There the assumption is, that everything that survived the gc 2 times, is probably here to stay, and g3 will never be cleared (Might sound stupid, but in reality, this seems to be a good assumption).

So the cleartime is O(StackSize*AverageNumReferencesToObjects) because for every object, all references need to be rewritten. But the allocation of an object, as this is just increasing a stack pointer, is basically free (compared to traditional heap allocation systems which have to search free space) and while g2 gc is expensive, Microsoft reported somewhen that their g1 gc is performed in around the time it takes Windows to handle a page fault.

So if you allocate a lot of temporary objects (like in Pascal is often done with for example streams or string lists), gc might even be faster, but the thing about GC is that it is unpredictable on when  the g2 gc runs, which can cause notable lags. Also memory fragmentation simply doesn't happen with such GC systems. It all depends on what you need.
Which is exactly why I like pascal old school objects, because they live on the stack and it always feels like a complete waste of resources to create a TStringList for only one small procedure. But thats historic and we can't travel back in time and tell borland to do it any other way

Btw. while on the desktop the g2 gc lag is not that notable, even in GUI applications, on android, when you control your device on your fingertips every lagg is notable instantly, which is why google had to become creative, but thats a whole different story.

Warfley

  • Sr. Member
  • ****
  • Posts: 309
Re: Is Pascal the right language for me ?
« Reply #59 on: August 14, 2020, 01:34:21 pm »
Well, actually sounds like replacing one tedious chore by the other.

I never got the obsession with nullability. Basically it only helps when you change a piece of source from non-nullable types to nullable types, and for that case a limited language extension seems to be overkill IMHO.

Most code is made with nullable types, and remains so.

In my experience, while this nullability marking can be pretty tedious at times, depending on the API, checking for null pointer in languages like Java is much more tedious. Of course when you do something like (typescript example, which also has this system):
Code: Javascript  [Select][+][-]
  1. if (map.contains(key)) {
  2.   let result = map.get(key); // optional but I know it's not
  3. }
It is annoying, but for this there is the "Hack" of simply writing !, which means: "I know what I'm doing, trust me" and avoids these checks.

But the thing where it is useful (I must confess this is more a problem in the Java world but anyway) is not when types change, but null pointer errors are most often documentation errors, where someone uses an API or a lib and thinks a value can't be null, but then it is. Maybe the user has not looked closely enough into the API docs, or the API docs are not sufficient, both things happen often (and simply telling programmers to do it right hasn't worked out for 30 years now). Another problem that can lead to null pointer errors is complexity, when you carry a variable around through many paths, on which one might lead to it not being initiated (some cornercase or so) but it is not obvious to see.

The optional type solves this problem on a technical level, where the type itself tells you if it is optional or not and if the compiler can't prove that a type will be be initilized on all paths and it is not marked as optional, it won't compile. It basically goes the route of replacing documentation by a clear coding pattern, which is great, because documentation is something that somehow never works (either outdated, not written at all, or ignored by the users)

From my experience this works incredibly well. The only main source of annoyance are interfaces with languages that don't have this type system, like in typescript, when you use a classical js library, a value from the js library can always be everything, so it always optional and then you get to the same problems as before, just with additional syntax.

 

TinyPortal © 2005-2018