DavidSpickett wrote:

> I've added %undo to the documentation and implemented %help. Would it be good 
> to also add %help to the documentation?

Yes add %help. It feels a bit redundant and it is, but it'll also be a hint for 
future developers to say "hey, remember that new commands have to appear in 
%help too".

> To print stuff, I am just using printf(). Is this fine? It would be easy to 
> switch to std::cout or it looks like there are some llvm print functions but 
> I am not sure if its necessary/preferred to use them.

Generally we'd use some `llvm::` thing mostly because it'll be writing to a 
stream that can be redirected for testing and other purposes. The best idea is 
to look at how the surrounding code operates and follow that style.

Also when you add tests you'll see that capturing stdout is more annoying than 
passing a string backed stream to whatever you're testing, and reading back 
from the string.

Overall though, using the "obvious" functions just to get a thing working and 
then swapping to the project specific APIs is a good approach. Even if you 
stuck with printf, all that would happen is a reviewer would say hey this 
output is fine but you need to use this API instead, which is an easy fix.

> The only use of '%' I know of in cpp is the modulo operator which would never 
> be the first character in a line

I don't keep up with the standards but I seem to remember a change that relaxed 
some restricted characters Probably for C++26 at the earliest though. You are 
right that % in normal circumstances is just modulo.

Ofc maybe someone does `a %b` and would prefer to see the compiler error, so if 
the line (stripped of surrounding whitespace) is not just `%thing`, then it 
does not make sense to treat it as a % command.

> As far as %something throwing a specific error about a bad %command, I feel 
> like there are too few commands and they are too easy to type for it to be 
> needed. Let me know if you think its needed and I will implement it.

My point was how do you even discover that the % thing exists and how do you 
see typos? Yes you can compare to the docs but:
```
> %unod
Invalid % command: unod
```
Puts it all closer together so I don't have to look at docs. If it did the "did 
you mean undo?" thing that'd be even better but leave that for another time.

I agree this part is not necessary just nice to have, so I would leave it out 
and if you have time later come back to it.

It's just one of those "nice" things I have got used to in many other (more 
complex) programs. Where `program --option=something_random_I_made_up` responds 
with `Invalid --option value, you could have used these instead:`.

https://github.com/llvm/llvm-project/pull/150348
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to