wren-lang / wren-cli

A command line tool for the Wren programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[RFC] Utility class for validation functions

joshgoebel opened this issue · comments

I see:

  // TODO: Copied from File. Figure out good way to share this.
  static ensureString_(path) {
    if (!(path is String)) Fiber.abort("Path must be a string.")
  }

Why not just have a common utility class, ie: Ensure.string or Util.assertString...

class Util {
  static assertString(path) {
    if (!(path is String)) Fiber.abort("Path must be a string.")
  }
}

Open to suggestions for naming.


Alternaties: Subclass a common base class with the utilities but I'm not sure this is fully possible with foreign classes.

I created an assert lib and there are some others in the wild too

If this would be only for that specific use case my proposal would be

Assert.string() or Expect.string()

Related:

I think we just want to cover our specific requirements unless it's truly decided we want a FULL assertion library inside CLI, but that doesn't sound right OTTOMH. We gotta watch taking all the good names though since I don't think there is a way for people to get those names back if we use them all... that's worth consideration.