The Word for World is Forest, Ursula K. Le Guin

What a wonderful, thought-provoking book. And depressing, since we immediately recognize the ‘yumen’ behavior. Even today, all the problems I see around us can be traced back to stubborn, monomaniacal extremists who have such deep faith in their beliefs that they cannot admit other perspectives. 

Great comparison with Mindset and WEIRD people (to be linked later).

Follow by Email
Facebook
Twitter
LinkedIn

Fractals

It is surprisingly easy to generate a fractal image. A schematic of the Mandelbrot Set is as follows. Start with the equation $z_{n+1} = z_n^2 + c$, where $c$ is a complex number. Your “image” is a 2d array whose rows and columns correspond to the real and imaginary parts of $c$. Set $z_0 = 0$ and repeatedly apply the equation. If the value converges in a set number of iterations, set the corresponding entry in your array to 1, else 0.

Input

Array/figure size in pixels

Output

Bitmapped image, running time

Variants

Color the pixel by the number of iterations it took to converge. Try variants of the equation (see Julia sets). And note that the computation of each pixel is independent of every other: we can parallelize this! We visit this in another post. There are many ways to optimize the sequential implementation — try these out!

Report

Show us what you learnt!

Follow by Email
Facebook
Twitter
LinkedIn

Walt Whitman’s America: A Cultural Biography, David S. Reynolds

I’ve been struggling with Whitman for a long, long time. There are a few lines that capture the imagination, starting with some of the titles: “Leaves of Grass,” “Song of Myself” and “I Sing the Body Electric,” but when I read the poems themselves, I was left scratching my head. I’m fine with prose poetry, but many times I have no idea what he is referring to, or what he’s trying to say. And the most outrageous meaning seems … silly? implausible? 

An aside: it’s only through this book that I realized ‘O Captain!’, that darling of school elocution competitions, is by Whitman. And Rupali pointed me to “There Was a Child Went Forth Every Day,” which is pretty clear in its message.

So. My goal in reading this book was to get a context for what Whitman’s message is, to hopefully understand what his poetry is about (and what the fuss is all about!) and to revisit LoG. It delivered, on this and more.

It turns out that Whitman was quite the marketer! I wonder how much of his current stature is due to his poetry and how much is due to his self-promotion. It looks like even before the first edition, his goal was to be recognized as the voice of America. Unfortunately, the success that each edition garnered was overshadowed by the lofty goals that Whitman had set, so of course, he was bitterly disappointed till the end.

It also turns out that a lot of the lines that I puzzled over are actually as explicit as I had thought 🙂

Outside Whitman, American culture and politics in the mid-nineteenth century was pretty bad (anyone for ‘Gangs of New York’?). Corruption was rife, and it seems like Lincoln was the only decent President that the USA had in that period. In this context, the Trump presidency is more of a reversion to the mean, rather than the outlier that everyone hoped it was. Another recent read, Fortune’s Children, covers roughly the same period, and the contrast between how Whitman and his family lived at the same time but in completely different worlds as the extremely wealthy NYC society is shocking.

A final observation: homosexuality was relatively tolerated, but describing heterosexual encounters was not. It’s interesting how norms change over short time spans – by the 1930s homosexuality was being persecuted. I’m currently also reading a book about WEIRD people, and it’s interesting to think about how these changes may have come about.

Okay, it’s time to take another crack at Leaves of Grass

Follow by Email
Facebook
Twitter
LinkedIn

Searching

Input

Array size, data type, search algorithm, key. The key can specified as an index or as a non-existent value

Output

index, if key is in the array, -1 otherwise. Running time

Program

  1. Generate the array of the given data type and size. Populate with random numbers in sorted order (duh!)
  2. Implement the usual suspects:
    1. Linear search
    2. Binary search
    3. Exponential search
  3. Implement different optimizations for each of these
  4. Test that the search is correct

Run 

your implementation. There can be many variations in here, based on where the key is. Compare the performance of different searches for keys at the beginning, middle and end of the array. What do you think is the best-, average- and worst-case situation for each search? Do the performance results match your intuition? There are different ways of analyzing the performance, such as time v. array size for different key locations, or time v. key location for different array sizes, or …. What do you choose?

Report

your findings! Can you correlate these to the theoretical analysis and the architecture of your platform?

Follow by Email
Facebook
Twitter
LinkedIn

Sorting

This is so fundamental that you’re probably wondering why I even bother to put it here. Read on…

