DidactMacros
I put this under chat/ discussions as this does not regard a bug, just some design/best practices.
I have program that I am building as per an exercise, and I want to use Kernel.to_string so that I don’t have to check a type later down the line.
The data being converted to string is simply going onto a table, and is being obtained from a keyword list. If the get on the keyword list yields nil the to_string will yield an empty string, and I’m fine with that.
I did not want to use inspect, as this is for logging/debugging and it seems there could be some security consequences down the line if I get into the habit of using inspect in this way, since it processes special terms and sigils.
to_string seems quite powerful, and it’s going to cut down a lot of code that I didn’t want to write and which would have seemed a bit repetitive, but should I be using it in this way?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
benwilson512
Hey @DidactMacros your distinction between
inspectandto_stringis dead on.inspectis dangerous precisely because it can give away potentially significant information.to_stringhowever is designed to be used exactly the way you’re using it. Types that have a canonical, user facing string representation will just work!DidactMacros
Thanks a lot, that’s great to know. Full steam ahead then.
ityonemo
Iirc, this happens under the hood anytime you use #{} interpolation
rhcarvalho
That’s right, the relevant docs:
Adzz
What does this bit mean?
DidactMacros
I mean that I want to convert the data to a string if it is a compatible data type for the to_string function, rather than identifying and converting it through guards or cases.
The data is being obtained through list[key] from a keyword list, if nil is yielded I will get an empty string, which is what I want.
If any functions or incompatible types are sent through, it would throw an error, I’m not expecting that, but a runtime error seemed appropriate for such an occurrence.
Should I try to handle that differently?