-
Notifications
You must be signed in to change notification settings - Fork 359
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
Debug.log could be more intuitive for beginners and less misuse prone #1082
Comments
Thanks for reporting this! To set expectations:
Finally, please be patient with the core team. They are trying their best with limited resources. |
Is a hack but something alone these lines might work: const log = name => {
const p = typeof Promise === 'undefined' ? undefined : Promise.reject("you must pass this function two arguments!");
return value => {
if (p !== undefined) {
p.catch(x => x);
}
console.log(`${name}: ${value}`);
}
} If you call elm/core would need to es5-ify the syntax. |
I agree with you, and I think log/logWith should be formatted as a tree by default to be inspected/expanded, currently it is displayed as a big unreadable string. |
inspired by elm/core#1082
Just to tell that this issue is important. I spent 3 hours until 03:00 am yesterday because of that, only to find today that the compiler is not enforcing the condition of having two arguments. Since we usually can trust the compiler, I never ever imagined this time was an exception, just to find out that I was wrong :) |
I agree that the usage in the Debug.log function could be made less error prone, especially for beginners. Since we're ignoring the data coming from it, it's common to forget the currying when printing strings and get the outcome pointed to in this issue. One pattern I adopted on my elm usage that avoids this issue is trying to use the Anyway, it isn't a fix and I think elm could benefit from the suggestion of "log/logWith", maybe just avoiding the breaking change, but I wanted to share as a mindset change that helps me avoid this mistake. |
I think the compiler should just tell you to read the docs for the |
Actually maybe the type of
|
This is not helpful, folks don't have an error, they have no output, this is the main issue discussed here.
It would not be possible anymore to insert it in the middle of a pipeline without composing with |
I think having |
Maybe |
I see there is a "breaking" label, with this option: #1082 (comment) it doesn't have to be a breaking change. |
Problem
It's easy to be tricked by a partial application of
Debug.log
that does not log anything:A lot of beginners try
Debug.log "I got here"
logs and are asking on slack why this does not work. Even experienced developers are occasionally tricked by mute_ = Debug.log value
, wasting some precious debug time.Requirements
Based on the feedback of developers and those helping regularly beginners, it seems that to cover most use cases without being error prone, the
log
function must:One solution
Consequently, an alternative to the current design would be to have two functions, the default one just logging the value, another one prefixing a string before the value like the current design:
It's then expected to not have any log with a partial application, as nothing is logged:
It's easy and intuitive to log a simple string:
It still works in pipelines:
Moreover
Debug.log
allows to log a value without the cognitive load of having to find a tag name, which is a very common use case if you need only one log during a debug session.Lastly if the log is found confusing, it's easy to consciously prefix a tag with
logWith
:Possible Improvements
A later improvement could be to add automatically a tag for the
Debug.log
function based on compiled code information, for example the function name or source code file and source code line.Impact
This would be a major change in semantic versioning. However the fact that
Debug.log
is not permitted with--optimized
should significantly limit the actual impact on users source code.Thank you @jessta, @pd-andy and others for the inputs and feedback.
The text was updated successfully, but these errors were encountered: