DEV Community

Roman Sorin
Roman Sorin

Posted on

How do you like to read articles/tutorials?

When reading documentation or articles that contain code, do your prefer to:

  1. step through the file line-by-line
  2. see the full code snippet pasted with inlined comments
  3. see the full snippet, and a summary/walk-through after?

Here's an example of #2/3 taken from a recent post of mine:

import hashids from "hashids";

// Two arguments supplied: a salt and a minimum padding (length)
const postHash = new hashids("post", 8);

const post = { id: 4 };
post.id; // 4

const hashedPostId = postHash.encode(post.id);
hashedPostId; // 6akz1JVq
postHash.decode(hashedPostId); // [4]
Enter fullscreen mode Exit fullscreen mode

"Here, we're importing the hashids package and creating an instance of the module, calling it postHash. ..."

vs. doing something like:

const postHash = new hashids("post", 8);
Enter fullscreen mode Exit fullscreen mode

"First, we create an instance of the hashids module and supply a salt and padding. ..."

Top comments (0)