stan-dev / stan-dev/docs

refactoring chapter for User's Guide

Open
#396 0 comments 1 reaction 4 assignees View on GitHub

@WardBrian is already working on this.

Since Sep 8, 2021.

enhancement
Dominant language
TeX
Stars
43
Forks
133
Avg merge
11h 32m
Merged PRs (30d)
4

Description

Summary:

Add a chapter to the Stan User's Guide on refactoring programs for clarity.

Description:

We essentially want to port the non-OO parts of Martin Fowler's book, Refactoring. It's Java-based, but it gives the flavor. Sometimes, there's also an efficiency boost, but we don't want anything about efficiency to only be in the refactoring chapter given that there's an efficiency chapter.

We could also extend this to patterns and anti-patterns, though most of the guide is already about patterns.

Additional Information:

List of refactoring to add.

  • collapse nested conditionals
if (a) {
  s;
} else {
  if (b) {
    t;
  } else {
    u;
  }
}

should be

if (a) {
  s;
} else if (b) {
  t;
} else if (c) {
  u;
}
  • early return
real x;
if (a) {
  // some computation
  x = y1;
} else {
  // some computation
  x = y2;
}
return x;

should be

if (a) {
  // some computation
  return y1;
} else {
  // some computation
  return y2;
}

or if there is no computation

return a ? y1 : y2;

There are a lot more of these we can add, but I just wanted to provide some flavor for the issue. A PR can address this in only a few cases and we can merge it and then add to it as we go.

Current Version:

v2.18.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.