Coder Social home page Coder Social logo

Debug printing feature in language about gleam HOT 37 OPEN

lpil avatar lpil commented on May 27, 2024 7
Debug printing feature in language

from gleam.

Comments (37)

lpil avatar lpil commented on May 27, 2024 6

echo is actually a really good suggestion! I like that a lot.

Does it have to be a keyword? Something that worked more like a global function would be a lot more composable w/gleam syntax in my opinion, and you wouldn't have to adopt a whole new style of control flow for a single keyword. Tbh this feels so clearly like a function I think it would be extremely strange to have it be a keyword as described above.

It is to do things that a function cannot do. I'm not sure making it look a bit like a function would be beneficial given it couldn't be one.

from gleam.

massivefermion avatar massivefermion commented on May 27, 2024 6

echo thing as "thing" seems reasonable to me.

from gleam.

erikareads avatar erikareads commented on May 27, 2024 5

I'm a fan of whatis.

from gleam.

tynanbe avatar tynanbe commented on May 27, 2024 4

Just call it glimpse and be done with it πŸ˜‰

from gleam.

TanklesXL avatar TanklesXL commented on May 27, 2024 4

pry is the only one not previously said that comes to mind for me

from gleam.

brettkolodny avatar brettkolodny commented on May 27, 2024 4

spy because it makes me feel cool

from gleam.

bcpeinhardt avatar bcpeinhardt commented on May 27, 2024 3

πŸ‘€ value

No seriously though I would prefer it just be called debug or dbg or debug_print or something to that effect.
I wouldn’t mind a naming conflict and deprecating io.debug.

I think the ideal syntax would be for it to work in a pipe and for keyword value to be how it’s called

Edit: I no longer think this syntax is a good idea, I would much prefer something like a global function.

from gleam.

lpil avatar lpil commented on May 27, 2024 3

I doubt we'll ever use ? for anything. It's very easy to miss, not very Gleamy.

from gleam.

lpil avatar lpil commented on May 27, 2024 3

Definitely. This is also what io.debug does today.

from gleam.

lpil avatar lpil commented on May 27, 2024 2

Having it return the value sounds good. We'd need to decide if it has any special pipes support as I suspect folks will want to pipe into it.

from gleam.

lpil avatar lpil commented on May 27, 2024 2

We're not breaking the stdlib, and there's lots of other contexts in which the word debug is more appropriate and already taken, such as logging libraries.

I don't think debug is as good a name for printing as it would be for use in a debugger too.

from gleam.

inoas-nbw avatar inoas-nbw commented on May 27, 2024 2
  • i like peek and dump both are single syllable and have no underscores and are short enough.
  • i don't like whatis because I would want to type what_is but that's slow to type.
  • should def be an expression that returns the value so that it can be piped or just any call/value wrapped anywhere really
  • I also like ? exp:
? foo
|> ? bar
|> ? quux(? batz)

I like it :)

from gleam.

massivefermion avatar massivefermion commented on May 27, 2024 2

I would like thing? but ? thing seems too weird to me. I don't see how it fits in Gleam! I really feel like it breaks the flow somehow!
But I should add that a keyword seems more Gleamy. I think pry or peek are great.

from gleam.

giacomocavalieri avatar giacomocavalieri commented on May 27, 2024 2

We could also reuse the "as" used by todo and panic:

foo
|> bar
|> echo as "tag"
|> baz

It would be a bit more awkward when used as a function though:

// maybe? I have no idea how it should look
echo foo as "tag"

from gleam.

massivefermion avatar massivefermion commented on May 27, 2024 1

I like whatis but the fact that it's not what_is would be painful to me!
I vote peek.

One annoyance is that the anything-to-string code is in the standard library, not in core. Perhaps it could gracefully degrade if stdlib isn't available.

What behavior would it degrade to?

from gleam.

MystPi avatar MystPi commented on May 27, 2024 1

My personal favorites are dump and ? expr. whatis and what_is are both slower to type and to say (even mentally), so I'm not as big a fan of them.

from gleam.

bcpeinhardt avatar bcpeinhardt commented on May 27, 2024 1

What about trace?

Seems like we don't want to do anything that would overlap w/proper logging (trace, debug, info, warn, error).

from gleam.

bcpeinhardt avatar bcpeinhardt commented on May 27, 2024 1

Ah yeah "looks like a function but isn't a function" is actually a bad outcome I suppose πŸ€”

from gleam.

bcpeinhardt avatar bcpeinhardt commented on May 27, 2024 1

If I hadn’t been poisoned by previous language experience I would think value? would be a quick easy common sense way to have a built in debugging feature, but having seen all the powerful ? syntax in other languages it would feel like such a demotion for the ?.
I wonder if we'd regret using ? here down the line when we have an idea for a cool new feature that ? Would be perfect for.

from gleam.

giacomocavalieri avatar giacomocavalieri commented on May 27, 2024 1

If this doesn't make it into 1.0 would it be sensible to reserve echo?

It was reserved in v0.34.0

from gleam.

sotolf2 avatar sotolf2 commented on May 27, 2024

Big fan of whatis as well

from gleam.

lpil avatar lpil commented on May 27, 2024

One annoyance is that the anything-to-string code is in the standard library, not in core. Perhaps it could gracefully degrade if stdlib isn't available.

What behavior would it degrade to?

Printing in the syntax of the native target. JS or Erlang

