theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

CODE STANDARDS CHECKLIST (WIP) #399

Open benloh opened 2 years ago

benloh commented 2 years ago

Sri is codifying the past 7 years of our programming code style in one place so they can assign fancy numbers to them or something. Plus they keep seeing these issues pop up over and over, so this indicates that maybe they are not clearly stated.

GENERAL CONVERSIONS

BONUS: GENERAL CONVENTIONS

BONUS: STYLE CONVENTIONS LOOSELY KEPT

WIP: DATA AND COMMAND ABSTRACTIONS

A module or class API is a collection of methods that are designed to communicate its conceptual model of use. In object-oriented terms, I think of this as figuring out:

Knowing that, you can then design the API so the following is clear and consistent, and that its scope of responsibility continues to be clear:

This is all very abstract, so we need to come up with canonical STEP-related concepts and patterns that are already in use.

benloh commented 2 years ago

In GitLab by @daveseah on May 9, 2022, 14:23

comment from ben from slack re appcore to datacore connections (from a discussion on how a datacore API operates relative to something that uses it like an appcore)

I think there were three levels of constraints for datacore that are somewhat related:

benloh commented 2 years ago

In GitLab by @daveseah on May 9, 2022, 15:23

Another area: Typescript Conventions

We use a few prefixes in a general way that is from the typescript documentation but maybe not specific enough as we are with our variable and function naming.

There are some special cases:

Typescript Tricks worth noting:

benloh commented 2 years ago

In GitLab by @daveseah on Jun 8, 2022, 08:00

Yet another area: React Handler (and UI handlers in general)

An issue I see is that there is no distinction made between what is a user interface event handler (aka code that routes an Event object) versus application logic (code directly receives data to perform some application operation) versus gui logic (code that directly receives an event or data to change the state of the gui without changing any application data). These are three distinct operations, and our code should show this distinction.

EXAMPLE TO UNPACK (WIP)

Example below is the fragment of code to discuss

SlotEditor functional (not class!) component

<button type="button" onClick={SaveSlot}>
function SaveSlot(e) {
  WIZCORE.SaveSlotLineScript(e);
}

WIZCORE module

export function SaveSlotLineScript(e) {
  const {
    slots_linescript,
    script_tokens,
    sel_linenum
  } = STORE.State();
  const lineIdx = CHECK.OffsetLineNum(sel_linenum, 'sub'); // 1-based
  script_tokens.splice(lineIdx, 1, slots_linescript);
  STORE.SendState({ script_tokens });
}

quick notes:

  1. onClick prop is binding to another function definition and not explicitly passing the event. It's important to show that the event is being passed because this makes it clearer that it's a UI event handler. Better written as onClick={event=>SaveSlot(event)} even though it is more verbose. This also has the effect of (1) binding the containing variable scope to the arrow function explicitly, which is helpful in class components that are not using .bind() explicitly and (2) you can tack on additional parameters other than just event to reuse the same handler but with different parameters.

  2. function SaveSlot(e) is not doing very much other than redirecting to another call. It's not even unpacking data from the event (which is also unidentified). It's just code noise and it's passing UIEvent to WIZCORE directly to perform a data operation. This is conflating two concerns into one.

  3. export function SaveSlotLineScript(e) in WIZCORE doesn't even use the event that's passed (and it's still called e and untyped). It's performing a pure data operation based on internal state.

quick outline: