in reply to Re: Data structures drive logic! (was Re3: Passing / evaluating / dieing on one line...)
in thread Passing / evaluating / dieing on one line...
If you don't like $_->(), then use &{$_} instead. *shrugs* Six of one, half-dozen of the other. The point is that people are too afraid of code-references. They're one of the many reasons why Perl is so powerful.
As for the fact that do_A and do_B could be expressions or blocks ... That is a straw man. If you're doing the same code over and over, it should be a function. Plain and simple. I'm going to be stubborn here, but "The Rule"(tm) should be "Use a function for a piece of code that appears twice unless you have a good reason otherwise". Hence, if you initialize $i three times, there should be a function to initialize $i. What if you want to change what happens there, such as printing a debugging statement every time $i is initialized to 1? If it's broken out to a function, that's easy. If it's not, then it's nigh-unto impossible.
The point is maintainability, not ease of initial coding. Perl is very good in terms of reducing development time. Part of that is the ability to test out possibilities through one-liners and throw-away scripts. The other is the capability to write extremely maintainable code, in ways that other languages don't allow.
Remember - development is about 40% writing new stuff and 60% changing stuff that's already there. (I might even be overestimating the former.) If you can't easily change it, it's not reducing your development time. End of story.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|