Code musing

| 1 Comment

Interesting framing by Carl Masak:

Code generation and stone soup

Every type of control flow in programming languages is just convenient sugar for if statements and while loops.

ifs and whiles are the stone soup to which all the rest of our control flow can be added as seasoning. ifs let you conditionally skip ahead in code, and whiles allow you to conditionally skip back. That's all you need.

Hadn't quite heard it put it like that before.

I'm as likely as not to try and turn a given task into an operation on lists -- filter with grep, process with map, repeat and fade.

I guess if you could squint you could look at map as a flavor of while and grep as your if.

1 Comment

Us coders who still work in assembly language (and occasionally discrete logic) will be happy to point out that "while" is just an "if" and a "goto".

Of course since Perl lacks a native switch (yes, I know about "use Switch", I think he's wrong about switch being syntactic sugar for "if/else", because I've implemented switch in Perl using a hash and code references. Which, to my mind, is closer to how to think of "switch" than "if/elsif/else".


About this Entry

This page contains a single entry by Steve Bogart published on January 23, 2010 12:19 AM.

On not wasting opportunities was the previous entry in this blog.

Amazon v. Macmillan is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.