Phillarmonic / pixicato-bundle

A Symfony bundle for validating Brazilian PIX keys.
MIT License
2 stars 0 forks source link

Random pix key #1

Open andersonpem opened 3 weeks ago

andersonpem commented 3 weeks ago

We missed the random type key in our implementation. I actually started the conversation in the wrong repo :stuck_out_tongue: https://github.com/Phillarmonic/cpf-cnpj/issues/5

We have a regex for that. https://developers.international.pagseguro.com/reference/pix-key-validation-and-regex

Very similar to a uuid.

phillarmonkey commented 3 weeks ago

Adding to my queue in the project at https://taskavel.com/

phillarmonkey commented 3 weeks ago

Also, again, thank you for bringing this to my attention.

Z.

andersonpem commented 3 weeks ago

Gogogo 🤓 Alt Text

phillarmonkey commented 3 weeks ago

From your experience, performance-wise, which one is better?

andersonpem commented 3 weeks ago

I think using regex is usually faster. For simple regular expressions that might not cause regressions and need a different regex engine like the RE2 of Golang like when the Cloudflare regex issue took them down due to infinite backtrack, then using regex is advisable.

It all comes down to how predictable the expression is. In the case of CPF and CNPJ, we need to do extra calculations to make sure a number is valid.

In the case of a random key, all we need to do is check if the format matches, because there's no inherent validation check logic to the data.

I have also written a framework in PHP from scratch to study how routers, dependency injection and other aspects work. By far the fastest and more performant approach for route resolution (that is quite more complex than this) was to match things with regex. And then implement logic from there. I got very happy when I made dependency injection work from scratch :stuck_out_tongue: I felt very proud.

So, yes. Considering the nature of the data, regex will do.

phillarmonkey commented 3 weeks ago

Linear time regex engines are very interesting.

"Let this be a warning to all who are performing extremely convoluted regex matching at scale". Wise words. And you cannot go bigger than Cloudflare.

Very well. We're not cloudflaring our way through the problem, so I'd say using regex is pretty safe, quick and efficient (dirty?)

Updated task at Taskavel. Give me some time to cook this up.

phillarmonkey commented 3 weeks ago

I have also written a framework in PHP from scratch

Also, can you share this with me? I wanna see how you implemented Dependency Injection.

Z.

andersonpem commented 3 weeks ago

Alright. Check Discord.