5 ms·
Yes the only "weird" thing in pascal was pointers and pointer dereferencing with the caret ^ I loved pascal syntax.
by froh 5y ago
Yes the only "weird" thing in pascal was pointers and pointer dereferencing with the caret ^
I loved pascal syntax.
- jacquesm 5y agoYes, C got that bit right. -> made a lot more sense.
- pyjarrett 5y agoIn Ada (Pascal derivative), there's implicit dereference so we just use it like normal, `A.B`.
- renox 5y agoWhich has pros and cons: a pointer indirection can be expensive so the potential additional cost is hidden and pointers semantic is so different than hiding their usage is a bit risky.. That said this simplify refactoring and is much less 'noisy' to read. My preference is Pascal style but with an @ instead of a ^ which feels a bit weird.
- badsectoracula 5y agoThe caret is because ↑ (arrow up, in case HN drops it) wasn't really "typeable" (or even available) in most computers. I'm not sure if Wirth's Pascal even had the caret - i do have an old book about Pascal which uses the arrow for pointers, but i remember seeing the caret in various dialects. IMO Pascal actually has much better pointer syntax than C, even with the caret (which is basically a pointer/arrow up without the tail): 1. Pointer de-referencing is done via something that looks like a pointer and doesn't reuse some math operator (despite writing C for more than two decades i still pause for a bit whenever i want to multiply a pointer to a number) 2. Getting the address of something is via the "at" character @ (which kinda makes sense as a pointer to something is a way to refer "at" it), no way to mix the two 3. No special syntax for referencing a member of a record (struct) through a pointer, all record members are referenced using a dot ".", all pointers are de-referenced through the caret "^" so of course all members to a record pointer is done through using both of them: "^." Also i think that the reason C has -> is because in C pointer de-reference is a prefix whereas in Pascal is a suffix so without it you'd either have to write (*ptr).foo. Pascal avoids that by having both be suffix operators.
- layer8 5y agoASCII actually had up-arrow instead of caret before 1967/1968, although that was slightly before the birth of Pascal (published in 1970).
- jecel 5y agoYes, the preliminary (1963) ASCII had an up arrow instead of the caret and a left arrow instead of the underline. DEC, Xerox and others built equipment around the 1963 draft and failed to change when the final version of ASCII came out. That is why when Pascal and Smalltalk came along later they used the "wrong" characters. In the case of Smalltalk, it was Digitalk's "Methods" (the precursor of Smalltalk/V) that adopted := for assignment in place of the left arrow (though the IBM PC character set actually had one, just not with the same code as ASCII 1963) since all of its tutorials were aimed at Pascal programmers.
- jacquesm 5y agoHey there Jecel, how are you doing? Any progress on your super interesting projects?
- RicardoLuis0 5y ago> Also i think that the reason C has -> is because in C pointer de-reference is a prefix whereas in Pascal is a suffix so without it you'd either have to write (*ptr).foo. Pascal avoids that by having both be suffix operators. That distinction comes from early C (pre-ANSI / K & R C), where structures were really definitions of offsets (and said offsets were global, you couldn't have different 'offsets' for a member with the same name in different structs). Say you had a struct 'struct mystruct {int a;int b;int c};': You could do '200.b' to access the value at the 'b' offset of the memory location '200' ( '*(int*)( 200 + offsetof(struct mystruct,b) )' or '((struct mystruct*)200)->b' ) And '200->b' would access offset 'b' of the memory pointed to by memory location '200' ( '*(int*)( *(intptr_t*)200 + offsetof(struct mystruct,b) )' or '(*(struct mystruct**)200)->b' )
- donio 5y agoprocedure vs function is weird too. And the period required at the end of the program. I remember learning Pascal and C around the same time coming from BASIC and assembly and Pascal didn't seem particularly easier only more verbose. New concepts like types and pointers were much more of a hurdle than syntax.
- jacquesm 5y agoProcedure: something that has only side effects. Function: something that may have side effects but that also returns a value. Pure Function: something that only returns a value, and has no side effects. That's how I always understood the terms.
- wott 5y ago> Yes the only "weird" thing in pascal I guess you forgot about the semicolons which must or must not be there depending on location. And the final dot. And, if we move a bit away from pure syntax, strings, even modern ones, which start at 1 for backward compatibility reasons with the original very limited Pascal strings, while dynamic array start at 0 (and original limited pascal arrays start wherever you like).
- Tozen 5y agoSemicolons are separators in Pascal, not terminators like in C/C++. The context of usage is different. The final dot is clarifying the end of the program or unit. It also makes a more clear distinction between the main body or subroutine of the program versus other functions and procedures that are only component parts. I don't think people are saying that Pascal is a perfect language, as none are, but rather it's an easier to understand and read language. Many teachers would agree with that assessment.