Giter VIP home page Giter VIP logo

Comments (6)

fubark avatar fubark commented on May 18, 2024 2

Gotcha, yea to add to this, I think we should rename toString() to utf8(). That function would do validation and can return an error. string() on the otherhand doesn't return errors and does it's best to get back something. Right now I think that behavior is to return "rawstring (20)" where 20 is the length and it does something similar with other object types. One alternative could be: it does validation and either returns the utf8 or an empty string upon error.

from cyber.

fubark avatar fubark commented on May 18, 2024 1

Just pushed an update for this. Also fixed some formatting issues with number and raw string slice.

from cyber.

fubark avatar fubark commented on May 18, 2024

You can achieve this with string(four). I'm open to adding this down the road if people like toString(). One issue I can see is it'll give the impression that every value has toString() and that would require adding a missing function fallback that may reduce performance.

from cyber.

sts10 avatar sts10 commented on May 18, 2024

Ah, thank you.

For what it's worth, I think string(4) is more in-line with how number("4") and int("4") work currently. Is there a reason we still need foo.toString()? In other words, could you add the functionality of foo.to_String() into string(foo), then deprecate .toString()?

from cyber.

fubark avatar fubark commented on May 18, 2024

toString() doesn't exist at the moment (Except for rawstring to get back a valid utf8 string). I'm hesitant to add it to number because it would lead to other primitives to have it too.

from cyber.

sts10 avatar sts10 commented on May 18, 2024

Except for rawstring to get back a valid utf8 string

Ah OK. I guess what I was suggesting is to allow users to use string(rawstring) to get back a valid utf8 string. Then Cyber could do away with toString() all together.

Broadly, I think having string(foo) and foo.toString() in the docs could confuse new users. But I'm obviously not aware of the interior mechanics and whether this is easy or difficult.

from cyber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.