Skip to content

Instantly share code, notes, and snippets.

@frank-dspeed
Last active August 25, 2022 04:15
Show Gist options
  • Save frank-dspeed/0b5f909ecb1943eb2283c2ac2d54ae66 to your computer and use it in GitHub Desktop.
Save frank-dspeed/0b5f909ecb1943eb2283c2ac2d54ae66 to your computer and use it in GitHub Desktop.
Self Explaining Code Patterns for ECMAScript maybe later TypeChecking. Typescript

SelfExplaining ECMAScript Javascript

I am at Present Researching Patterns to make code more self Descriptiv and Maybe Runtime Checkable My Personal Succeesor Over Typescript & Flow at Present used in Stealify to allow IDL Expression

So we use it to supply Intend to our Software that we use Something via a Handle Expressed by a IDL

its the functional eqivalent of Tagged Template Strings in Fact.

Tagged Template Strings Example

// A Function that accepts unlimted args
const Cpp = ((...args) => [arrayOfTypeString, ...all] = args;
Cpp`
int main() {
  int y = SOME_MACRO_REFERENCE;
  int x = 5 + 6;
  cout << "Hello World! " << x << std::endl();
} // and this is the last one!`

Used as

// longStringInArray Map Pattern
['.includes("/") === false && .startsWith("@")']
  // use with a Function that accepts no Arrguments
  // Or at last does not Use them _prefixedName by Convention with TypeScript
  // returns void any
  .map(()=>"Result")[0];

// longStringInArray Reduce Pattern ( parsing Detect Array Containing Single Constant Typed String using reduce(()=>"Result", <any>) )
['.includes("/") === false && .startsWith("@")']

  // called with function<> Object<{}> needs to be assigned in Code
  // returns any
  .reduce(()=>"result",{});
  // The result is what the Function Returned  if it is void its what you put in on init
  .reduce(()=>Object<any>, Object<any>);
  // No Arrgument allowed can return any
  .reduce(()=>"This is the Result", Object<any>);
  // With argument usage
  .reduce((
    /** can be any aslong as the function does not return */
    ) => {
      /** can include anything if it returns void*/
      }, Object<any>);
   // NoOp Version function<NoOp> empty. or () => void; with result<any>
  .reduce(()=>{},"Result");

LongString Chain Result Pattern - intermediateValue type String followed by and && (expression(Any))

parsing detect algo: AST Nodes

  • intermediateValue Type String
  • Node Type Operator [and, &&]
  • Node Type (expression(Any)) Nothing that follows comments are ignored
'.includes("/") === false && .startsWith("@")' && "Result";
 // Typescript Experiment
 '@type {string}' && "Result"; 
 // the above is eq to Typescript allowJs checkJs version below
 /** @type {string} */ "Result"

Needs research in http Archive if this pattern is used for anything legit else looks like the best we can come up with :D i am so happy.

Goals

  • More Expressiv then Typescript
  • gets compiled away for performance on runtime without additional build directly by the Engine as comments
    • If you use Computed Type Annotations you can replace the Computing function in production builds to create zero runtime overhead with the AOT Compiled Types.
  • 100% Typescript Compatible. as also Flow
    • Should allow easy Transpilation from other Languages
  • Bundler Tooling.
  • Human Readable Code Comments that
     ///#Notes arrayMap maybe the most best calling method as it is imperativ.
     [ [args, this.npm] ].map( ([
       [initerName, ...otherArgs], { flatOptions, flatOptions: { color }, localBin, globalBin, config },
    ]) => 
     ///#Notes Funtion that needs call
    ([ initerName, ...otherArgs] = args, { 
       flatOptions, flatOptions: { color }, localBin, globalBin, config 
     } = this.npm) => 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment