[Development] Recommended way to take in strings

Thiago Macieira thiago.macieira at intel.com
Thu Jun 1 08:25:56 CEST 2023


On Wednesday, 31 May 2023 22:38:11 PDT Marc Mutz via Development wrote:
> On 31.05.23 16:05, Thiago Macieira wrote:
> > [...] Therefore, if
> > your function isn't named after a verb in the imperative, then it should
> > be
> > const QString &.
> 
> Function names have nothing to do with it: `fromString(~~stringish~~)`
> is a dead-sure candidate for QAnyStringView while
> `operator[](~~stringish~~)` doesn't even have a name as such.

They do, if they've followed the naming convention. "fromString" does not 
follow it.

However, I was hasty. There are more options.

parse(), calculateResult(), execute() have verbs in the imperative as roots 
and are actions. contains() is a verb in the third person and is not an 
action. Those two *can* use Views.

errorOccurred() is a signal. We haven't discussed this, but in most cases we 
have an errorString() equivalent so this string is probably stored anyway. And 
it's probably calculated, so might as well use const QString &.

fileName() is a property name, though the setter does have a verb in the 
imperative (setFilename()). Those mustn't be Views.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5152 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230531/eda977d1/attachment-0001.bin>


More information about the Development mailing list