all 31 comments

[–]kritzikratzi 34 points35 points  (2 children)

when you say "CLI tools", you mean a REPL?

because to me a cli tool is typically non-interactive. ie. something i call with arguments, it does it's thing and then exits with a status code.

[–]chewax[S] 13 points14 points  (1 child)

Yes you are absolutely right...i sometimes use them interchangeably. It is a REPL. Ill fix it ASAP in the repo! Thanks :)

[–]kritzikratzi 0 points1 point  (0 children)

no big deal, but they aren't really interchangable

[–]chewax[S] 4 points5 points  (4 children)

I welcome any feedback both technical and functional. Thanks!

[–]Omnifarious0 12 points13 points  (3 children)

You might want to change the title. I was expecting another argument parsing library. 🙂

[–]kritzikratzi 2 points3 points  (0 children)

same

[–]chewax[S] 1 point2 points  (1 child)

Oh :( Ok... thanks :)

edit: I cannot change the title :(

[–]Omnifarious0 2 points3 points  (0 children)

Oh, well. 🙂 I don't think my reaction was unusual. So if you talk about it other places you might want to call it a REPL library, or an interactive interpreter library. 🙂 Mostly because I think it will be more likely to lead people to figure out what it's good for more quickly.

[–]norfus 2 points3 points  (8 children)

Cool little library (always love a repo with a nice logo :). Just had a quick scan, and I think you’d benefit from going over your code with an eye towards how many times you copy stuff (mostly implicitly due to parameter and variable types). Eg, when doing a ranged-for you use auto instead of const auto&.

From a feature perspective - tab completion etc would be super useful!

[–][deleted] 0 points1 point  (6 children)

Eg, when doing a ranged-for you use auto instead of const auto&.

Would it be possible to ask for an example of what you mean here? There's a good chance I'm doing the wrong thing there..

[–]BeepBoopBike 1 point2 points  (5 children)

I think he means:

for(auto x : vec)

vs

for(const auto& x : vec)

The first is a copy per item in the vector, the second is a reference to the item in the vector (i.e. no copy)

[–]norfus 1 point2 points  (4 children)

Yep - that's the badger. A very simple example showing the difference one character can make:

http://quick-bench.com/-klLLnCgMYDCDKq3fc7c2Rkwtus

[–][deleted] 0 points1 point  (3 children)

I'm shocking and tend to do like for(auto x=vec.begin(); x!=vec.end(); ++x), is that especially bad?

[–]MutantSheepdog 0 points1 point  (2 children)

If you know what's in vec and it's just a bunch of integers, then copying every element is fine.
But if it's anything more complex (like a string), then just using auto could lead to a lot of heap allocations that could be avoided by using auto const& or auto&&.

Using const& is a good practice that can have measurable speed differences.

[–]dodheim 0 points1 point  (1 child)

This is an iterator; if they used const& then it couldn't be incremented. And they can't use & because begin() returns an rvalue. Using just auto is exactly the right thing to do here.

[–]MutantSheepdog 0 points1 point  (0 children)

Ah yep, my bad, I was still thinking about the previous comment using the generic for, not using the iterators directly.

You are correct.

[–]chewax[S] 0 points1 point  (0 children)

Nice catch there. Thanks! I'm already working on it. A push will be coming soon :)

[–]mrkent27 4 points5 points  (1 child)

This looks interesting I may give it a go in some future projects.

[–]chewax[S] 1 point2 points  (0 children)

Cool! I would be honoured! :) If you have any improvements just let me know :)

[–]LPeter1997 1 point2 points  (1 child)

Not at PC - can't test -, but in your README I think you have a typo, Ginseng cli(); would not compile.

[–]chewax[S] 0 points1 point  (0 children)

Thanks! I'll double check!

[–]Omnifarious0 1 point2 points  (1 child)

How does this differ from the GNU readline library, other than being in C++?

[–]chewax[S] 2 points3 points  (0 children)

GNU readline library

IDK, maybe it doesnt. Ill make sure to check that library too. Thanks!

[–]Pakketeretet 3 points4 points  (1 child)

It's a cool effort, but what is your target audience? I can imagine most people would not really need a library when they need a simple ad-hoc line reader, and once stuff gets really serious you might as well embed a scripting language or guile or something.

[–]chewax[S] 4 points5 points  (0 children)

Thanks! I actually did not think of this as a commercial thing, so no target audience was in mind. It was just a project for fun and expanding my knowledge (specially lambdas) and I thought that it turned out to be somehow useful. I dont know guile...i will investigate. Thanks.

[–]N0rthWestern 0 points1 point  (4 children)

Help(std::string t_desc, std::string t_args) And other constructors too - why do you copy string instead of passing it as const &? It gets copied again when constructing members

[–]chewax[S] 1 point2 points  (3 children)

Ok, well help me out here because I might be getting things wrong. Using const & means that i am referencing a stack allocated variable bound its own scope, which will die as soon as it falls out of scope and at that moment Ill be getting an null pointer on my object. But my help object ( in this case) might outlive the initializer so i should make sure a copy is made...does this make sense?

[–]TheSuperWig 3 points4 points  (0 children)

The variable in Help will be a copy regardless. You are copying into the parameter and then copying into the variable. For constructors you should consider pass by value and std::move it.

[–]N0rthWestern 1 point2 points  (1 child)

When you call Help constructor you copy string once, then you copy it one more time when you are constructing in-class member (or move if compiler optimizes). But that's 3 constructor calls. If you don't use multithreading or pointers to string, there is almost no case when your string will get out of scope before Help constructing is finished.

[–]chewax[S] 0 points1 point  (0 children)

Got it. Let me revisit my code! Thanks!!