-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
rdmd: and with a last statement without effect should print it #317
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
77a3038
to
b988788
Compare
rdmd.d
Outdated
if (code.length > 0 && code[$ - 1] != ';') | ||
code ~= ';'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: this change comes from #303 which hasn't been released yet.
This is nice if we manage to make it unambiguous. |
import std.typecons : tuple; | ||
foreach (t; [tuple(`"eval_works"`, "eval_works"), | ||
tuple("2 + 2", "4"), | ||
tuple("2.write; 2 + 2", "24")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try a test with "if(0) {} 2 + 2" - that won't work
One thought comes to mind, would we need to support the case where a developer doesn't want the return value of their expression to be printed? |
b988788
to
3d6815d
Compare
Then he can add a semi-colon (as before).
It would error too at the moment - but sure that's easy enough.
The point was that everything without an ending semi-color fails atm and this trick will do the sensible thing in the vast majority of cases. |
For the record (we've already discussed this in other PRs): no, I didn't. Automatically adding closing semicolons to code provided via What #303 changed was to stop that closing semicolon being added if one was already there (to avoid empty statements at the end of the program, which some compilers object to). |
BTW, I would like to understand better the particular motivation behind this feature, other than that it seems cool. "95% of all uses" are mentioned above. What are those uses? Are they motivated by real, reported user needs? Or just imagination about what users might do? "people who use it like I ask all this because it seems an odd thing to magically special case the behaviour of D code for this one specific use-case. The good old principle of least surprise suggests that |
Could you provide examples you would find surprising? |
If I ask for a piece of D code to be evaluated, I expect for that D code to be evaluated as it is. I do not expect for some extra magic to be done that prints out something I didn't ask to be printed. I certainly do not expect the difference between nothing happening versus something happening to be whether or not I put a semicolon on the end of the code I provided. That's really weird special-casing. In a case like this, the onus really has to be on the feature proposal to explain what is so good and valuable about it that we need to break with the intuitive and longstanding behaviour of
|
Most of that was just repeating what you already said... You said it would be surprising, can you provide surprising examples you were thinking of so the rest of us can evaluate it for ourselves? Surprise is subjective after all |
NO. This is fundamentally the wrong way to be thinking about this.
The proposed feature is a breaking change to one of the most widely used pieces of software in the D ecosystem. The onus is 100% on the feature proposal to provide significant justification for such a change. Any other attitude is a fundamentally irresponsible attitude to maintaining a tool that LOTS of people rely on. |
I dont know why your assuming how I'm thinking about this. I'm just asking you to provide examples to backup one of your arguments. Also, how would this be a breaking change? |
I've defined my sense of "surprising" clearly: it's surprising if D code provided to Indeed, it's a pretty basic principle of maintaining widely used software that behavioural changes visible to the user should be carefully thought about and justified. From this point of view any such behavioural change is by definition surprising. Asking questions about why that would be surprising strongly suggests a lack of understanding of that principle. Which is why I suggest the thinking is wrong-headed. The focus needs to be on why the feature is good and important enough to justify the surprise.
Because |
I was just asking questions to gather data. But every time I ask a question you start making assumptions about what Im thinking then proceed to rant and repeat yourself. I'm going to disengage from this, conversing with you is a time sink with no benefit. |
Folks, I'd like to ask that we put the focus on the questions I asked above: #317 (comment) |
@WebDrake no worries. This is moving nowhere unfortunately for now because the logic to insert a FWIW I doubt that - if it works perfectly - could break much code, because I also get the point that printing Anyhow as long as we can't easily rewrite the last expression (or have a plan on how to do this), there's really no need to worry that this will be added. -> setting this to BLOCKED for now. Sorry about this, it was a nice idea, but it seems it's not that easy in practice... |
@wilzbach OK, but I still think it would be good to be clear about the motivation and real use-cases if this is ever to be un-blocked. "It's a nice idea" is a risky basis for behavioural change if it's not backed up by real, concrete user needs (which is not the same as "Well, then you could do THIS and THIS..."). There's a LOT of value in the simplicity and clarity that says, " As I noted, |
I'd like to suggest an alternative #320 that IMO is better |
just make a --print flag |
That would be Anyhow, I'm not really sure on the best way to solve this problem here:
I'm currently thinking about limiting this to a smaller subset, e.g. insert a "writeln(...);" if there's no semi-colon at the end and the beginning of the eval code can be reached by only seeing |
The core problem here is that whatever solution is taken, it involves creating some magical alternative language that looks like D but behaves differently in very subtle ways. |
tl;dr: @WebDrake recently changed the
rdmd
to automatically add semicolons for the last statement without effect (#303), but I think we can do a bit better and makerdmd
even more user-friendly.At the moment we are in the unique position to introduce this without any breakage as until now
rdmd
didn't allow this:The new behavior will default to
writeln
if the last statement would have no effect:A few more examples:
$(H4 Use
rdmd
as your calculator)...
I'm aware that this is a "poor man's solution" and could be done better, but look at it this way:
rdmd
and people who use it likeperl
's evalQ: Oh come on, people can just type
writeln
themselvesYes of course, but for CLI tools every keystroke matters and REPLs print to stdout.
Also it's a nice default for these two specific flags (in comparison to the hard error).
CC @CyberShadow @marler8997 @WebDrake @andralex