4 ms·
> Begin End vs { } doesn't really bother me. but they don't really mean the same thing - {} defines a local scope, begin...end doesn't.
by zabzonk 3y ago
> Begin End vs { } doesn't really bother me.
but they don't really mean the same thing - {} defines a local scope, begin...end doesn't.
- deleted 3y ago[deleted]
- oaiey 3y agoDepends a lot on the language does not it?
- zabzonk 3y agowe are talking about pascal
- johannes1234321 3y agoAbout pas Al in comparison to languages using {} for blocks, where some have block scoping and some don't.
- zabzonk 3y agono idea what you are talking about here - what is "pas Al" - post an example of what you mean.
- saladdressing 3y agoPascal. It’s a typo.
- nurettin 3y agoyou are probably talking about C++ vs pascal. But you should be talking C.
- hnlmorg 3y agoThey are both used to define blocks. Eg Begin … End in for loops https://wiki.freepascal.org/For https://wiki.freepascal.org/For From what I recall, Pascal doesn’t support variables scoped within a specific block. But then neither do some languages with C-style curly braces too. So {} and Begin…End are pretty much the same thing. BASIC (and Visual Basic especially) often get a lot of criticism for their syntax but the End Thing style block terminator was very clear. It’s a pity that the only popular alternative to C-style braces is Python because I do think ALGOL-style syntax has a lot more going for it than people give it credit.
- zabzonk 3y agoi do not think you understand the concept of scope.
- ipcress_file 3y agoWould you explain it? I'm self taught, have programmed in Python, C, and am looking at Pascal, and I don't understand the difference.
- xupybd 3y agoPerhaps you're being a little short here? Explaining what you mean would go a long way to fostering good will.
- countrymile 3y agoMore of these replies on HN please!
- hnlmorg 3y agoI’ve written a few compilers in my time so I have some idea about scoping rules ;) As I and other have already said, it depends on the specific language. Some languages scope local variables at the function level (irrespective of {} or Begin End), and other languages scope local variables inside the containing {} or Begin and End block. In that regard {} and Begin End serve identical purposes of defining a local execution block and then it’s up to the language or dialect, or sometimes even the compiler authors, to decide upon the rules of variable scoping. What you’re doing here is conflating syntax grammar with deeper rules about a languages compiler or specification. To come back to your original point, Delphi does support variable scoping inside Begin End blocks. I don’t know if FreePascal also does but older dialects of Pascal didn’t because of the original intent of Pascal being a single pass compiler. Equally, not all languages that have C-like curly braces support variable scoping in the way you’re trying to describe. JavaScript originally didn’t and had to create a whole new keyword to add it (a little like what Delphi did, funny enough). My own shell scripting language very intentionally doesn’t support scoping despite having curly braces. As for inlining other contexts like functions, classes, etc, it has been a while since I’ve written any Pascal so I can’t recall the nesting rules here. But like with our discussion about variables, it’s more a question of whether the specification and/or compiler has support rather than a quirk of the Begin End grammar that forbids it — just as is the case with {} too.
- clouddrover 3y agoThey do: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Inline_Variable_Declaration https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Inli...
- beached_whale 3y agowithout that, one can use a repeat until loop to simulate I think