from gleam.

giacomocavalieri avatar giacomocavalieri commented on May 27, 2024

I'd like both what_is or peek, even whatis (but I prefer the snake case version)

Where could it be used? Would it work like debug returning its rhs?

peek peek foo
// print foo twice?

bar(peek foo)
// print foo?

foo
|> peek bar
// print bar?

from gleam.

inoas-nbw avatar inoas-nbw commented on May 27, 2024

pry is the only one not previously said that comes to mind for me

but are we really prying... into the vm runtime value?

from gleam.

Zinggi avatar Zinggi commented on May 27, 2024

I'm just a silent reader on discord, but I'll chime in for bike shedding πŸ˜†

What about trace?

Apparently that even has some precedent in ActionScript: https://open-flash.github.io/mirrors/as2-language-reference/global_functions.html#trace()

from gleam.

bcpeinhardt avatar bcpeinhardt commented on May 27, 2024

? has a lot of potential power as a single character operator, I would hate to see it wasted on this.
What about echo as the name?

Does it have to be a keyword? Something that worked more like a global function would be a lot more composable w/gleam syntax in my opinion, and you wouldn't have to adopt a whole new style of control flow for a single keyword. Tbh this feels so clearly like a function I think it would be extremely strange to have it be a keyword as described above.

from gleam.

inoas-nbw avatar inoas-nbw commented on May 27, 2024

echo is actually a really good suggestion! I like that a lot.

Does it have to be a keyword? Something that worked more like a global function would be a lot more composable w/gleam syntax in my opinion, and you wouldn't have to adopt a whole new style of control flow for a single keyword. Tbh this feels so clearly like a function I think it would be extremely strange to have it be a keyword as described above.

It is to do things that a function cannot do. I'm not sure making it look a bit like a function would be beneficial given it couldn't be one.

that's the reason I like ? as it cannot be confused...
What would the semantic explanation be for echo versus peek or pry or dump?

from gleam.

lpil avatar lpil commented on May 27, 2024

What would the semantic explanation be for echo versus peek or pry or dump?

No semantic difference here, just about how they feel, look, and any connotations from other languages.

from gleam.

inoas avatar inoas commented on May 27, 2024

hm, echo would write a string to the output buffer in php.
which other languages use echo?

echo foo
|> echo bar
|> echo quux(echo batz)

I think the question mark with a space is a good thing, ... a word kind of pollutes the screen/attention and makes it harder to follow the code with the debug printing included.

from gleam.

inoas avatar inoas commented on May 27, 2024

Could gleam publish fail if there are debug commands in the code?

from gleam.

lpil avatar lpil commented on May 27, 2024

Yes! That's one of the things covered above

from gleam.

chuckwondo avatar chuckwondo commented on May 27, 2024

Goals:

  1. Prints location so the programmer knows where the logging is coming from
  2. Prints optional extra context, like a tag
  3. Does not require an import
  4. Warns so you don't forget it by mistake
  5. Blocks gleam publish so you can't publish code that uses it

Let's keep in mind goal 2. Including a "tag" in the output in order to label the thing being printed can be extremely helpful in aiding debugging.

I don't think any of the syntax proposals so far include such tagging.

How about something like the following?

value
|> process
|> :tee "my tag"
|> more_processing

This potentially does the following:

  • supports piping
  • uses a : prefix to distinguish as not a function (since it's not a valid function name) -- see alternative suggestions below
  • is relatable to the *nix tee command, which passes its input through unchanged to its output, while also spitting it out to a file (in this case, spitting it out to either stdout or stderr, which is perhaps another question to consider)
  • would write "my tag: x" (where x is the value returned from process) to either stdout or stderr

I think the question of where to write the output (stdout or stderr) is perhaps another consideration. I would lean towards stderr so that injecting :tee doesn't potentially interfere with the program itself, which might be intended to be used in command pipeline (like the tee command itself). If it were to write to stdout, it might interfere with proper operation of the program that we might be trying to debug.

Alternative syntaxes for the :tee shown above:

|> :tee "my tag"
|# "my tag"
|> #"my tag"
|> ("my tag")
|> #my tag#

from gleam.

inoas avatar inoas commented on May 27, 2024

I think it should print to stderr. If required later gleam.toml could make this behaviour configurable.


For words, short 1-word-1-syllable dump, pry, peek, show are those I'd prefer.


If we need tagging for the question mark, if we do prefixing, it could look like this:

// Regular
? var as "tag1"

// Piped
? foo as "tag2"
|> ? bar as "tag3"
|> ? quux(? batz as "tag4") as "tag5"

...or if it is suffixed like this:

// Regular
var ? "tag1"

// Piped
foo ? "tag2"
|> bar ? "tag3"
|> quux(batz ? "tag4") ? "tag5"

from gleam.

rnice avatar rnice commented on May 27, 2024

inspect foo

from gleam.

lpil avatar lpil commented on May 27, 2024

Inspect is not an option, it is already taken. We have gone with echo, the discussion is the design now.

from gleam.

chuckwondo avatar chuckwondo commented on May 27, 2024

@lpil, as mentioned above, I'd suggest output go to stderr, not stdout, to avoid potential interference with intentional program output. Does that make sense?

from gleam.

inoas avatar inoas commented on May 27, 2024

If this doesn't make it into 1.0 would it be sensible to reserve echo?

from gleam.

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.