Forgot your password?
typodupeerror
Programming

Sloppy's Journal: I can't believe this happened. I miss .. Pascal?! 1

Journal by Sloppy

I was writing a function in PHP4 and it kept getting bigger. It could use some splitting up for readability/testing/debugging purposes, although it didn't really need that to work. But then I realized I needed to reuse some sections of code, and since I hate duplicating code, those parts needed to be pulled out into their own functions.

But they needed access to the working set of local variables of the big function. Oh great.. do I pass all those vars by reference, making the argument list really long? Do I move all those variables into a struct (well, an associative array) and pass that?

These are, like, Programming 101 issues. Experienced programmers don't normally have to think about this stuff, because the right thing to do is just .. obvious.

Then I remembered that Pascal has the unusual (and rarely(*) needed) feature of nested procedures, where the sub-procedures can directly access the outer scope's local variables. It dawned on me: that would be incredibly convenient (and readable) in this case.

I wussed out and put everything into a class. It's not really oop (all this class does, is return a result) but that looked like the best way to deal, except now I have an ugly this-> in front of everything.

(*) I haven't programmed in Pascal (or anything like it) in over 20 years. Never really missed that feature until today.

This discussion has been archived. No new comments can be posted.

I can't believe this happened. I miss .. Pascal?!

Comments Filter:
  • Hey, Pascal is my native programming language. I don't think nested procedures are rare. I've used them often, and have seen them in production code.

As the trials of life continue to take their toll, remember that there is always a future in Computer Maintenance. -- National Lampoon, "Deteriorata"

Working...