What's Pascal to you?
What's Pascal to you?In my opinion Pascal is just another programming language from a wide spectrum, with machine instructions and assembly at one extreme and Siri/Google Assistant at the other extreme. One can construct endless arguments and comparisons between different languages to pick the "best" language.
What's Pascal to you?My weapon of choice when I'm not forced to use anything else specifically. One of a few language I can't have excuse like "it's compiling / building / packing / whatevershitthatmanymainstreamlanguageshave" because compilation is damn fast that compile-debug cycle has no need for interpreter (Hi, Haskell!) and release is practically a few seconds difference as opposed to minutes or hours (Long time no see, ReactJS! You again, Haskell!). All of those without any loss of performance or crazy memory hog, even deployment to server is a single static binary (not really, but at least the dependencies are usually against system level libraries, not application ones). No claim for single command installation (that does a bunch of downloading, installing, configuring, etc. that takes too long so we can go for a cup of coffee or tea and it's still not yet finished when we return) needed, because installation is not even required.
Because I'm not so smart to program in C++ :)I was a C++ programmer but when I discovered Delphi I decided don't use C++ again in my life. But I still like C though. ::)
What's Pascal to you?
Same goes for - native - sets.
variable declarations within a code block... even on the fly.... which is silly although it "saves time"..<think! >:D >.
better than scrolling every time to var region !Relax Your Forefinger, and jump instead:
Afaik, the first MacOs's had been written with Pascal.
-> Does anybody know, why, and why Pascal was left ?
@All the others
I love Lazarus and FPC. :-*
It installs fast and w/o Problems (at least with me: WinXP SP3).
It is so easy to use, compiles and runs fast, and is full with useful Features, ...
And a very strict separation of declaration and implementation throughout the language, which makes it not only easier to read but also less prone to errors than C like languages that allow e.g. variable declarations within a code block... even on the fly....
.... which is silly although it "saves time"..<think! >:D >.
-> So far, so good, but why did they have to change the programming language,
only because of changing the processor. Did Pascal not support it ?
I believe that declaring variable only in the block where it belongs is what actually makes code not only less prone to errors, but also easier to read.Quite the contrary, my experience with block level declaration makes my code buggier than the Pascal strict single declaration style. This is mainly due to the variable shadowing where you might unintentionally shadow the outer variable having the same name and type as the inner one and accidentally misrefer, either in outer or inner block. Not that often happen, but when it does, it really sucks to debug.
"Don't declare variable outside of exact block they belong to" is what I really miss in Pascal.
Agreed. I prefer to do more complex logic in several blocks with nested functions. First, it is so easy in pascal. Second, a named block of code is very easy to understand and reduces the complexity of the code. And if you think about efficiency, "inline" will remove this issue.I believe that declaring variable only in the block where it belongs is what actually makes code not only less prone to errors, but also easier to read.Quite the contrary, my experience with block level declaration makes my code buggier than the Pascal strict single declaration style. This is mainly due to the variable shadowing where you might unintentionally shadow the outer variable having the same name and type as the inner one and accidentally misrefer, either in outer or inner block. Not that often happen, but when it does, it really sucks to debug.
"Don't declare variable outside of exact block they belong to" is what I really miss in Pascal.
"routine nested in routine" Pascal featureI quite hate that feature. The function name gets pulled away from its code. Besides I don't see why the feature would be needed, just reduces a bit typing.
Besides I don't see why the feature would be needed, just reduces a bit typing.
I quite hate that feature. The function name gets pulled away from its code. Besides I don't see why the feature would be needed, just reduces a bit typing.
When you need some functionality inside a function, you can implement it only there, by creating nested function, whose scope is within the function it is nested in, so not polluting outer scope.+1
When you need some functionality inside a function, you can implement it only there, by creating nested function, whose scope is within the function it is nested in, so not polluting outer scope.+1
I quite hate that feature. The function name gets pulled away from its code. Besides I don't see why the feature would be needed, just reduces a bit typing.Quite the contrary, you can name the nested subroutines very well according to their specific task inside the outer routine. And no, it doesn't reduce typing, it adds instead. But for the much more increased readibility and potentially prevent duplication, the more typing pays.
Anyways, I don't use it so in the end I'm fine with it.
Nested procedure can take parameters, so that is more than just typing.I wasn't aware of that so I didn't see the point of nested functions. Already convinced!
(From a code-readability point of view I'd prefere the nested functions to be placed below the "outer" function.)that is impossible in all known languages, all procedures/functions must be declared and compiled before they are used so above is the only appropriate place.
Afaik originally it was a gcc extension (maybe meanwhile standarized), but is syntax only. Afaik gcc doesn't implement children touching the parent variables or parameters.May be not now, but it did allow to use parent variables and parameters. I can't find the code right now (I've found it wasn't in the old Allegro.pas code %)) but I did it and it worked.
"Don't declare variable outside of exact block they belong to" is what I really miss in Pascal.How would You declare global Vars then ?
What I really miss in Pascal, is the Possibility to declare static Vars within a Routine. :(
@Handoko
No, I mean Vars, that are declared in a Routine and keep their Value until the next Call.
:)
This is a slightly more revealing example
Sure! :DNote you need to have {$writeableconst on} or the equivalent {$J+} for this to work.
Indeed, the most use for a typed const is to maintain state over function calls, it behaves like a persistent (global) var, not a local var but is hidden from global access.. […]Or a unit where the var is allocated in the implementation section.
The alternative is writing a class, but this feature is much older and a precursor to Object Pascal.
[…] {$writeableconst on} […]One of the worst compiler switches, ever (besides {$COperators on}). I mean constants, hence their name are supposed to remain constant, i.e. you can't assign any value to them.
One of the worst compiler switches, ever (besides {$COperators on}). I mean constants, hence their name are supposed to remain constant, i.e. you can't assign any value to them.No it is not: it is a constant over calls, not a traditional constant without type (which many people will probably also do not understand: how to determine the type of a constant....).
However, the syntax is quite unfortunate. I never understood why are these declared with const keyword.I somewhat agree with you, but note typed consts are typed. So although const necessarily has a different meaning it is quite natural.
Perhaps we should call these global variables with local scope (although accessible from local scope only, they are allocated in global memory region).
Of course, as we know what we are doing, there is nothing wrong with using this feature.
but note typed consts are typed. So although const necessarily has a different meaning it is quite natural.
@ZoranQuote"Don't declare variable outside of exact block they belong to" is what I really miss in Pascal.How would You declare global Vars then ?
@ZoranQuote"Don't declare variable outside of exact block they belong to" is what I really miss in Pascal.How would You declare global Vars then ?
Are you serious?
I'd do it this way:
var N: Integer;
That is a constraint, not a type. A const is typeless, usually platform dependent as well. Only its value is guaranteed.but note typed consts are typed. So although const necessarily has a different meaning it is quite natural.Typed? Natural? What makes it typed?
Not to mention that you can declare true constant's type explicitly, as well:
const N = Int64(123); // a true const
And a very strict separation of declaration and implementation throughout the language, which makes it not only easier to read but also less prone to errors than C like languages that allow e.g. variable declarations within a code block... even on the fly.... which is silly although it "saves time"..<think! >:D >.
I also started learning C and C++. Meh. Nice languages, but nothing like Pascal for me (totally subjective sentiment).Thank you for being objective here.
Compiler directives are not necessarily part of the Pascal language. Strictly speaking they aren't.Yes, sure. They are not part of the language. Still practically the language can not be used without them. :(
But cryptic syntax is always possible:Equivalent to #13#10#7.Now, how many of you remember what that does.?
begin write(^M^J^G);end.
the caret character (^) can be used in combination with a letter to specify a character with ASCII value less than 27. Thus ^G equals #7 - G is the seventh letter in the alphabet. The compiler is rather sloppy about the characters it allows after the caret, but in general one should assume only letters.
Equivalent to #13#10#7.Equivalent to mechanical typewriter (return + bell).
Have you read the link? Typed constant is not the constant that you thought.Yes, it is (sorry).
However, the syntax is quite unfortunate.In my Opinion, as well, it's quite misleading to name something a "Constant", that is variable,
Perhaps we should call these global variables with local scopeOr simply "static variables".
I'd do it this way:It depends on how You define an "exact block" - I wouldn't call a Unit or the Program itself an "exact block".
He means in each scope. With your code you are creating a variable for all function scope, ...I actually meant in each scope in the Sense of being available anytime and anywhere in the Program.
@ZoranQuoteHowever, the syntax is quite unfortunate.In my Opinion, as well, it's quite misleading to name something a "Constant", that is variable,
even if it can be seen as "constant over calls" as Thaddy mentioned. (I also fell into that "Trap".) %)QuotePerhaps we should call these global variables with local scopeOr simply "static variables".
AFAIK the "typed constant" description is nomenclature inherited from TP / early-Delphi times, we can't blame the FPC developers for that.
Personally I prefer to call them "initialised variables".
we can't blame the FPC developers for that.I didn't want to blame the FPC-Developers, but everything can be improved.
No it is is not. Typed constants are not even unique to Pascal.AFAIK the "typed constant" description is nomenclature inherited from TP / early-Delphi times, we can't blame the FPC developers for that.
Yes, the unfortunate naming is Borland's fault.
No it is is not. Typed constants are not even unique to Pascal.AFAIK the "typed constant" description is nomenclature inherited from TP / early-Delphi times, we can't blame the FPC developers for that.
Yes, the unfortunate naming is Borland's fault.
To mention a few: several COBOL dialects, ADA and C++.
For somebody that actually read the theory it is perfectly valid and logical naming. Typed vs Literal should be enough to understand it..
https://en.wikipedia.org/wiki/Constant_(computer_programming)
In C++ - depending on compiler settings - it is possible to change the value of a named constant within its scope. That is basically the same as Pascal.
The big difference between const and named/typed const is memory allocation. Named consts and typed consts have an address....
Zoran you miss the point for typed consts. It is actually a low-level construct that pre-dates Object Pascal and makes maintaining state - like fields of a class - between function.procedure calls possible.
It is NOT a var!It is const in the sense that it is const, not writable, outside of the scope where it is declared. A var is reset every call.
{{$WRITEABLECONST ON} function countme:integer; const i:integer = 0; begin; inc(i); Result := i; end; var k:integer; begin for k:= 0 to 9 do writeln(countme); end.
Nothing new, nothing to do with Pascal as such. It is quite a common concept in computer science, not only compiler design, but e.g. also functional design.
There is already sufficient difference between a typed const and an untyped - really an inferred const which size is usually determined based on the CPU register size! - const. And even if writableconst is selected, it still is a memory location and NOT free for the compiler to substitute with a immediate constant value. Although optimization may choose otherwise when appropiate.. The latter is real implementation detail....
I also started learning C and C++...Nice languages, but nothing like Pascal for me...Though I did not try out or even learn so many ProgrammingLanguages as You did
+ For me, Pascal just happened to suit my personality, and has been quite capable of doing all that I have needed.
it will be more like glorifying PascalNot necessarily, see here http://forum.lazarus-ide.org/index.php/topic,40803.msg285336.html#msg285336 (http://forum.lazarus-ide.org/index.php/topic,40803.msg285336.html#msg285336)
I used VB for awhile and it sucked and then Delphi came...and I immediately dropped VBSame with me.
+ I ported everything I had to Lazarus and FPC and have not used Delphi since.
but much more important for the programmer is to keep distinction between what can vary...and what is constantYes. :)
-> What is missing in Pascal ?
-> What can not be done with Pascal without "big Detours" ?
(even if this Thread's Title is "Why Pascal?".)
For me C/C++ is like "interesting, but strange", while Pascal is like being at Home.
(really totally subjective Sentiment)
I found an actual picture of how C++ looks like:+1