Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"true" should not be hardcoded #19

Open
throop02 opened this issue Aug 2, 2017 · 22 comments · May be fixed by #34
Open

"true" should not be hardcoded #19

throop02 opened this issue Aug 2, 2017 · 22 comments · May be fixed by #34

Comments

@throop02
Copy link

throop02 commented Aug 2, 2017

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
Copy link

or simply (NaN !== NaN)

@mde
Copy link
Owner

mde commented Jan 30, 2018

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
Copy link
Owner

mde commented Jan 30, 2018

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
Copy link

return !~-1;

Perhaps then we should look into #7 caching again

@mde
Copy link
Owner

mde commented Nov 7, 2019

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
Copy link

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
Copy link

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
Copy link

Miigon commented May 18, 2021

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
Copy link
Owner

mde commented May 19, 2021

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

@devshark
Copy link

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
Copy link
Owner

mde commented Jun 19, 2021

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: #25

@devshark
Copy link

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

return undefined === anotherUndefined;

@TimVosch
Copy link

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
Copy link

kaelonR commented Jan 6, 2022

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
Copy link

Miigon commented Jan 9, 2022

@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
Copy link

dandean commented May 13, 2022

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
Copy link
Owner

mde commented May 13, 2022

Has anyone considered the impact of quantum computing here?

@Miigon
Copy link

Miigon commented May 14, 2022

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

@luphoria
Copy link

luphoria commented Jun 6, 2023

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
Copy link
Owner

mde commented Jun 8, 2023

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 tj-commits linked a pull request Jul 6, 2024 that will close this issue
@tj-commits
Copy link
Contributor

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.