Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Saturday, February 9, 2008

80% Now or 100% Later

Given a choice, should you take the 80% solution you can do now or the 100% solution you have to wait for?

The bottom line here is, clearly, available time and effort. Assuming you have the resources to make either happen, it comes down to which one can you get done prior to any relevant deadlines and whether or not the difference in time and effort will impact negatively other projects (recall the 80/20 Rule).

The awful truth is we don't always get to do the best thing every time nor can we always put out our best effort on what we do. A simple example is this: you have two projects to get done, A and B. Project A is due in a week, Project B is due in 10 days (calendar days and weeks, not business days and weeks). Project A needs a week's worth to do really well, but three days to be a satisfactory result. Project B has the same setup. Late is very bad (like you don't get paid, lose a contract, or fail a class). What do you do?

I'd plan for eight days days of work (four days in on each) and have an extra "emergency" day for each and live with a better than minimal but less than optimal result on both. Should I get more done than I thought, that's great (but not likely). On the other hand, I have two days to help get all the requirements met to at least a satisfactory level.

How does this relate? 80% now versus 100% later is all about priorities and bottom lines. In the above case the point is get the job done, not get it done perfectly. It says, in short, take what you can get and move on to the next priority item. It is, in short, slash and burn project planning.

Sometimes its more important to get the job done than getting it done well.

Saturday, February 2, 2008

LaTeX in a WYSIWYG World

Most of the non-mathematically-inclined people I know don't use LaTeX and probably never would even if paid. I've even had people say with the advent of point-and-click formula editors for MS Word, there's no point in bothering with it anymore anyway.

Yet I can't shake the sneaking suspicion LaTeX is still better. Maybe it's just elitism from knowing a system most would find esoteric at best and downright weird at worst (outside of mathematics and related fields, of course).

But I still snicker at the thought of sending my humanities profs .tex files when asking them to review a draft of a paper, or using beamer to give a presentation.

Sunday, December 9, 2007

Things I've Noticed About My Code

I'm not a professional coder nor even a talented amateur--strictly a weekender. The day I hack the Linux kernel is the day pigs fly. Nonetheless watching myself evolve as a programmer must be something like a caterpillar watching itself turn into a moth. Hopefully I'm getting better.

Some things I've noticed:
  • Whitespace has become something I'm almost religious about.
  • Same for indentation. (Is there a difference?)
  • The more I code the smaller each discrete piece becomes, even to the point of being only a few lines.
  • I've started writing bits of code I know I'll use over and over again (or don't want to keep coding out each time I need) as stand-alone functions/procedures to be called as needed.
  • I've now officially reused code from another of my projects.
  • Comments have become much more frequent and structured. If there's anything even vaguely cryptic it comes with a comment. Significant blocks of code come with comments.
  • I tag the start and end loops and conditionals with numbered comments to help me keep track of them (this is in addition to whitespace and indentation).
  • I version my software, but I'm not yet to the point of using a versioning system like svn.
I have to wonder if others notice these same types of things in themselves.

Most of this has come about because of my couple of somewhat coding intensive research projects. Two summers ago I wrote a couple thousand lines of SAS code to process a dataset and over the last 7 months I've written a few hundred lines to do some computational geometry and statistics in R. Just looking back at my own code has taught me how annoying poorly written code can be.

Wednesday, November 28, 2007

Coding Irony

I went through the part of the code which was most suspect vis-a-vis the errors I was getting and found the flaw: a typo. The irony of this situation is not to be underestimated. Insofar as I can tell, all the algorithmic stuff is right, and in fact everything else is right, but this little tiny thing in wrong.

I'm just hoping it doesn't unveil some larger flaw lurking in the shadows, obscured by the heinous nature of what I found.

Sunday, November 25, 2007

My Little Coding Nightmare Revisited

It's even worse than I thought initially. It turns out that the error is systematic and not sporadic (as I should have immediately guessed from its repeatability). It turns out that there is always a sort of inflation of the values of the sum of squared differences coming from somewhere.

This means that while the script looks like it is working great and doing what it should, it is completely bunk and will need to somehow be fixed to avoid this issue. I am thinking about trying to put a series of commands in to reset the values of different variables to zero in hopes of clearing out whatever error is compounding on me.

The next option if that fails it to post the relevant files to the R mailing list and hope someone is kind enough to tell me where I went wrong . . . which I somehow doubt.

Tuesday, November 20, 2007

Coding Nightmares

My coding nightmare tonight has been discovering an error in the way a piece of code executes I can't duplicate outside it's native environment, but I can repeat natively.

Here I am, working on an R script to do some (rather elementary) computational geometry and I want it to compute $(a-c)^2 + (b-d)^2$ (to use the TeX notation) where $a,b,c,d \in \[-2,2\]$. A little examination shows that the sum should always be less than or equal to 16. I was getting 16.8. Not good.

The problem is that while I can duplicate this kind of MAJOR error when computing this number as part of the script, I can't get it by starting R up cleanly and manually imputing one example. Then it works fine. I have to wonder what in the world is going on.

The worst part is most likely the solution is simple and would be obvious to a professional programmer but to me, an amateur, is far from it.

Grrrr . . .