Input

Array size, data type, algorithm, sort order

Output

Running time of different parts of the code

Program

  1. Create an array of the given data type and size, and populate it with random values
  2. Implement multiple sorting routines:
    1. InsertionSort
    2. MergeSort
    3. QuickSort
    4. ShellSort
    5. CountingSort
  3. Implement different optimizations for these
  4. Test that the final array is sorted

Run

your implementation with different array sizes. Your program should report the time to generate the array, sort it and test that it has been sorted correctly.

Write a wrapper script that captures the above running times and generates a plot that shows the comparative performance of different sorting routines: the x-axis is the array size and the y-axis is the time. You should have multiple versions of the above sorts with different implementations.

What do you expect the graph to look like? Can you explain the shape of what you actually get? 

Should you combine different sorting approaches? What would you expect, and how would you do this?

What factors impact the performance that you observe?

Report

Compile your experiments and describe your findings. What conclusions do you draw from this? What do you hypothesize, and how did you test your hypotheses?

 

Follow by Email
Facebook
Twitter
LinkedIn

Command-Line and Options

Your programs should be parameterized and should take inputs at the command line (not prompt the user for inputs!)

The command line can be used to control the behavior of the program:

  • Specify the sort order
  • Specify the algorithm
  • Provide debug/progress information
  • Specify output formats and destination

To specify inputs:

  • From a file v. generate internally
  • Provide the search key if searching

This helps when you want to benchmark or generate performance data – easy to put into a script and push the button.

Figure out once how to process command-line options, and you can just use this for all your programs. Most languages have existing libraries or packages that do pretty sophisticated parsing and fancy stuff like how you specify flags and options. Experiment with these!

Follow by Email
Facebook
Twitter
LinkedIn

Edsger W. Dijkstra: a Commemoration, Krzysztof R. Apt and Tony Hoare, eds

Memories of many men about EWD. He’s well known, of course, for his eponymous algorithm (and was worried that that is all he will be remembered for!), but was so much more. There are many threads that I want to follow up on, and a few things that jumped out at me

  • The importance of writing well. 
  • The Tuesday Afternoon Club
  • All references in this paper start with 0
  • He didn’t use a computer (he was gifted one but just kept it in his bookshelf)!
Follow by Email
Facebook
Twitter
LinkedIn

Focus on Performance

Colleges don’t talk about program performance; I find this strange since they focus so much on student performance!

Develop the habit of instrumenting your code by default — figure out the correct timer to use for your platform, and measure, measure, measure. Understand the interplay between the code you write, what the compiler does to it, and how it runs on the CPU. 

Investigate the tools available on your platform, and experiment with these. You will learn a lot from this than you can ever imagine!

Follow by Email
Facebook
Twitter
LinkedIn

Debug & Test

Learn how to debug your code. This is not just about the tools (research and get familiar with the appropriate tools for your language and platform) but also about writing code that is easy to debug and your mental model for how you approach debugging. 

Think about how you can test the code that you’ve written — both at the micro-level and for the entire application. Get into the habit of writing your own test cases, or rather, generating your test cases. Can you be comprehensive? (why not?) What are the corner cases? Each time you make a change / add a feature / fix a bug, ensure that your code passes all the tests you have defined. 

Learn how to talk about your implementation: the choices you made for the data structures and algorithms and why you chose this instead of that. And remember:

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Brian Kernighan

Follow by Email
Facebook
Twitter
LinkedIn

Version Control

git is the flavor of the day; so learn how to git. Force yourself to use the command line, this will help you understand the philosophy of version control in general, and git in particular.

Create a github account and start using it. Use it to showcase your improving maturity as a programmer and developer, and use it to showcase your projects. 

Pro Git, Chacon and Straub is a fantastic tutorial and reference, and is available online

Follow by Email
Facebook
Twitter
LinkedIn

Editors

Learn how to use a good editor.

I’m not going to get into a religious war here, so will not make any recommendations. However, once you’re touch-typing, you should be making changes to your code in terms of your thoughts, not in terms of your editor’s commands. Choose an editor that makes sense, and choose one that is built for editing code. You will see your efficiency sky-rocket. 

Follow by Email
Facebook
Twitter
LinkedIn

Touch Typing

The one, simple thing you can do to increase your productivity more than 10-fold is to learn how to touch type. 

