Hacker News new | ask | show | jobs
by brown-dragon 2845 days ago
One trick I've learned is to write out, (in a structured comment), what I am going to do an how I'm going to do it _before_ actually writing the code.

It seems redundant but it actually forces me to do a quick think-through of what's happening. Plus distractions get a lot easier to handle: I just need to read what I've written down to reload the context.

Paradoxically, I've found that this method of typing out _more stuff_ actually helps me finish much faster.

1 comments

I second this. Over time and struggling with concentration in bullshit jobs, I've learned following tricks when I feel stuck and/or stressed out:

- I have an org-mode document with a TODO list and project notes always open. Whenever I'm stuck, I'll start decomposing the task into smaller and smaller TODO items, simultaneously with doing a written brainstorm. Sometimes I'll write out a hundred lines of text, but it does help me get unstuck.

- Similar to what you mention, I frequently write a TODO list in comment as a scaffolding in the file I work on, and I then proceed to fill the space between TODO items with appropriate code.

Yep - that's exactly been my experience.

(off-topic) Org mode is really amazing. I've transitioned almost completely from Emacs to Vim over the last few years but I still have Emacs on my dock only because of `org-mode`. I've tried substitutes in vim but nothing really works.

(back on topic) Another advantage of writing comments is coming back to the code becomes so much easier. I can re-read the comments and understand what's going on much faster.

To do this properly I've developed a simple system of 'categories' that allow me to structure the comments properly. I think they works really well. For anyone curious - here's an example in my last weekend project: https://github.com/theproductiveprogrammer/luminate

Check out the comments in the code (`main.js`). I think they make the code much easier to understand and maintain. It's almost an alternative to TDD - Comment Driven Design (CDD!)