Dealing with overloads in QString

Discuss anything related to product development
Post Reply
Navadvipa Chandra d
Posts: 34
Joined: Sun Apr 19 2020 7:02 pm

Dealing with overloads in QString

Post by Navadvipa Chandra d »

Hello, Barbara and All!

I looked at the QString class in the Copper Spice documentation. And that's what I found there.:

bool contains (char ch, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool contains (const QRegularExpression8 &regExp) const
bool contains (const QString8 &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool contains (QChar32 c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool contains (QStringView8 str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const

Then I have a 3 questions.
The function

bool contains function (const QString 8 &str, Qt::Case Sensitivity cs=Qt::Does CaseSensitive) const

!. duplicate functionality or not?
2. Isn't it possible to solve all the problems of this function using regular expressions?
3. What is the use of this function and is it necessary?

Here you can add
bool Like(const QString8 &ATemplatye) const

or make an extended version ( It hasn't been done yet, but it's a small thing ).

bool Like(const QString8 &ATemplatye, Qt::CaseSensitivity cs=Qt::CaseSensitive) const

Thank Yo very much.
With best regards, Navadvipa Chandra das.
Navadvipa Chandra d
Posts: 34
Joined: Sun Apr 19 2020 7:02 pm

Re: Dealing with overloads in QString

Post by Navadvipa Chandra d »

Hello, Barbara and All!

I'm looking at the forum and I saw that this is my message listed in a separate question. It spun off from another topic.

Like( QString::iterator t_end, QString::iterator s_end, QString::iterator t, QString::iterator s )
Now I'm already against adding this function as a method of the QString class. And it doesn't matter under what name - "Like" or "contains". On the one hand, you can reduce the number of parameters passed to the function - you only need template iterators, and on the other hand, when the function exists separately, it becomes more versatile and flexible. Imagine that you have a large list of strings, and you want to work with this list of strings using only the first five characters of each string.

It is not difficult to write

QString::iterator B = S.begin, E = B + 5; // we believe that the lines are long enough, otherwise verification is required.

But if we use a class method, then the begin() and end() iterators are already fixed and not passed to the function. If you transfer them, then you need to make this function static, because no internal data is used.

If we want to process the first five characters using regular expressions, we first need to create a shortened version of the string using QString8::mid or QString8::substr, which will call the string constructor, which in the for loop will add one character to the string we need. This will be much slower than preparing the necessary parameters for the Like function.

Sincerely, Navadvipa Chandra das.
barbara
Posts: 491
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Dealing with overloads in QString

Post by barbara »

You have made some comments however it is unclear what you trying to say. For example, since no such thing as a "template iterator" we do not know what this refers to. I think you are saying, a function "becomes more versatile and flexible" than a method. On what basis are you making this claim?

The names of functions and methods are extremely important. The name "contains" has a specific meaning in both CopperSpice and the C++ standard. Adding a new meaning to an existing term is dangerous.

Just because something might be easy to write not mean it belongs in a third party library. It is also not clear what you are saying about "transferring" iterators.

We absolutely want to add meaningful features to CopperSpice. However it is our opinion that overly specific API calls do not belong in a third party library.

A much better alternative is to take all the functionality you want for your project and create a personal library. Simply link your library with CopperSpice. Then link your application with your library. This will work perfectly. If you want to publish your personal library for others to use, this would be awesome and very generous.
Navadvipa Chandra d
Posts: 34
Joined: Sun Apr 19 2020 7:02 pm

Re: Dealing with overloads in QString

Post by Navadvipa Chandra d »

Hello, Barbara and All!

The template iterator does not exist in C++.
But I just named the second parameter of the function by this name - "Template".

I explain:

bool Like ( QString String, QString Template );
bool Like ( QString::iterator String_begin, QString::iterator String_end, QString::iterator Template_begin, QString::iterator Template_end );

Where the first String parameter is the string in which the search is performed.
And the second Template parameter is the string we want to find.

It turns out that in order for the Like function to be as flexible as possible, it needs to be a global function. In my opinion, it is unnecessary to create a special class for it with a single static Like function.

But the function that converts a number into a verbal form, I agree, you need to write a separate class here, as this will reduce the number of parameters passed to the function. I probably will.

As for the fact that this is my personal library, I disagree here. I find it useful for everyone, not just for the Shrila Prabhupada's Dictionary project. Some things can be improved. They are absolutely universal and do not belong to any particular project. If the tool is useful for only one specific project, then it makes no sense to move it to the library. Here I agree.

With respect, Navadvipa Chandra das.
barbara
Posts: 491
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Dealing with overloads in QString

Post by barbara »

The intent of the following comments is provide feedback and offer some education. You are free to ignore this code review as you see fit.


>> (1)
>> bool Like ( QString String, QString Template );
>> bool Like ( QString::iterator String_begin, QString::iterator String_end, QString::iterator Template_begin, QString::iterator Template_end );

The first letter of a variable name should never be a capital letter. Yes, it will compile but it is wrong on so many levels and would be rejected in a code review by all major software companies. By convention, in C++ a capital letter should only be used as the first character of a class or type name. Going against this convention will alienate other developers and should be avoided.

Using a variable name of "string" is tolerable but not readable. This conflicts with a data type in the standard library. Variable names should have a meaning for other developers who is reading your code. I should not need to read your comments to have a basic understanding of the code.

Using the variable name of "template" would be illegal since this is a reserved keyword. Getting around this by using "Template" is bad programming. This is also a meaningless name and makes your code extremely hard to read or comprehend.


>> (2) And the second Template parameter is the string we want to find.

This is just wrong. The second parameter is NOT a template so your code is misleading. The compiler will not treat this value as a template which means you may not understand templates.


>> (3) As for the fact that this is my personal library, I disagree here. I find it useful for everyone.

This statement is over the top and very startling. You have no idea if your code is useful for other people, you are making an unfounded statement. Have you interviewed 10,000 people and asked them for a code review?

Barbara
Navadvipa Chandra d
Posts: 34
Joined: Sun Apr 19 2020 7:02 pm

Re: Dealing with overloads in QString

Post by Navadvipa Chandra d »

Hello, Barbara and All

Here is the original line from the QPrabhupada.h file :

bool Like( QString::iterator t_end, QString::iterator s_end, QString::iterator t, QString::iterator s );

I just explained what the letters "s" and "t" in the parameter names mean.

With best regards, Navadvipa Chandra das.
Last edited by Navadvipa Chandra d on Wed Apr 02 2025 8:19 pm, edited 1 time in total.
Post Reply