This isn’t just about improving your performance at the keyboard. It has to do with removing distractions and obstacles when coding. It’s about becoming one with the machine, translating the thoughts in your head into code, without having to hunt around for the right key and pressing it one at a time. Your brain works much faster than you can express your thoughts, and anything you can do to bridge that gap improves your performance. 

And this has a multiplier effect as you learn how to use a good editor.

 

Follow by Email
Facebook
Twitter
LinkedIn

The Developers Bookshelf

Algorithms & Data Structures

I’ve found multiple perspectives deepens my understanding of topics. The following books cover roughly the same ground, but have very different approaches, and I’ve gotten different insights from each of them

  • Introduction to Algorithms, Cormen, Leiserson, Rivest and Stein. The basics, written clearly and yet with rigor, this book should be the one to start with on most topics. Read it for self-study or as a reference.
  • Algorithm Design, Kleinberg and Tardos. A much more detailed look than CLRS, and the systematic exposition is a joy to read. There are a crazy number of exercises as well!
  • Algorithms, Dasgupta, Papadimitriou and Vazirani. Much less detailed than the first two, but a very different approach to many topics. 
  • Algorithms, 4th Ed., Sedgewick and Wayne. Many fewer topics covered, but in a lot more depth. Especially see how to analyze and test implementations. Great exercises and see the associated booksite as well.

And of course, no list of Algorithms books can be complete without

  • The Art of Computer Programming, vols. 1-n, Knuth. This is advanced, and not for the faint of heart. Also, the best categorization of sorting algorithms that I’ve seen. And demonstrates the limits of analysis (by which I mean it demonstrates how much analysis you can do!). 

Programming Praxis

More than syntax, programming is about the mindset. Here are a few books that help in this area:

  • Programming Pearls, Bentley. Yes, it’s old. Yes, it’s worth every bit.
  • Beautiful Code, Oram & Wilson. Bringing art into engineering
  • The Pragmatic Programmer: From Journeyman to Master, Hunt & Thomas

Others

  • Hackers and Painters: Big Ideas from the Computer Age, Paul Graham
  • Turing’s Cathedral: The Origins of the Digital Universe, George Dyson. A bit of history. 
  • Anything and everything by Simon Singh
  • “Surely You’re Joking, Mr. Feynman”, Richard Feynman

Language-Specific Books

C++

  • The C++ Programming Language, Stroustrup
  • Accelerated C++, Koenig & Moo
  • Modern C++ Design, Alexandrescu

Python

There are too many (very) good options, but I’m going to stick with just one:

  • Python Data Science Handbook, Jake VanderPlas

Design

  •  Design Patterns: Elements of Reusable Object-Oriented Software, Gamma, Helm, Johnson, Vlissides
  • Head First Design Patterns, Freeman & Robson

Fiction

  • The Hitchhiker’s Guide to the Galaxy, Douglas Adams. Everyone should know the answer to the ultimate question
  • The Discworld novels, Terry Pratchett
Follow by Email
Facebook
Twitter
LinkedIn

Round Ireland with a Fridge, Tony Hawks

A cheerful account of a pointless trip that brought to mind something that Jerome K. Jerome would write. I kept reading the dialogues in Derry Girls accents. And there are gems like these:

‘Yes’, I replied accurately.

Follow by Email
Facebook
Twitter
LinkedIn

Programming for the Programmer

Motivation

Students aspiring to program come in all varieties. Some are good, some are not so good and this categorization is strictly within the same pool.

The frustrating part (for me) is that the good programmers have a long way to go to become competent developers. And the not-so-good programmers are not so good for no fault of their own. I find that the assignments that they do, either in college or elsewhere are unambitious and are too focused on specific concepts.

Many students seem to think sites such as leetcode are all that is required. I beg to differ – these are fine for preparing for interviews, but not for  becoming good developers.

Here’s a series of assignments that will take you beyond your current capabilities will teach you more about algorithms and data structures than you currently know, help you learn how to use the right tools, techniques, and skills, and get you started on building your portfolio of work.

The first group doesn’t even ask you to write any code:

The next group is focused on the basics:

  • Sort
  • Search
  • Fractals
  • Command line / options

And a few complicated ones:

  • Shell
  • Bellman-Ford
  • Matrix multiplication
  • Random walks

And the skills needed for tomorrow today:

  • Shared-memory multiprocessing
  • Distributed-memory multiprocessing
  • Map-reduce
Follow by Email
Facebook
Twitter
LinkedIn
Search

  • Search

  • Categories

  • Post Date