3 ms·
It’s different in Pascal l, iirc: in JavaScript with has dynamic scope in and affects every function you call inside the work statement; in Pascal, it has lexi
by fiddlerwoaroof 6y ago
It’s different in Pascal l, iirc: in JavaScript with has dynamic scope in and affects every function you call inside the work statement; in Pascal, it has lexical scope. I used it all the time in Delphi and don’t recall any real issues.
- kazinator 6y agoThe Pascal/Modula-2 WITH statement brings all of the members of a record into the lexical scope, without them being mentioned in the statement (i.e. implicitly). So when you add, remove or rename members of a record, you are potentially influencing the contents of scopes in other files all over the project. You can cause variable shadowing that way. VAR B : INTEGER; WITH ^P DO A := B; (* B is just a local, A is a field *) END If B is added as a field, the above suddenly means ^P.A = ^P.B. Any time you edit a Modula-2 record, you have to search the program for all the places where its type may be targeted by WITH. Probably if you stick to some rules, like never using WITH on another module's record type, you will be fine. Diagnostics related to shadowing could help.
- fiddlerwoaroof 6y agoI assume it’s statically checked, so you’ll get a compilation error?
- FpUser 6y agoIt is a habit. I use Delphi all the time even now as one of my currently active projects is written in it. I just do not use WITH.