Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: coding of algorithms is inherently procedural

by mstone (Deacon)
on May 18, 2005 at 18:37 UTC ( [id://458381]=note: print w/replies, xml ) Need Help??


in reply to coding of algorithms is inherently procedural

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:

  • nested functions with a single entry point and well-defined exit points
  • while() statements with some simple variants (for() loops, next, last, and redo modifiers, continue blocks and so on)
  • and if-then-else statements

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.

  • Comment on Re: coding of algorithms is inherently procedural

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://458381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-16 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found