mde / true

A JavaScript port of the Unix utility 'true'. Returns the Boolean value `true`
101 stars 26 forks source link

"true" should not be hardcoded #19

Open throop02 opened 7 years ago

throop02 commented 7 years ago

If the ES standard is updated and "true" is changed to another keyword (such as yea, yes, or affirmative) it would break this library. Instead of returning true could we return (1==1)?

yukulele commented 6 years ago

or simply (NaN !== NaN)

mde commented 6 years ago

In theory, the ES standard could update the definition of NaN, or even 1. Can we think of a more future-proof way to accomplish this?

mde commented 6 years ago

Also worth noting that the strict equality operator is not necessary with NaN. No value is coerceable to be equal to NaN -- not even itself.

tfrijsewijk commented 5 years ago

return !~-1;

Perhaps then we should look into #7 caching again

mde commented 5 years ago

It's also theoretically possible that the laws of logic could change, and this could no longer be true. Ideally we'd find an even more bulletproof way to represent this.

solonovamax commented 3 years ago

Perhaps we could try calling the unix tool true from the command line? I hear that it's pretty fast & accurate most of the time. Though, that means you'd need some other method for non unix systems, or unix systems without true.

OlegGavrilov commented 3 years ago

Perhaps we could try calling the unix tool true from the command line? I hear that it's pretty fast & accurate most of the time. Though, that means you'd need some other method for non unix systems, or unix systems without true.

I would rather depend on a wasm-compiled version of true tool.

Miigon commented 3 years ago

just in case the fundamental law of thermodynamic changes in the future, how can we think of a better/more future proof way to build a computer on which this library runs on?

mde commented 3 years ago

Any serious effort here needs to take all the various Quantum Computing models into account.

devshark commented 3 years ago

Have we considered the following?

return !undefined;

I am assuming undefined will never be defined, and it is guaranteed after the announcement of IE's retirement.

To be completely safe and backwards-compatible, we can define our own undefined value:

module.exports = function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue () {
  return function (undefined) {
    return !undefined
  }();
};
mde commented 3 years ago

This could be an interesting approach, although conceptually this is relying on JavaScript type-coercion behavior, which seems less strict than the rigorous and obviously hugely beneficial typing approach conceived of here: https://github.com/mde/true/issues/25

devshark commented 3 years ago

I've updated the PR and skipped type-coercion altogether.

return undefined === anotherUndefined;
TimVosch commented 3 years ago

Wouldn't it make sense to have a serverless function somewhere which this function references? That would also help horizontal scaling if a project requires a lot of true's/ye's/yes's/affirmatives's. You wouldn't have to bother about the definition of true since the serverless can simply be update by a third party.

kaelonR commented 2 years ago

To truly make this library future-proof against the onslaught of frequent changes to javascript's core language features, I think it's probably best if we do not generate the value true ourselves but require the caller to supply it as parameter to the library's public API. The code would look like this:

module.exports = function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue (trueValue) {
  return trueValue;
};

then for users of the library, they'd interact with it like this:

if(aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue(true))

This way we can ensure that this library will always work, by offloading the burden of maintenance to the end users and off our own hands.

Miigon commented 2 years ago

@J141 I agree with you but user codebase can also be affected by the frequently changing language, making the library non-functional. I think the best way to tackle this is to train a machine-learning based model to dynamically learn what value "true" should be in a given runtime, preferably implemented without using the "true" value, to avoid bootstrapping problem.

dandean commented 2 years ago

I really like these ideas about future proofing this library. One thing that's certain and has been proven time and again is the reliability and long-term efficacy of the blockchain. If we offload the work of this library onto the blockchain, the value of true will never change, and we can reliably reference it over time, even if the rules of logic and/or thermodynamics are pulled out from under us, like a rug. There are some excellent stablecoins out there we could rely on far into the future, such as $LUNA.

mde commented 2 years ago

Has anyone considered the impact of quantum computing here?

Miigon commented 2 years ago

@dandean One $LUNA as fee for one "true" invoke, sounds like a good idea (AND a great deal!)

luphoria commented 1 year ago

To truly make this library future-proof against the onslaught of frequent changes to javascript's core language features, I think it's probably best if we do not generate the value true ourselves but require the caller to supply it as parameter to the library's public API. The code would look like this:

module.exports = function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue (trueValue) {
  return trueValue;
};

then for users of the library, they'd interact with it like this:

if(aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue(true))

This way we can ensure that this library will always work, by offloading the burden of maintenance to the end users and off our own hands.

Seems like a good idea at first, but this opens attack vectors (especially MItM and corruption).

Docker fixes this. What if we shipped a container running Node.js version 12, and relied on this version to define true and then return its response to the user? Perhaps, instead, we could use a complete virtual machine, to combat against potential attacks from or breaking down the line at the advent of quantum computing.

mde commented 1 year ago

Good thoughts here. But there would have to be some way of safely updating the OS/Node versions, as well as whatever version of the container or VM technology we choose. So critical to be forward-thinking in these areas.

tj-commits commented 1 month ago

You can use axios to download an image of the text true, and then use tesseract to get the text of the image and then use the Boolean function to convert it to the boolean value true. We can not use the unix utility true as the unix utility true does not return true instead exits with code 0. The code will look like this:

var IMAGE_URI =
  "https://mma.prnewswire.com/media/1009614/True_Logo.jpg?p=twitter"
var Tesseract = require("tesseract.js")
var axios = require("axios")
var fs = require("node:fs")
module.exports =
  function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue() {
    return new Promise(function (resolve) {
      axios
        .get(IMAGE_URI, { responseType: "arraybuffer" })
        .then(function (response) {
          fs.writeFile("./true.jpg", response.data, function (err) {
            if (err) throw new Error("error: " + err.message)
            Tesseract.recognize("./true.jpg", "eng").then((result) => {
              fs.rmSync("./true.jpg")
              fs.rmSync("./eng.traineddata")
              resolve(Boolean(result.data.text))
            })
          })
        })
    })
  }

Of course, now the user would use it like this:

const t = require('true')
(async function() {
   var myTrueValue = await t()
   console.log(myTrueValue) // true
})()

or this

t().then(myTrueValue => {
  console.log(myTrueValue) // true
})
solonovamax commented 1 month ago

You can use axios to download an image of the text true, and then use tesseract to get the text of the image and then use the Boolean function to convert it to the boolean value true. We can not use the unix utility true as the unix utility true does not return true instead exits with code 0. The code will look like this:

var IMAGE_URI =
  "https://mma.prnewswire.com/media/1009614/True_Logo.jpg?p=twitter"
var Tesseract = require("tesseract.js")
var axios = require("axios")
var fs = require("node:fs")
module.exports =
  function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue() {
    return new Promise(function (resolve) {
      axios
        .get(IMAGE_URI, { responseType: "arraybuffer" })
        .then(function (response) {
          fs.writeFile("./true.jpg", response.data, function (err) {
            if (err) throw new Error("error: " + err.message)
            Tesseract.recognize("./true.jpg", "eng").then((result) => {
              fs.rmSync("./true.jpg")
              fs.rmSync("./eng.traineddata")
              resolve(Boolean(result.data.text))
            })
          })
        })
    })
  }

Of course, now the user would use it like this:

const t = require('true')
(async function() {
   var myTrueValue = await t()
   console.log(myTrueValue) // true
})()

or this

t().then(myTrueValue => {
  console.log(myTrueValue) // true
})

what if the name of the boolean value of true changes? how would this be accounted for?