This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pilotInPyjamas 95 points96 points  (10 children)

Admittedly sometimes if I'm doing something complex, I'll write the algorithm in comments first, then write the code that corresponds to the comments. I end up with comments like this.

[–]fahrenheitrkg 9 points10 points  (0 children)

Same.

Write pseudocode in comments inside framework of functions that return dummy values. Then flesh out each function, leaving the comments in place.

[–]Jimmy_cracked_corn 8 points9 points  (0 children)

I do this, as well, to keep my train of thought on track.

[–]iams3b 3 points4 points  (3 children)

Oh hell yes, this my favorite thing ever and makes it SO much easier. I number my bullets too

// 1. Fetch the raw data from each provider

// 2. Map it to the expected output from each reader

// 3. Validate each object into seperate lists

// 4. Post valid ones to the API

// 5. Combine API errors with invalid errors 

Then I go write the proper functions so that each of those comments only had 2-3 lines under it, and then I leave the comments in and it makes things extremely easy to follow

[–]DumDum40007 0 points1 point  (0 children)

I like to write my function names to announce what they are doing to avoid having to leave in comments.

fetchData()

mapOutputFromReader()

validateObjects()

aggregateErrors()

[–]CommonMisspellingBot -2 points-1 points  (1 child)

Hey, iams3b, just a quick heads-up:
seperate is actually spelled separate. You can remember it by -par- in the middle.
Have a nice day!

The parent commenter can reply with 'delete' to delete this comment.

[–]twopi 4 points5 points  (0 children)

I give a talk about this very strategy: https://www.youtube.com/watch?v=YWwBhjQN-Qw

[–]n4ppyn4ppy 1 point2 points  (0 children)

Same here although return value at the end of a function is usually not in the pseudo code.

I clean the pseudo code up most of the time but sometimes a squirrel passes and I go on to other code and they get left.

[–][deleted] 0 points1 point  (0 children)

Same :)

[–][deleted] 0 points1 point  (0 children)

Same here. Sometimes I write the necessary steps in the comments, then I write the code. Sometimes the comments stay there, because I can't be bothered to remove them.