3 ms·
The syntax is timeless, because it is much closer to math than B/BCPL/C heritage. It has its own issues but overall it is much better thought out than most oth
by weinzierl 3y ago
The syntax is timeless, because it is much closer to math than B/BCPL/C heritage.
It has its own issues but overall it is much better thought out than most other languages.
Here is a comment I wrote a couple of months ago with more arguments for Pascal's syntax:
"Yes, Rust does indeed and a long time before that it was Pascal. I really love Pascal's syntax, it makes a lot of sense when you approach it with a math background.
- '=' is for equality only
- assignment is ':=' which is the next best symbol you can find in math for that purpose
- numeric data types are 'integer' and 'real', no single/double nonsense
- 'functions' are for returning values, 'procedures' for side effects
- Function and procedure definitions can be nested. I can't tell you what shock it was for me to discover that's not a thing in C.
- There is a native 'set' type
- It has product types (records) and sum types (variants).
- Range Types! Love'em! You need a number between 0 and 360? You can easily express that in Pascal's type system.
- Array indexing is your choice. Start at 0? Start at 1? Start at 100? It's up to you.
- To switch between call-by-value and call-by-reference all you have to do is change your function/procedure signature. No changes at the call sites or inside the function/procedure body. Another bummer for me when I learned C.
Pascal wasn't perfect but I really wish modern languages had syntax based on Wirth's languages instead of being based on BCPL, B and C."
https://news.ycombinator.com/item?id=32983878 https://news.ycombinator.com/item?id=32983878
- troupo 3y agoIt's only "mathematical" if you chose very specific parts of the language from a very specific version of Pascal when looked at at a very specific angle. E.g. the argument falls apart immedately: - there's no assignment operator in maths - there are no procedures in maths, everything is a function - functions cannot be nested in maths (unless I'm mistaken) - types is maths, but Pascal uses a very narrowed down and dumbed down version of it etc. etc. Pascal is the way Pascal is because Wirth wanted the simplest possible language according to Wirth's own criteria that could be compiled in a single pass on a 1980s computer. It's the go [1] of its time. That is it. Both the syntax and Pascal's concept are severely outdated. It's a very good thing that modern languages never adopted Pascal's syntax and went for something that is actually usable. Hell, Erlang is a more mathematical and timeless syntax than Pascal, and it's a trivial langauge at it's core. [1] Can't find the actual text now, but there was a rationale by Rob Pike that go was amed at junior engineers, and needed to be simple.
- weinzierl 3y ago"- there's no assignment operator in maths" There is no assignment but in math we use := to express that two things are equal per definition. I never said it was the same thing, just that it is the closest thing. From a math perspective it makes total sense, while singular = for assignment makes no sense at all. Especially when you want express the concept of equality as well and cannot use the obvious choice = anymore because you already used it for something else. "- there are no procedures in maths, everything is a function" Exactly and that's why functions and procedures in Pascal are separate things, like it is meant to be. Functions have an equivalent in math, procedures don't. Mixing the two concepts up into the weird thing C calls a function is just wrong. "- functions cannot be nested in maths (unless I'm mistaken)" In some sense they can. In C they can't because of technical restrictions, no one ever was fond of that restriction, not even back in the day. "- types is maths, but Pascal uses a very narrowed down and dumbed down version of it" Pascal is a programming language, not math. My point is solely that Pascals syntax is superior to C's because (among other reasons) the former is closer to centuries old tried and tested and well established syntax of mathematical notation. It has some consistency and elegance and certainly flaws as well. C's syntax decisions were more driven by long gone technical restrictions than what makes sense to a human. Now we have to live with that baggage.
- troupo 3y agoEdit: In his Pascal report Wirth mentions math zero times: http://pascal.hansotten.com/uploads/books/Pascal_User_Manual_and_Report_Fourth_Edition.pdf http://pascal.hansotten.com/uploads/books/Pascal_User_Manual... And in fact in 1971 he wrote that it was basically copied from ALGOL: https://oberoncore.ru/_media/library/wirth_the_programming_language_pascal.pdf https://oberoncore.ru/_media/library/wirth_the_programming_l... Edit2: Most relevant part from second link: "The syntax has been devised so that Pascal texts can be scanned by the simplest techniques of syntactic analysis". That's it. On to other comments which are basically relevant given Wirth's own words: > but in math we use := to express that two things are equal per definition. Then it isn't variable assignment. It's what you pretend it is because Pascal defined variable assignment this way, and now you're trying find an angle for which "Pascal is closer to math" works. When we write "x = f(y)" or "x = y + z where z = f(t)" in maths there's no confusion as to what this expresses. No need for "equal by definition". Note: Interestingly enough, Wikipedia doesn't list `:=` in its glossary of mathematical symbols [1] And then there's another sign used for definitions: equality sign with delta [2] > Especially when you want express the concept of equality as well and cannot use the obvious choice = anymore because you already used it for something else. Math also has the same problem, because equalities are not equal :) Hence you have: - equal - equal by definition - ~ has six different definitions depending on context - ≡ has two different definitions etc. > Exactly and that's why functions and procedures in Pascal are separate things, like it is meant to be. It's not "meant to be". Programming languages are not math. The distinction between functions and procedures in Pascal exists only because Wirth decided that's how it should be. > In some sense they can. It means that it makes no sense to pretend that nesting functions in Pascal has anything to do with math. > Pascal is a programming language, not math. Precisely. And yet, just two paragraphs above you argue for a distinction between functions and procedures because math ;) > My point is solely that Pascals syntax is superior to C's because (among other reasons) the former is closer to centuries old tried and tested and well established syntax of mathematical notation. Modern math notation didn't become "old tried and tested" until somethig like 19th century, and even now it still remains somewhat fluid. And it's only closer if you arbitrarily twist definitions and meanings like "equal by definition" is surely "variable assignment". As I said in the very first line of my original comment: "It's only 'mathematical' if you chose very specific parts of the language from a very specific version of Pascal when looked at at a very specific angle." It's also "better than C" only for some vague defintion of "better" where "is closer to math" has no relation to either reality or to being better. [1] https://en.wikipedia.org/wiki/Glossary_of_mathematical_symbols https://en.wikipedia.org/wiki/Glossary_of_mathematical_symbo... [2] https://math.stackexchange.com/questions/1289339/what-is-meant-by-the-delta-equivalent-sign https://math.stackexchange.com/questions/1289339/what-is-mea...
- badsectoracula 3y ago> numeric data types are 'integer' and 'real', no single/double nonsense Actually in Free Pascal (and AFAIK Delphi) there are Single and Double (and Extended) that map to 32bit and 64bit floats (Extended depends on the target CPU, e.g. for 32bit x86 is 80bit floats but for 64bit x86 is 64bit floats) since you actually do need to differentiate between the two in practice. > 'functions' are for returning values, 'procedures' for side effects FWIW even in Turbo Pascal (i don't remember which exact version) functions could also be used as procedures (the return value was ignored). While in theory separating the two sounds nice, in practice it is often useful to be able to ignore function results. > Array indexing is your choice. Start at 0? Start at 1? Start at 100? It's up to you. One additional neat bit is that you don't even have to use numbers, any ordinal type will work. Enums are ordinal types so you can do "type Foo = (Bar, Baz, Bad); FooArray = array [Foo] of Integer;" and then use "Bar, Baz, Bad" to access the array. You can use ranges too. > To switch between call-by-value and call-by-reference all you have to do is change your function/procedure signature. No changes at the call sites or inside the function/procedure body. Another bummer for me when I learned C. FWIW i prefer the C# approach of being explicit when you pass something as a reference since it makes it obvious on the call site just by reading the code. Beyond these i agree with your comment.
- weinzierl 3y agoWhen it comes to real vs float I should not have called the later nonsense. I agree that both have their place depending whether you want to express things at a lower (closer to hardware or wire protocol) level or more abstractly. It is still sad that languages like C (and even Rust) only offer the lower level types. What you said about functions and procedures is also true. I still think that it is valuable to have a distinction syntactically, even if they are relatively similar under the hood. Maybe one day we will have a Pascal compiler that can enforce that functions are side-effect free...
- badsectoracula 3y ago> Maybe one day we will have a Pascal compiler that can enforce that functions are side-effect free... Pure functions are actually one of the WIP functionality in Free Pascal :-). AFAIK the ultimate goal is to have the compiler evaluate them at compile time where possible.
- zelphirkalt 3y ago> Range Types! Love'em! You need a number between 0 and 360? You can easily express that in Pascal's type system. I did not know those existed that early. > Array indexing is your choice. Start at 0? Start at 1? Start at 100? It's up to you. Reminds me again of GNU Guile's arrays, which also allow you to specify what index an array starts with. Very flexible.
- skissane 3y ago> Reminds me again of GNU Guile's arrays, which also allow you to specify what index an array starts with. Very flexible. Reminds me of the "OPTION BASE" statement in BASIC. Found in Microsoft BASICs all the way from GW-BASIC (and probably even earlier than that) through to classic Visual Basic, VBA and VBScript (but not VB.NET). Not sure when it originated, possibly it goes all the way back to some version of the original Dartmouth BASIC (they changed the array base at some point from 1 to 0, so "OPTION BASE" enabled backward compatibility). Also found in some non-Microsoft BASICs, e.g. IBM System/34 BASIC. ANSI Full BASIC (did anyone ever implement it?) supported arbitrary array bases, not just 0 or 1, e.g. "DIM A(100 TO 200)"
- zzo38computer 3y ago> - '=' is for equality only - assignment is ':=' which is the next best symbol you can find in math for that purpose That is just syntax. I am not so sure if it is better or worse or not, but there it is. Different programming languages do have different syntax, and sometimes that can be helpful if their structure is different. However, what I think is that the syntax for types in C is confusing (when you are making types combining by e.g. function of array of integer, or whatever). > numeric data types are 'integer' and 'real', no single/double nonsense It is helpful to be able to specify how many bits you want. (In the case of integers, range types (as you also mention) might help, though.) > 'functions' are for returning values, 'procedures' for side effects It is useful in C to be able to have side effects and return values, and to be able to ignore return values sometimes. (BASIC doesn't have and that sometimes annoys me) > Function and procedure definitions can be nested. I can't tell you what shock it was for me to discover that's not a thing in C. In GNU C you can do that, although a function that refers to stuff in the function it is inside of is only valid before the outer function returns. (And, you are not allowed to declare the inner function as "static" to allow it to work even after it returns in case it does not access stuff that is only valid before the outer function returns.) > Array indexing is your choice. Start at 0? Start at 1? Start at 100? It's up to you. That is good, and it is useful. Usually I think starting at zero makes sense, but sometimes there is sense to start at any integer, including positive and negative numbers, so it is good to be able to specify any number.