XP is just a number | |
PerlMonks |
Re: coding of algorithms is inherently proceduralby mstone (Deacon) |
on May 18, 2005 at 18:37 UTC ( [id://458381]=note: print w/replies, xml ) | Need Help?? |
What you're seeing is a trick of the light. There are infinitely many ways to express algorithms, some of which look nothing like structured code. You can implement any given algorithm with a network of logic gates, for instance, or a cellular automaton. They're both Turing-complete, but neither their definitions nor their operation look much like procedural/structured code. It's true that algorithms do support the concept of state, and with it, a primitive concept of time. Any statement that follows the general pattern: "do this, then use the results to do that," defines boundaries between the inputs and outputs of an operation, and establishes the basic idea that one thing needs to happen before another. Yes, that's 'procedural', but it isn't inherently 'structured' Writers explain algorithms with structured code because that happens to be what people are used to. Structured programming.. specifically the notion that all programs can be written with:
is the common denominator of every programming language made since the 1970s. It's surprisingly easy to convert structured code to OO code, though. An Object is bascially a Random Access Machine, which can be summarized as a block of addressed memory with a set of functions which operate on that memory. To refactor a piece of structural code as OO code, you start by turning all your variables into object attributes, and all your functions into object methods. At that point, you have compatible, if somewhat trivial, OO code. It won't necessarily be good OO code, but it will follow the OO paradigm. Basically, though, the fact that you're seeing structured code everywhere is a self-selecting convention. Writers use it because they assume it will be familar to any programmer trained in the last 30 years. If OO becomes the dominant mindset for programming (or FP, or some declarative style, or some formal-methods typesystem), the writers will shift over to a pidgin version of whatever is most popular.
In Section
Meditations
|
|