Skip to content

Does Lisp Influence Your C++?

ADMIN | 26-07-2013

That article had a lot of good ideas, but I feel like it kind of missed the point regarding Lisp/Scheme/Functional Programming.

Hexagon pattern 1

The idea for this post started on Aug 11, 2011, when I read Gregg’s post about choosing a scripting language for 3DScript, the CGM interactive test bed.  That article had a lot of good ideas, but I feel like it kind of missed the point regarding Lisp/Scheme/Functional Programming.  He used a do loop to try to make the point that the syntax is rather goofy.   The reason scheme came up at all is that it is used as a scripting language for acis3dt.exe our 3D ACIS Modeler Test application.

I actually agree that the syntax for a do loop is goofy.  However, learning about Lisp (and the lispy features of perl, see http://hop.perl.plover.com/) has made me a much better programmer than I would otherwise be.  In some ways, this thesis is older than the hills. To illustrate this, Google various subjects surrounding Lisp, Functional Programming, etc., for example, map-reduce.  When I talk with other programmers, I get the feeling that the message bears repeating.

So please bear with me while I sketch a few specifics.  Also, feel free to add your own in the comments:

  • Referential transparency makes things a lot easier to reason about.  Put another way: it is much easier to deal with C/C++ code that doesn’t modify global and static variables.
  • The best way to speed up code is to get a smarter algorithm. 

- Writing programs as compositions of simple (but high order functions), makes it much easier to reason about them:
- There are a few functional programming clichés that often help in dramatically speeding things up
                         - Memoization
                         - Make the algorithm lazy

  • Mathematical proofs are very easily given in terms of induction/recursion

- The literature on Lisp has lots of discussion about how you can convert between recursion and iteration.

  • Thinking about classes in terms of closures is helpful to me.


A common anti-pattern in legacy code is monolithic and large functions which give a detailed to do list.  Typically, I end up extracting functions from the huge monster, turning them into classes, and then parameterizing their behavior.  This is really almost the same thing as taking a code snippet, making a closure over the variables you need to encapsulate, etc.

C/C++  still tends to be ubiquitous because:
(a) So many system libraries are written in C or C++
(b) Well written C++ can be very fast

However, C-style languages don’t lend themselves to simple and concise reasoning about code.  If there were a well-established Lisp with a good linker, it might eat C’s lunch.

Here's a cartoon on the subject http://imgs.xkcd.com/comics/lisp.jpg

What do you think?

You might also like...

5 Min read
3D Modeling
What is digital manufacturing? Here’s a simple digital manufacturing definition: the process of using computer systems...
5 Min read
CGM Modeler
Software components are like the stage crew at a big concert performance: the audience doesn’t see them, but their...
Application Lifecycle Management Flow
4 Min read
CGM Modeler
When you hear the term, Application Lifecycle Management (ALM), you likely think about the process that a software...
9 Min read
CGM Modeler
SLS in Additive Manufacturing is used to convert 3D CAD designs into physical parts, in a matter of hours.
8 Min read
CGM Modeler
There’s a lot of confusion around what the terms additive manufacturing and 3D printing mean.
4 Min read
3D Modeling
Additive manufacturing, often referred to as 3D printing, is a computer-controlled process for creating 3D objects.
5 Min read
CGM Modeler
Computational Fluid Dynamics (CFD) is a type of analysis that provides insight into solving complex problems, and...
2 Min read
CGM Modeler
WRL files are an extension of the Virtual Reality Modeling Language (VRML) format . VRML file types enable browser...
Voxel model example
3 Min read
CGM Modeler
Voxels are to 3D what pixels are to 2D. Firstly -- let’s examine what pixels actually are. Everything you see on your...
Point_cloud_torus
2 Min read
CGM Modeler
Point-cloud modeling is typically used in the process of 3D scanning objects. Rather than defining surfaces through...
Polygonal Modeling
2 Min read
CGM Modeler
Polygonal (or polyhedral) modeling is the most common type of modeling for video games and animation studios. This type...
aerodynamics-CFD
9 Min read
CGM Modeler
Computational fluid dynamics (CFD) is a science that uses data structures to solve issues of fluid flow -- like...
BREP Model example
2 Min read
CGM Modeler
BRep modeling, or Boundary Representation modeling, is, in CAD applications, the most common type of modeling. BRep is...
Feature Recognition Zoomed
5 Min read
CGM Modeler
IN THIS ARTICLE: What is FEA (Finite Element Analysis) Principles of Finite Element Analysis and Simulation Software A...
3YourMind and Spatial
3 Min read
3D Modeling
As manufacturers begin to rely more and more on additive manufacturing (AM), moving from a few select piece parts that...
Voxeldance and Spatial
2 Min read
3D InterOp
To the uninitiated, 3D printing may seem a simple process — download your CAD file and hit print. But the world of...
BIM_word_cloud_web
2 Min read
3D Modeling
The construction industry has long taken advantage of prebuilt components, from prehung doors to prefabbed roof...
Clash-Detection-fig-1
4 Min read
3D Modeling
A major benefit of constructing a building virtually is the cost savings gained by identifying errors in the design...