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 reply to Re: coding of algorithms is inherently procedural by mstone
in thread coding of algorithms is inherently procedural by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.